Skip to content

Commit

Permalink
Recents: Recognise server notices room(s) and put them in the dedicat…
Browse files Browse the repository at this point in the history
…ed section

#1937
  • Loading branch information
manuroe committed Aug 23, 2018
1 parent 9879033 commit 402c02b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions Riot/Modules/Common/Recents/DataSources/RecentsDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
74 changes: 66 additions & 8 deletions Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +47,7 @@ @interface RecentsDataSource()
NSMutableArray* peopleCellDataArray;
NSMutableArray* conversationCellDataArray;
NSMutableArray* lowPriorityCellDataArray;
NSMutableArray* serverNoticeCellDataArray;

NSInteger shrinkedSectionsBitMask;

Expand All @@ -61,9 +63,9 @@ @interface RecentsDataSource()
@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
{
Expand All @@ -74,6 +76,7 @@ - (instancetype)init
favoriteCellDataArray = [[NSMutableArray alloc] init];
peopleCellDataArray = [[NSMutableArray alloc] init];
lowPriorityCellDataArray = [[NSMutableArray alloc] init];
serverNoticeCellDataArray = [[NSMutableArray alloc] init];
conversationCellDataArray = [[NSMutableArray alloc] init];

directorySection = -1;
Expand All @@ -82,6 +85,7 @@ - (instancetype)init
peopleSection = -1;
conversationSection = -1;
lowPrioritySection = -1;
serverNoticeSection = -1;

_areSectionsShrinkable = NO;
shrinkedSectionsBitMask = 0;
Expand Down Expand Up @@ -242,7 +246,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
// 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)
{
Expand Down Expand Up @@ -275,6 +279,11 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
lowPrioritySection = sectionsCount++;
}

if (serverNoticeCellDataArray.count > 0)
{
serverNoticeSection = sectionsCount++;
}
}

return sectionsCount;
Expand Down Expand Up @@ -311,6 +320,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
{
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;
Expand Down Expand Up @@ -378,6 +391,11 @@ - (NSAttributedString *)attributedStringForHeaderTitleInSection:(NSInteger)secti
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;
Expand Down Expand Up @@ -438,6 +456,10 @@ - (UIView *)badgeViewForHeaderTitleInHomeSection:(NSInteger)section
{
sectionArray = lowPriorityCellDataArray;
}
else if (section == serverNoticeSection)
{
sectionArray = serverNoticeCellDataArray;
}

for (id<MXKRecentCellDataStoring> cellData in sectionArray)
{
Expand Down Expand Up @@ -521,6 +543,10 @@ - (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame
{
sectionBitwise = RECENTSDATASOURCE_SECTION_LOWPRIORITY;
}
else if (section == serverNoticeSection)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_SERVERNOTICE;
}
else if (section == invitesSection)
{
sectionBitwise = RECENTSDATASOURCE_SECTION_INVITES;
Expand Down Expand Up @@ -889,6 +915,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cellData = [lowPriorityCellDataArray objectAtIndex:cellDataIndex];
}
}
else if (tableSection == serverNoticeSection)
{
if (cellDataIndex < serverNoticeCellDataArray.count)
{
cellData = [serverNoticeCellDataArray objectAtIndex:cellDataIndex];
}
}
else if (tableSection == invitesSection)
{
if (cellDataIndex < invitesCellDataArray.count)
Expand Down Expand Up @@ -1041,6 +1074,21 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe
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;
}
Expand All @@ -1055,12 +1103,13 @@ - (void)refreshRoomsSections
[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)
{
Expand All @@ -1077,7 +1126,11 @@ - (void)refreshRoomsSections

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];
}
Expand Down Expand Up @@ -1288,6 +1341,7 @@ - (void)refreshRoomsSections
[peopleCellDataArray sortUsingComparator:comparator];
[conversationCellDataArray sortUsingComparator:comparator];
[lowPriorityCellDataArray sortUsingComparator:comparator];
[serverNoticeCellDataArray sortUsingComparator:comparator];
}
}
else if (favoriteCellDataArray.count > 0 && _recentsDataSourceMode == RecentsDataSourceModeFavourites)
Expand Down Expand Up @@ -1421,8 +1475,8 @@ - (BOOL)isDraggableCellAt:(NSIndexPath*)path
{
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
Expand Down Expand Up @@ -1451,6 +1505,10 @@ - (NSString*)roomTagAt:(NSIndexPath*)path
{
return kMXRoomTagLowPriority;
}
else if (path.section == serverNoticeSection)
{
return kMXRoomTagServerNotice;
}

return nil;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

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
Expand All @@ -114,6 +114,10 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
self.lowPrioritySection += sectionsOffset;
}
if (self.serverNoticeSection != -1)
{
self.serverNoticeSection += sectionsOffset;
}
sectionsCount += sectionsOffset;
}
}
Expand Down

0 comments on commit 402c02b

Please sign in to comment.