Merge pull request #2059 from vector-im/riot_1937_4

Server Quota Notices: Implement the blue banner
This commit is contained in:
manuroe
2018-10-05 16:40:21 +02:00
committed by GitHub
8 changed files with 134 additions and 15 deletions
+7
View File
@@ -1,3 +1,10 @@
Changes in 0.7.5 (2018-10-)
===============================================
Improvements:
* Upgrade MatrixKit version (v0.8.5).
* Server Quota Notices: Implement the blue banner (#1937).
Changes in 0.7.4 (2018-09-26)
===============================================
+4
View File
@@ -281,6 +281,10 @@
"room_resource_limit_exceeded_message_contact_1" = " Please ";
"room_resource_limit_exceeded_message_contact_2_link" = "contact your service administrator";
"room_resource_limit_exceeded_message_contact_3" = " to continue using this service.";
"room_resource_usage_limit_reached_message_1_default" = "This homeserver has exceeded one of its resource limits so ";
"room_resource_usage_limit_reached_message_1_monthly_active_user" = "This homeserver has hit its Monthly Active User limit so ";
"room_resource_usage_limit_reached_message_2" = "some users will not be able to log in.";
"room_resource_usage_limit_reached_message_contact_3" = " to get this limit increased.";
// Unknown devices
"unknown_devices_alert_title" = "Room contains unknown devices";
+1
View File
@@ -53,6 +53,7 @@ extern UIColor *kRiotColorRed;
extern UIColor *kRiotColorIndigo;
extern UIColor *kRiotColorOrange;
extern UIColor *kRiotColorBlue;
extern UIColor *kRiotColorCuriousBlue;
#pragma mark - Riot Standard Room Member Power Level
extern NSInteger const kRiotRoomModeratorLevel;
+3 -1
View File
@@ -47,6 +47,7 @@ UIColor *kRiotColorRed;
UIColor *kRiotColorIndigo;
UIColor *kRiotColorOrange;
UIColor *kRiotColorBlue;
UIColor *kRiotColorCuriousBlue;
// Riot Background Colors
UIColor *kRiotBgColorWhite;
@@ -101,7 +102,8 @@ UIKeyboardAppearance kRiotKeyboard;
kRiotColorIndigo = UIColorFromRGB(0xBD79CC);
kRiotColorOrange = UIColorFromRGB(0xF8A15F);
kRiotColorBlue = UIColorFromRGB(0x81BDDB);
kRiotColorCuriousBlue = UIColorFromRGB(0x2A9EDB);
kRiotBgColorWhite = [UIColor whiteColor];
kRiotBgColorBlack = UIColorFromRGB(0x2D2D2D);
kRiotBgColorOLEDBlack = [UIColor blackColor];
+1 -1
View File
@@ -27,7 +27,7 @@
#import "UIViewController+RiotSearch.h"
@interface RoomViewController : MXKRoomViewController <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate, RoomParticipantsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, ContactsTableViewControllerDelegate>
@interface RoomViewController : MXKRoomViewController
// The expanded header
@property (weak, nonatomic) IBOutlet UIView *expandedHeaderContainer;
+47 -1
View File
@@ -123,7 +123,7 @@
#import "Riot-Swift.h"
@interface RoomViewController ()
@interface RoomViewController () <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate, RoomParticipantsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, ContactsTableViewControllerDelegate, MXServerNoticesDelegate>
{
// The expanded header
ExpandedRoomTitleView *expandedHeader;
@@ -211,6 +211,9 @@
// Listener for `m.room.tombstone` event type
id tombstoneEventNotificationsListener;
// Homeserver notices
MXServerNotices *serverNotices;
}
@end
@@ -821,6 +824,8 @@
if (self.roomDataSource)
{
[self listenToServerNotices];
self.eventsAcknowledgementEnabled = YES;
// Set room title view
@@ -1166,6 +1171,7 @@
[self removeWidgetNotificationsListeners];
[self removeTombstoneEventNotificationsListener];
[self removeMXSessionStateChangeNotificationsListener];
[self removeServerNoticesListener];
if (previewHeader || (self.expandedHeaderContainer.isHidden == NO))
{
@@ -3810,6 +3816,32 @@
}];
}
#pragma mark - Server notices management
- (void)removeServerNoticesListener
{
if (serverNotices)
{
[serverNotices close];
serverNotices = nil;
}
}
- (void)listenToServerNotices
{
if (!serverNotices)
{
serverNotices = [[MXServerNotices alloc] initWithMatrixSession:self.roomDataSource.mxSession];
serverNotices.delegate = self;
}
}
- (void)serverNoticesDidChangeState:(MXServerNotices *)serverNotices
{
[self refreshActivitiesViewDisplay];
}
#pragma mark - Widget notifications management
- (void)removeWidgetNotificationsListeners
@@ -4026,6 +4058,20 @@
}];
}
else if (serverNotices.usageLimit && serverNotices.usageLimit.isServerNoticeUsageLimit)
{
[roomActivitiesView showResourceUsageLimitNotice:serverNotices.usageLimit onAdminContactTapped:^(NSURL *adminContact) {
if ([[UIApplication sharedApplication] canOpenURL:adminContact])
{
[[UIApplication sharedApplication] openURL:adminContact];
}
else
{
NSLog(@"[RoomVC] refreshActivitiesViewDisplay: adminContact(%@) cannot be opened", adminContact);
}
}];
}
else
{
[self refreshTypingNotification];
@@ -93,6 +93,14 @@
*/
- (void)showResourceLimitExceededError:(NSDictionary *)errorDict onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped;
/**
Display a usage limit notice sent in a system alert room.
@param usageLimit the usage limit data.
@param onAdminContactTapped a callback indicating if the user wants to contact their admin.
*/
- (void)showResourceUsageLimitNotice:(MXServerNoticeContent *)usageLimit onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped;
/**
Remove any displayed information.
*/
@@ -376,32 +376,63 @@
- (void)showResourceLimitExceededError:(NSDictionary *)errorDict onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped
{
[self reset];
CGFloat fontSize = 15;
// Parse error data
NSString *limitType, *adminContactString;
NSURL *adminContact;
MXJSONModelSetString(limitType, errorDict[kMXErrorResourceLimitExceededLimitTypeKey]);
MXJSONModelSetString(adminContactString, errorDict[kMXErrorResourceLimitExceededAdminContactKey]);
[self showResourceLimit:limitType adminContactString:adminContactString hardLimit:YES onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped];
}
- (void)showResourceUsageLimitNotice:(MXServerNoticeContent *)usageLimit onAdminContactTapped:(void (^)(NSURL *))onAdminContactTapped
{
[self showResourceLimit:usageLimit.limitType adminContactString:usageLimit.adminContact hardLimit:NO onAdminContactTapped:onAdminContactTapped];
}
- (void)showResourceLimit:(NSString *)limitType adminContactString:(NSString *)adminContactString hardLimit:(BOOL)hardLimit onAdminContactTapped:(void (^)(NSURL *adminContact))onAdminContactTapped
{
[self reset];
CGFloat fontSize = 15;
NSURL *adminContact;
if (adminContactString)
{
adminContact = [NSURL URLWithString:adminContactString];
}
// Build the message content
// Reuse MatrixKit as is for the beginning
NSMutableString *message = [NSMutableString new];
if ([limitType isEqualToString:kMXErrorResourceLimitExceededLimitTypeMonthlyActiveUserValue])
NSAttributedString *message2;
if (hardLimit)
{
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_monthly_active_user"]];
// Reuse MatrixKit as is for the beginning of hardLimit
if ([limitType isEqualToString:kMXErrorResourceLimitExceededLimitTypeMonthlyActiveUserValue])
{
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_monthly_active_user"]];
}
else
{
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_default"]];
}
}
else
{
[message appendString:[NSBundle mxk_localizedStringForKey:@"login_error_resource_limit_exceeded_message_default"]];
if ([limitType isEqualToString:kMXErrorResourceLimitExceededLimitTypeMonthlyActiveUserValue])
{
[message appendString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_1_monthly_active_user", @"Vector", nil)];
}
else
{
[message appendString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_1_default", @"Vector", nil)];
}
message2 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_2", @"Vector", nil)
attributes:@{
NSFontAttributeName: [UIFont boldSystemFontOfSize:fontSize],
NSForegroundColorAttributeName: kRiotPrimaryBgColor
}];
}
NSDictionary *attributes = @{
@@ -430,9 +461,21 @@
NSAttributedString *messageContact1 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_1", @"Vector", nil) attributes:attributes];
NSAttributedString *messageContact2Link = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_2_link", @"Vector", nil) attributes:messageContact2LinkAttributes];
NSAttributedString *messageContact3 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_3", @"Vector", nil) attributes:attributes];
NSAttributedString *messageContact3;
if (hardLimit)
{
messageContact3 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_limit_exceeded_message_contact_3", @"Vector", nil) attributes:attributes];
}
else
{
messageContact3 = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"room_resource_usage_limit_reached_message_contact_3", @"Vector", nil) attributes:attributes];
}
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:message attributes:attributes];
if (message2)
{
[attributedText appendAttributedString:message2];
}
[attributedText appendAttributedString:messageContact1];
[attributedText appendAttributedString:messageContact2Link];
[attributedText appendAttributedString:messageContact3];
@@ -441,8 +484,16 @@
self.messageTextView.tintColor = kRiotPrimaryBgColor;
self.messageTextView.hidden = NO;
self.backgroundColor = kRiotColorPinkRed;
self.messageTextView.backgroundColor = kRiotColorPinkRed;
if (hardLimit)
{
self.backgroundColor = kRiotColorPinkRed;
self.messageTextView.backgroundColor = kRiotColorPinkRed;
}
else
{
self.backgroundColor = kRiotColorCuriousBlue;
self.messageTextView.backgroundColor = kRiotColorCuriousBlue;
}
// Hide the separator to display correctly the banner
self.separatorView.hidden = YES;