diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 3bf631afc..a0877f3e9 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -312,6 +312,8 @@ "settings_enable_push_notif" = "Notifications on this device"; "settings_global_settings_info" = "Global notification settings are available on your %@ web client"; +"settings_pin_rooms_with_missed_notif" = "Pin rooms with missed notifications"; +"settings_pin_rooms_with_unread" = "Pin rooms with unread messages"; "settings_on_denied_notification" = "Notifications are denied for %@, please allow them in your device settings"; //"settings_enable_all_notif" = "Enable all notifications"; //"settings_messages_my_display_name" = "Msg containing my display name"; diff --git a/Riot/Model/RoomList/RecentsDataSource.m b/Riot/Model/RoomList/RecentsDataSource.m index f8f446f04..fd92ce662 100644 --- a/Riot/Model/RoomList/RecentsDataSource.m +++ b/Riot/Model/RoomList/RecentsDataSource.m @@ -95,12 +95,9 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou - (void)setDelegate:(id)delegate andRecentsDataSourceMode:(RecentsDataSourceMode)recentsDataSourceMode { - if (self.delegate != delegate || _recentsDataSourceMode != recentsDataSourceMode) - { - // Update the configuration, the recentsDataSourceMode setter will force a refresh. - self.delegate = delegate; - self.recentsDataSourceMode = recentsDataSourceMode; - } + // Update the configuration, the recentsDataSourceMode setter will force a refresh. + self.delegate = delegate; + self.recentsDataSourceMode = recentsDataSourceMode; } - (void)setRecentsDataSourceMode:(RecentsDataSourceMode)recentsDataSourceMode @@ -1199,62 +1196,100 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou if (_recentsDataSourceMode == RecentsDataSourceModeHome) { - // Sort each rooms collection by considering first the rooms with some missed notifs, the rooms with unread, then the others. - NSComparator comparator = ^NSComparisonResult(id recentCellData1, id recentCellData2) { - - if (recentCellData1.highlightCount) - { - if (recentCellData2.highlightCount) - { - return NSOrderedSame; - } - else - { - return NSOrderedAscending; - } - } - else if (recentCellData2.highlightCount) - { - return NSOrderedDescending; - } - else if (recentCellData1.notificationCount) - { - if (recentCellData2.notificationCount) - { - return NSOrderedSame; - } - else - { - return NSOrderedAscending; - } - } - else if (recentCellData2.notificationCount) - { - return NSOrderedDescending; - } - else if (recentCellData1.hasUnread) - { - if (recentCellData2.hasUnread) - { - return NSOrderedSame; - } - else - { - return NSOrderedAscending; - } - } - else if (recentCellData2.hasUnread) - { - return NSOrderedDescending; - } - return NSOrderedSame; - }; + BOOL pinMissedNotif = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithMissedNotif"]; + BOOL pinUnread = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithUnread"]; + NSComparator comparator = nil; - // Sort the rooms collections - [favoriteCellDataArray sortUsingComparator:comparator]; - [peopleCellDataArray sortUsingComparator:comparator]; - [conversationCellDataArray sortUsingComparator:comparator]; - [lowPriorityCellDataArray sortUsingComparator:comparator]; + if (pinMissedNotif) + { + // Sort each rooms collection by considering first the rooms with some missed notifs, the rooms with unread, then the others. + comparator = ^NSComparisonResult(id recentCellData1, id recentCellData2) { + + if (recentCellData1.highlightCount) + { + if (recentCellData2.highlightCount) + { + return NSOrderedSame; + } + else + { + return NSOrderedAscending; + } + } + else if (recentCellData2.highlightCount) + { + return NSOrderedDescending; + } + else if (recentCellData1.notificationCount) + { + if (recentCellData2.notificationCount) + { + return NSOrderedSame; + } + else + { + return NSOrderedAscending; + } + } + else if (recentCellData2.notificationCount) + { + return NSOrderedDescending; + } + else if (pinUnread) + { + if (recentCellData1.hasUnread) + { + if (recentCellData2.hasUnread) + { + return NSOrderedSame; + } + else + { + return NSOrderedAscending; + } + } + else if (recentCellData2.hasUnread) + { + return NSOrderedDescending; + } + } + + return NSOrderedSame; + }; + } + else if (pinUnread) + { + // Sort each rooms collection by considering first the rooms with some unread messages then the others. + comparator = ^NSComparisonResult(id recentCellData1, id recentCellData2) { + + if (recentCellData1.hasUnread) + { + if (recentCellData2.hasUnread) + { + return NSOrderedSame; + } + else + { + return NSOrderedAscending; + } + } + else if (recentCellData2.hasUnread) + { + return NSOrderedDescending; + } + + return NSOrderedSame; + }; + } + + if (comparator) + { + // Sort the rooms collections + [favoriteCellDataArray sortUsingComparator:comparator]; + [peopleCellDataArray sortUsingComparator:comparator]; + [conversationCellDataArray sortUsingComparator:comparator]; + [lowPriorityCellDataArray sortUsingComparator:comparator]; + } } else if (favoriteCellDataArray.count > 0 && _recentsDataSourceMode == RecentsDataSourceModeFavourites) { diff --git a/Riot/Riot-Defaults.plist b/Riot/Riot-Defaults.plist index 6526355fa..954859b75 100644 --- a/Riot/Riot-Defaults.plist +++ b/Riot/Riot-Defaults.plist @@ -2,6 +2,10 @@ + pinRoomsWithMissedNotif + + pinRoomsWithUnread + pushGatewayURL https://matrix.org/_matrix/push/v1/notify pusherAppIdDev diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index 5c0932712..444dace55 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -57,6 +57,8 @@ enum { NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX = 0, NOTIFICATION_SETTINGS_GLOBAL_SETTINGS_INDEX, + NOTIFICATION_SETTINGS_PIN_MISSED_NOTIFICATIONS_INDEX, + NOTIFICATION_SETTINGS_PIN_UNREAD_INDEX, //NOTIFICATION_SETTINGS_CONTAINING_MY_USER_NAME_INDEX, //NOTIFICATION_SETTINGS_CONTAINING_MY_DISPLAY_NAME_INDEX, //NOTIFICATION_SETTINGS_SENT_TO_ME_INDEX, @@ -1514,6 +1516,30 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); cell = globalInfoCell; } + else if (row == NOTIFICATION_SETTINGS_PIN_MISSED_NOTIFICATIONS_INDEX) + { + MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; + + labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_missed_notif", @"Vector", nil); + labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithMissedNotif"]; + labelAndSwitchCell.mxkSwitch.enabled = YES; + [labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; + [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithMissedNotif:) forControlEvents:UIControlEventTouchUpInside]; + + cell = labelAndSwitchCell; + } + else if (row == NOTIFICATION_SETTINGS_PIN_UNREAD_INDEX) + { + MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; + + labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_unread", @"Vector", nil); + labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithUnread"]; + labelAndSwitchCell.mxkSwitch.enabled = YES; + [labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; + [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithUnread:) forControlEvents:UIControlEventTouchUpInside]; + + cell = labelAndSwitchCell; + } } else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX) { @@ -2485,6 +2511,22 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); [self.tableView reloadData]; } +- (void)togglePinRoomsWithMissedNotif:(id)sender +{ + UISwitch *switchButton = (UISwitch*)sender; + + [[NSUserDefaults standardUserDefaults] setBool:switchButton.on forKey:@"pinRoomsWithMissedNotif"]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +- (void)togglePinRoomsWithUnread:(id)sender +{ + UISwitch *switchButton = (UISwitch*)sender; + + [[NSUserDefaults standardUserDefaults] setBool:switchButton.on forKey:@"pinRoomsWithUnread"]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + - (void)markAllAsRead:(id)sender { // Feedback: disable button and run activity indicator