diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index 2299783fa..e73396ac5 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -116,43 +116,35 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou #pragma mark - Properties -- (NSArray> *)invitesCellDataArray +- (NSArray> *)invitesCellDataArray { - return [self mapRoomSummaries:self.recentsListService.invitedRoomListData.rooms]; + return self.recentsListService.invitedRoomListData.rooms; } -- (NSArray> *)favoriteCellDataArray +- (NSArray> *)favoriteCellDataArray { - return [self mapRoomSummaries:self.recentsListService.favoritedRoomListData.rooms]; + return self.recentsListService.favoritedRoomListData.rooms; } -- (NSArray> *)peopleCellDataArray +- (NSArray> *)peopleCellDataArray { - return [self mapRoomSummaries:self.recentsListService.peopleRoomListData.rooms]; + return self.recentsListService.peopleRoomListData.rooms; } -- (NSArray> *)conversationCellDataArray +- (NSArray> *)conversationCellDataArray { - return [self mapRoomSummaries:self.recentsListService.conversationRoomListData.rooms]; + return self.recentsListService.conversationRoomListData.rooms; } -- (NSArray> *)lowPriorityCellDataArray +- (NSArray> *)lowPriorityCellDataArray { - return [self mapRoomSummaries:self.recentsListService.lowPriorityRoomListData.rooms]; + return self.recentsListService.lowPriorityRoomListData.rooms; } -- (NSArray> *)serverNoticeCellDataArray +- (NSArray> *)serverNoticeCellDataArray { - return [self mapRoomSummaries:self.recentsListService.serverNoticeRoomListData.rooms]; + return self.recentsListService.serverNoticeRoomListData.rooms; } -- (NSArray> *)suggestedRoomCellDataArray +- (NSArray> *)suggestedRoomCellDataArray { - return [self mapRoomSummaries:self.recentsListService.suggestedRoomListData.rooms]; + return self.recentsListService.suggestedRoomListData.rooms; } -- (NSArray> *)mapRoomSummaries:(NSArray> *)summaries - { - return [summaries vc_map:^id _Nonnull(id _Nonnull summary) { - return [[MXKRecentCellData alloc] initWithRoomSummary:summary - dataSource:self]; - }]; - } - - (NSInteger)totalVisibleItemCount { return self.recentsListService.totalVisibleItemCount; @@ -945,7 +937,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou - (id)cellDataAtIndexPath:(NSIndexPath *)indexPath { - id cellData = nil; + id summary = nil; NSUInteger cellDataIndex = indexPath.row; NSInteger tableSection = indexPath.section; @@ -963,53 +955,57 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou { if (cellDataIndex < self.favoriteCellDataArray.count) { - cellData = self.favoriteCellDataArray[cellDataIndex]; + summary = self.favoriteCellDataArray[cellDataIndex]; } } else if (tableSection == peopleSection) { if (cellDataIndex < self.peopleCellDataArray.count) { - cellData = self.peopleCellDataArray[cellDataIndex]; + summary = self.peopleCellDataArray[cellDataIndex]; } } else if (tableSection== conversationSection) { if (cellDataIndex < self.conversationCellDataArray.count) { - cellData = self.conversationCellDataArray[cellDataIndex]; + summary = self.conversationCellDataArray[cellDataIndex]; } } else if (tableSection == lowPrioritySection) { if (cellDataIndex < self.lowPriorityCellDataArray.count) { - cellData = self.lowPriorityCellDataArray[cellDataIndex]; + summary = self.lowPriorityCellDataArray[cellDataIndex]; } } else if (tableSection == serverNoticeSection) { if (cellDataIndex < self.serverNoticeCellDataArray.count) { - cellData = self.serverNoticeCellDataArray[cellDataIndex]; + summary = self.serverNoticeCellDataArray[cellDataIndex]; } } else if (tableSection == invitesSection) { if (cellDataIndex < self.invitesCellDataArray.count) { - cellData = self.invitesCellDataArray[cellDataIndex]; + summary = self.invitesCellDataArray[cellDataIndex]; } } else if (tableSection == suggestedRoomsSection) { if (cellDataIndex < self.suggestedRoomCellDataArray.count) { - cellData = self.suggestedRoomCellDataArray[cellDataIndex]; + summary = self.suggestedRoomCellDataArray[cellDataIndex]; } } - return cellData; + if (summary) + { + return [[MXKRecentCellData alloc] initWithRoomSummary:summary dataSource:self]; + } + return nil; } - (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath @@ -1056,22 +1052,15 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou #pragma mark - -- (NSInteger)cellIndexPosWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession within:(NSArray*)cellDataArray +- (NSInteger)cellIndexPosWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession within:(NSArray> *)summaries { - if (roomId && matrixSession && cellDataArray.count) + if (!roomId || !matrixSession || !summaries.count || self.mxSession != matrixSession) { - for (int index = 0; index < cellDataArray.count; index++) - { - id cellData = cellDataArray[index]; - - if ([roomId isEqualToString:cellData.roomIdentifier] && cellData.mxSession == matrixSession) - { - return index; - } - } + return NSNotFound; } - - return NSNotFound; + return [summaries indexOfObjectPassingTest:^BOOL(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + return [obj.roomId isEqualToString:roomId]; + }]; } - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession