From 9c33f977c81adf8052802753a75bc6e787bf45e3 Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 23 Aug 2018 16:50:14 +0200 Subject: [PATCH] Recents: Recognise server notices room(s) and put them in the dedicated section https://github.com/vector-im/riot-ios/issues/1937 --- Riot/Assets/en.lproj/Vector.strings | 1 + .../Recents/DataSources/RecentsDataSource.h | 2 + .../Recents/DataSources/RecentsDataSource.m | 74 +++++++++++++++++-- .../UnifiedSearchRecentsDataSource.m | 6 +- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index c78ecc45e..8d7ec630b 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -133,6 +133,7 @@ "room_recents_conversations_section" = "ROOMS"; "room_recents_no_conversation" = "No rooms"; "room_recents_low_priority_section" = "LOW PRIORITY"; +"room_recents_server_notice_section" = "SYSTEM ALERTS"; "room_recents_invites_section" = "INVITES"; "room_recents_start_chat_with" = "Start chat"; "room_recents_create_empty_room" = "Create room"; diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.h b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.h index 81ca32c18..bfb3833b4 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.h +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.h @@ -52,12 +52,14 @@ extern NSString *const kRecentsDataSourceTapOnDirectoryServerChange; @property (nonatomic) NSInteger peopleSection; @property (nonatomic) NSInteger conversationSection; @property (nonatomic) NSInteger lowPrioritySection; +@property (nonatomic) NSInteger serverNoticeSection; @property (nonatomic, readonly) NSArray* invitesCellDataArray; @property (nonatomic, readonly) NSArray* favoriteCellDataArray; @property (nonatomic, readonly) NSArray* peopleCellDataArray; @property (nonatomic, readonly) NSArray* conversationCellDataArray; @property (nonatomic, readonly) NSArray* lowPriorityCellDataArray; +@property (nonatomic, readonly) NSArray* serverNoticeCellDataArray; /** Set the delegate by specifying the selected display mode. diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index ad27b3746..03d6c7e0b 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -32,7 +32,8 @@ #define RECENTSDATASOURCE_SECTION_FAVORITES 0x04 #define RECENTSDATASOURCE_SECTION_CONVERSATIONS 0x08 #define RECENTSDATASOURCE_SECTION_LOWPRIORITY 0x10 -#define RECENTSDATASOURCE_SECTION_PEOPLE 0x20 +#define RECENTSDATASOURCE_SECTION_SERVERNOTICE 0x20 +#define RECENTSDATASOURCE_SECTION_PEOPLE 0x40 #define RECENTSDATASOURCE_DEFAULT_SECTION_HEADER_HEIGHT 30.0 #define RECENTSDATASOURCE_DIRECTORY_SECTION_HEADER_HEIGHT 65.0 @@ -46,6 +47,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou NSMutableArray* peopleCellDataArray; NSMutableArray* conversationCellDataArray; NSMutableArray* lowPriorityCellDataArray; + NSMutableArray* serverNoticeCellDataArray; NSInteger shrinkedSectionsBitMask; @@ -61,9 +63,9 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou @end @implementation RecentsDataSource -@synthesize directorySection, invitesSection, favoritesSection, peopleSection, conversationSection, lowPrioritySection; +@synthesize directorySection, invitesSection, favoritesSection, peopleSection, conversationSection, lowPrioritySection, serverNoticeSection; @synthesize hiddenCellIndexPath, droppingCellIndexPath, droppingCellBackGroundView; -@synthesize invitesCellDataArray, favoriteCellDataArray, peopleCellDataArray, conversationCellDataArray, lowPriorityCellDataArray; +@synthesize invitesCellDataArray, favoriteCellDataArray, peopleCellDataArray, conversationCellDataArray, lowPriorityCellDataArray, serverNoticeCellDataArray; - (instancetype)init { @@ -74,6 +76,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou favoriteCellDataArray = [[NSMutableArray alloc] init]; peopleCellDataArray = [[NSMutableArray alloc] init]; lowPriorityCellDataArray = [[NSMutableArray alloc] init]; + serverNoticeCellDataArray = [[NSMutableArray alloc] init]; conversationCellDataArray = [[NSMutableArray alloc] init]; directorySection = -1; @@ -82,6 +85,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou peopleSection = -1; conversationSection = -1; lowPrioritySection = -1; + serverNoticeSection = -1; _areSectionsShrinkable = NO; shrinkedSectionsBitMask = 0; @@ -242,7 +246,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou // Check whether all data sources are ready before rendering recents if (self.state == MXKDataSourceStateReady) { - directorySection = favoritesSection = peopleSection = conversationSection = lowPrioritySection = invitesSection = -1; + directorySection = favoritesSection = peopleSection = conversationSection = lowPrioritySection = invitesSection = serverNoticeSection = -1; if (invitesCellDataArray.count > 0) { @@ -275,6 +279,11 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { lowPrioritySection = sectionsCount++; } + + if (serverNoticeCellDataArray.count > 0) + { + serverNoticeSection = sectionsCount++; + } } return sectionsCount; @@ -311,6 +320,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { count = lowPriorityCellDataArray.count; } + else if (section == serverNoticeSection && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SERVERNOTICE)) + { + count = serverNoticeCellDataArray.count; + } else if (section == invitesSection && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_INVITES)) { count = invitesCellDataArray.count; @@ -378,6 +391,11 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou count = lowPriorityCellDataArray.count; title = NSLocalizedStringFromTable(@"room_recents_low_priority_section", @"Vector", nil); } + else if (section == serverNoticeSection) + { + count = serverNoticeCellDataArray.count; + title = NSLocalizedStringFromTable(@"room_recents_server_notice_section", @"Vector", nil); + } else if (section == invitesSection) { count = invitesCellDataArray.count; @@ -438,6 +456,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { sectionArray = lowPriorityCellDataArray; } + else if (section == serverNoticeSection) + { + sectionArray = serverNoticeCellDataArray; + } for (id cellData in sectionArray) { @@ -521,6 +543,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { sectionBitwise = RECENTSDATASOURCE_SECTION_LOWPRIORITY; } + else if (section == serverNoticeSection) + { + sectionBitwise = RECENTSDATASOURCE_SECTION_SERVERNOTICE; + } else if (section == invitesSection) { sectionBitwise = RECENTSDATASOURCE_SECTION_INVITES; @@ -889,6 +915,13 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou cellData = [lowPriorityCellDataArray objectAtIndex:cellDataIndex]; } } + else if (tableSection == serverNoticeSection) + { + if (cellDataIndex < serverNoticeCellDataArray.count) + { + cellData = [serverNoticeCellDataArray objectAtIndex:cellDataIndex]; + } + } else if (tableSection == invitesSection) { if (cellDataIndex < invitesCellDataArray.count) @@ -1041,6 +1074,21 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou indexPath = [NSIndexPath indexPathForRow:index inSection:lowPrioritySection]; } } + + if (!indexPath && (serverNoticeSection >= 0)) + { + index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:serverNoticeCellDataArray]; + + if (index != NSNotFound) + { + // Check whether the low priority rooms are shrinked + if (shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SERVERNOTICE) + { + return nil; + } + indexPath = [NSIndexPath indexPathForRow:index inSection:serverNoticeSection]; + } + } return indexPath; } @@ -1055,12 +1103,13 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou [peopleCellDataArray removeAllObjects]; [conversationCellDataArray removeAllObjects]; [lowPriorityCellDataArray removeAllObjects]; + [serverNoticeCellDataArray removeAllObjects]; _missedFavouriteDiscussionsCount = _missedHighlightFavouriteDiscussionsCount = 0; _missedDirectDiscussionsCount = _missedHighlightDirectDiscussionsCount = 0; _missedGroupDiscussionsCount = _missedHighlightGroupDiscussionsCount = 0; - directorySection = favoritesSection = peopleSection = conversationSection = lowPrioritySection = invitesSection = -1; + directorySection = favoritesSection = peopleSection = conversationSection = lowPrioritySection = serverNoticeSection = invitesSection = -1; if (displayedRecentsDataSourceArray.count > 0) { @@ -1077,7 +1126,11 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou if (_recentsDataSourceMode == RecentsDataSourceModeHome) { - if (room.accountData.tags[kMXRoomTagFavourite]) + if (room.accountData.tags[kMXRoomTagServerNotice]) + { + [serverNoticeCellDataArray addObject:recentCellDataStoring]; + } + else if (room.accountData.tags[kMXRoomTagFavourite]) { [favoriteCellDataArray addObject:recentCellDataStoring]; } @@ -1288,6 +1341,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou [peopleCellDataArray sortUsingComparator:comparator]; [conversationCellDataArray sortUsingComparator:comparator]; [lowPriorityCellDataArray sortUsingComparator:comparator]; + [serverNoticeCellDataArray sortUsingComparator:comparator]; } } else if (favoriteCellDataArray.count > 0 && _recentsDataSourceMode == RecentsDataSourceModeFavourites) @@ -1421,8 +1475,8 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { return NO; } - - return (path && ((path.section == favoritesSection) || (path.section == peopleSection) || (path.section == lowPrioritySection) || (path.section == conversationSection))); + + return (path && ((path.section == favoritesSection) || (path.section == peopleSection) || (path.section == lowPrioritySection) || (path.section == serverNoticeSection) || (path.section == conversationSection))); } - (BOOL)canCellMoveFrom:(NSIndexPath*)oldPath to:(NSIndexPath*)newPath @@ -1451,6 +1505,10 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { return kMXRoomTagLowPriority; } + else if (path.section == serverNoticeSection) + { + return kMXRoomTagServerNotice; + } return nil; } diff --git a/Riot/Modules/GlobalSearch/DataSources/UnifiedSearchRecentsDataSource.m b/Riot/Modules/GlobalSearch/DataSources/UnifiedSearchRecentsDataSource.m index 547972da0..4c87b10a5 100644 --- a/Riot/Modules/GlobalSearch/DataSources/UnifiedSearchRecentsDataSource.m +++ b/Riot/Modules/GlobalSearch/DataSources/UnifiedSearchRecentsDataSource.m @@ -89,7 +89,7 @@ if (_hideRecents) { - self.invitesSection = self.favoritesSection = self.peopleSection = self.conversationSection = self.lowPrioritySection = -1; + self.invitesSection = self.favoritesSection = self.peopleSection = self.conversationSection = self.lowPrioritySection = self.serverNoticeSection = -1; sectionsCount = sectionsOffset; } else @@ -114,6 +114,10 @@ { self.lowPrioritySection += sectionsOffset; } + if (self.serverNoticeSection != -1) + { + self.serverNoticeSection += sectionsOffset; + } sectionsCount += sectionsOffset; } }