From 40092917c004965ba58ec4c3fb61280fe69952c2 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 2 Oct 2018 15:30:00 +0200 Subject: [PATCH 1/2] Server Quota Notices: Implement the blue banner Closes #1937 --- CHANGES.rst | 7 ++ Riot/Assets/en.lproj/Vector.strings | 4 + Riot/Constants/RiotDesignValues.h | 1 + Riot/Constants/RiotDesignValues.m | 4 +- Riot/Modules/Room/RoomViewController.h | 2 +- Riot/Modules/Room/RoomViewController.m | 46 ++++++++++++ .../Views/Activities/RoomActivitiesView.h | 8 ++ .../Views/Activities/RoomActivitiesView.m | 75 ++++++++++++++++--- 8 files changed, 133 insertions(+), 14 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 44506e3e9..42d45faeb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) =============================================== diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 043a1609b..3c519c4d7 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -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"; diff --git a/Riot/Constants/RiotDesignValues.h b/Riot/Constants/RiotDesignValues.h index a6db623b6..35c4d05c8 100644 --- a/Riot/Constants/RiotDesignValues.h +++ b/Riot/Constants/RiotDesignValues.h @@ -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; diff --git a/Riot/Constants/RiotDesignValues.m b/Riot/Constants/RiotDesignValues.m index 1c381a36e..a6d4ce672 100644 --- a/Riot/Constants/RiotDesignValues.m +++ b/Riot/Constants/RiotDesignValues.m @@ -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]; diff --git a/Riot/Modules/Room/RoomViewController.h b/Riot/Modules/Room/RoomViewController.h index 292459be6..5c86bdb3d 100644 --- a/Riot/Modules/Room/RoomViewController.h +++ b/Riot/Modules/Room/RoomViewController.h @@ -27,7 +27,7 @@ #import "UIViewController+RiotSearch.h" -@interface RoomViewController : MXKRoomViewController +@interface RoomViewController : MXKRoomViewController // The expanded header @property (weak, nonatomic) IBOutlet UIView *expandedHeaderContainer; diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index e3991c9bc..aaa72f460 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -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]; diff --git a/Riot/Modules/Room/Views/Activities/RoomActivitiesView.h b/Riot/Modules/Room/Views/Activities/RoomActivitiesView.h index df8b66581..f28e47c44 100644 --- a/Riot/Modules/Room/Views/Activities/RoomActivitiesView.h +++ b/Riot/Modules/Room/Views/Activities/RoomActivitiesView.h @@ -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. */ diff --git a/Riot/Modules/Room/Views/Activities/RoomActivitiesView.m b/Riot/Modules/Room/Views/Activities/RoomActivitiesView.m index f456a7986..586f572af 100644 --- a/Riot/Modules/Room/Views/Activities/RoomActivitiesView.m +++ b/Riot/Modules/Room/Views/Activities/RoomActivitiesView.m @@ -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; From 56941a7f20171cf45889081cd3534de7e24d39e9 Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 4 Oct 2018 18:37:25 +0200 Subject: [PATCH 2/2] Server Quota Notices: Implement the blue banner Fix Steves's remark --- Riot/Modules/Room/RoomViewController.h | 2 +- Riot/Modules/Room/RoomViewController.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.h b/Riot/Modules/Room/RoomViewController.h index 5c86bdb3d..9d79bf0fe 100644 --- a/Riot/Modules/Room/RoomViewController.h +++ b/Riot/Modules/Room/RoomViewController.h @@ -27,7 +27,7 @@ #import "UIViewController+RiotSearch.h" -@interface RoomViewController : MXKRoomViewController +@interface RoomViewController : MXKRoomViewController // The expanded header @property (weak, nonatomic) IBOutlet UIView *expandedHeaderContainer; diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index aaa72f460..ea535c7c4 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -123,7 +123,7 @@ #import "Riot-Swift.h" -@interface RoomViewController () +@interface RoomViewController () { // The expanded header ExpandedRoomTitleView *expandedHeader;