Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Quota Notices: Implement the blue banner #2059

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
===============================================

Expand Down
4 changes: 4 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions Riot/Constants/RiotDesignValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion Riot/Constants/RiotDesignValues.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
UIColor *kRiotColorIndigo;
UIColor *kRiotColorOrange;
UIColor *kRiotColorBlue;
UIColor *kRiotColorCuriousBlue;

// Riot Background Colors
UIColor *kRiotBgColorWhite;
Expand Down Expand Up @@ -101,7 +102,8 @@ + (void)load
kRiotColorIndigo = UIColorFromRGB(0xBD79CC);
kRiotColorOrange = UIColorFromRGB(0xF8A15F);
kRiotColorBlue = UIColorFromRGB(0x81BDDB);

kRiotColorCuriousBlue = UIColorFromRGB(0x2A9EDB);

kRiotBgColorWhite = [UIColor whiteColor];
kRiotBgColorBlack = UIColorFromRGB(0x2D2D2D);
kRiotBgColorOLEDBlack = [UIColor blackColor];
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Room/RoomViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#import "UIViewController+RiotSearch.h"

@interface RoomViewController : MXKRoomViewController <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate, RoomParticipantsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, ContactsTableViewControllerDelegate>
@interface RoomViewController : MXKRoomViewController <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate, RoomParticipantsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, ContactsTableViewControllerDelegate, MXServerNoticesDelegate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those protocols don't need to be exposed in header and could be conformed in the .m instead to gain in readability


// The expanded header
@property (weak, nonatomic) IBOutlet UIView *expandedHeaderContainer;
Expand Down
46 changes: 46 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ @interface RoomViewController ()

// Listener for `m.room.tombstone` event type
id tombstoneEventNotificationsListener;

// Homeserver notices
MXServerNotices *serverNotices;
}

@end
Expand Down Expand Up @@ -821,6 +824,8 @@ - (void)displayRoom:(MXKRoomDataSource *)dataSource

if (self.roomDataSource)
{
[self listenToServerNotices];

self.eventsAcknowledgementEnabled = YES;

// Set room title view
Expand Down Expand Up @@ -1166,6 +1171,7 @@ - (void)destroy
[self removeWidgetNotificationsListeners];
[self removeTombstoneEventNotificationsListener];
[self removeMXSessionStateChangeNotificationsListener];
[self removeServerNoticesListener];

if (previewHeader || (self.expandedHeaderContainer.isHidden == NO))
{
Expand Down Expand Up @@ -3810,6 +3816,32 @@ - (void)listenCallNotifications
}];
}


#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
Expand Down Expand Up @@ -4026,6 +4058,20 @@ - (void)refreshActivitiesViewDisplay

}];
}
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];
Expand Down
8 changes: 8 additions & 0 deletions Riot/Modules/Room/Views/Activities/RoomActivitiesView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
75 changes: 63 additions & 12 deletions Riot/Modules/Room/Views/Activities/RoomActivitiesView.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,32 +376,63 @@ - (void)displayRoomReplacementWithRoomLinkTappedHandler:(void (^)(void))onRoomRe

- (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 = @{
Expand Down Expand Up @@ -430,9 +461,21 @@ - (void)showResourceLimitExceededError:(NSDictionary *)errorDict onAdminContactT

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];
Expand All @@ -441,8 +484,16 @@ - (void)showResourceLimitExceededError:(NSDictionary *)errorDict onAdminContactT
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;
Expand Down