From 30428234b0d87fd8dc8f8de1ea5f40addaedd271 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Thu, 23 Sep 2021 16:44:48 +0300 Subject: [PATCH 01/12] Remove unused markAllAsRead methods --- MatrixKit/Models/RoomList/MXKRecentCellData.m | 5 ----- MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h | 5 ----- MatrixKit/Models/RoomList/MXKRecentsDataSource.h | 5 ----- MatrixKit/Models/RoomList/MXKRecentsDataSource.m | 8 -------- .../Models/RoomList/MXKSessionRecentsDataSource.m | 10 ---------- 5 files changed, 33 deletions(-) diff --git a/MatrixKit/Models/RoomList/MXKRecentCellData.m b/MatrixKit/Models/RoomList/MXKRecentCellData.m index 42e9662e0..104b438fd 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellData.m +++ b/MatrixKit/Models/RoomList/MXKRecentCellData.m @@ -81,11 +81,6 @@ - (NSString*)notificationCountStringValue return [NSString stringWithFormat:@"%tu", self.notificationCount]; } -- (void)markAllAsRead -{ - [roomSummary markAllAsRead]; -} - - (NSString*)description { return [NSString stringWithFormat:@"%@ %@: %@ - %@", super.description, self.roomSummary.roomId, self.roomDisplayname, self.lastEventTextMessage]; diff --git a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h index 380736fd3..f3ca04345 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h +++ b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h @@ -64,11 +64,6 @@ */ - (void)update; -/** - Mark all messages as read - */ -- (void)markAllAsRead; - @optional /** The `lastEventTextMessage` with sets of attributes. diff --git a/MatrixKit/Models/RoomList/MXKRecentsDataSource.h b/MatrixKit/Models/RoomList/MXKRecentsDataSource.h index 5c3625689..88ff3db22 100644 --- a/MatrixKit/Models/RoomList/MXKRecentsDataSource.h +++ b/MatrixKit/Models/RoomList/MXKRecentsDataSource.h @@ -74,11 +74,6 @@ */ - (void)removeMatrixSession:(MXSession*)mxSession; -/** - Mark all messages as read in all the displayed recents. - */ -- (void)markAllAsRead; - /** Filter the current recents list according to the provided patterns. diff --git a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m index 006c9d30d..42a520757 100644 --- a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m @@ -233,14 +233,6 @@ - (BOOL)hasUnread return NO; } -- (void)markAllAsRead -{ - for (MXKSessionRecentsDataSource *recentsDataSource in displayedRecentsDataSourceArray) - { - [recentsDataSource markAllAsRead]; - } -} - - (void)searchWithPatterns:(NSArray*)patternsList { _searchPatternsList = patternsList; diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m index 52a6da523..21df37dbb 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m @@ -131,16 +131,6 @@ - (BOOL)hasUnread return NO; } -- (void)markAllAsRead -{ - // Clear unread count on all recent cells - for (NSUInteger i = 0; i < self.numberOfCells; i++) - { - id cellData = [self cellDataAtIndex:i]; - [cellData markAllAsRead]; - } -} - - (void)searchWithPatterns:(NSArray*)patternsList { if (patternsList.count) From f5d5354fb3c10d6421935beecc3054405cb6b89c Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Thu, 23 Sep 2021 16:50:55 +0300 Subject: [PATCH 02/12] Refactor recent cell data --- MatrixKit/Models/MXKDataSource.h | 2 +- MatrixKit/Models/RoomList/MXKRecentCellData.m | 19 +++++++++++++++---- .../RoomList/MXKRecentCellDataStoring.h | 15 +++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/MatrixKit/Models/MXKDataSource.h b/MatrixKit/Models/MXKDataSource.h index c8868ed1b..a1332d6e2 100644 --- a/MatrixKit/Models/MXKDataSource.h +++ b/MatrixKit/Models/MXKDataSource.h @@ -64,7 +64,7 @@ typedef enum : NSUInteger { /** The matrix session. */ -@property (nonatomic, readonly) MXSession *mxSession; +@property (nonatomic, weak, readonly) MXSession *mxSession; /** The data source state diff --git a/MatrixKit/Models/RoomList/MXKRecentCellData.m b/MatrixKit/Models/RoomList/MXKRecentCellData.m index 104b438fd..86663b1ec 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellData.m +++ b/MatrixKit/Models/RoomList/MXKRecentCellData.m @@ -17,19 +17,20 @@ #import "MXKRecentCellData.h" -#import "MXKSessionRecentsDataSource.h" +#import "MXKDataSource.h" #import "MXEvent+MatrixKit.h" @implementation MXKRecentCellData -@synthesize roomSummary, recentsDataSource, roomDisplayname, lastEventTextMessage, lastEventAttributedTextMessage, lastEventDate; +@synthesize roomSummary, dataSource, roomDisplayname, lastEventTextMessage, lastEventAttributedTextMessage, lastEventDate; -- (instancetype)initWithRoomSummary:(MXRoomSummary*)theRoomSummary andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource +- (instancetype)initWithRoomSummary:(id)theRoomSummary + dataSource:(MXKDataSource*)theDataSource; { self = [self init]; if (self) { roomSummary = theRoomSummary; - recentsDataSource = recentListDataSource; + dataSource = theDataSource; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update) name:kMXRoomSummaryDidChangeNotification object:roomSummary]; @@ -56,6 +57,11 @@ - (void)dealloc lastEventAttributedTextMessage = nil; } +- (MXSession *)mxSession +{ + return dataSource.mxSession; +} + - (NSString*)lastEventDate { return (NSString*)roomSummary.lastMessage.others[@"lastEventDate"]; @@ -66,6 +72,11 @@ - (BOOL)hasUnread return (roomSummary.localUnreadEventCount != 0); } +- (NSString *)roomDisplayname +{ + return roomSummary.displayname; +} + - (NSUInteger)notificationCount { return roomSummary.notificationCount; diff --git a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h index f3ca04345..26bb1ca58 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h +++ b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h @@ -20,7 +20,7 @@ #import "MXKCellData.h" -@class MXKSessionRecentsDataSource; +@class MXKDataSource; /** `MXKRecentCellDataStoring` defines a protocol a class must conform in order to store recent cell data @@ -33,12 +33,12 @@ /** The original data source of the recent displayed by the cell. */ -@property (nonatomic, readonly) MXKSessionRecentsDataSource *recentsDataSource; +@property (nonatomic, weak, readonly) MXKDataSource *dataSource; /** The `MXRoomSummary` instance of the room for the recent displayed by the cell. */ -@property (nonatomic, readonly) MXRoomSummary *roomSummary; +@property (nonatomic, readonly) id roomSummary; @property (nonatomic, readonly) NSString *roomDisplayname; @property (nonatomic, readonly) NSString *lastEventTextMessage; @@ -49,15 +49,18 @@ @property (nonatomic, readonly) NSUInteger highlightCount; @property (nonatomic, readonly) NSString *notificationCountStringValue; +@property (nonatomic, readonly) MXSession *mxSession; + #pragma mark - Public methods /** Create a new `MXKCellData` object for a new recent cell. - @param roomSummary the `MXRoomSummary` object that has data about the room. - @param recentListDataSource the `MXKSessionRecentsDataSource` object that will use this instance. + @param roomSummary the `id` object that has data about the room. + @param dataSource the `MXKDataSource` object that will use this instance. @return the newly created instance. */ -- (instancetype)initWithRoomSummary:(MXRoomSummary*)roomSummary andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource; +- (instancetype)initWithRoomSummary:(id)roomSummary + dataSource:(MXKDataSource*)dataSource; /** The `MXKSessionRecentsDataSource` object calls this method when it detects a change in the room. From 2a119721f3659ee03cd037684dac15fc1a94715f Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Thu, 23 Sep 2021 16:51:48 +0300 Subject: [PATCH 03/12] Adapt cell data changes --- MatrixKit/Controllers/MXKRecentListViewController.m | 2 +- .../Models/RoomList/MXKInterleavedRecentsDataSource.m | 7 ++++--- MatrixKit/Models/RoomList/MXKRecentsDataSource.m | 2 +- MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h | 5 ----- MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m | 6 +++--- .../Views/RoomList/MXKInterleavedRecentTableViewCell.m | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/MatrixKit/Controllers/MXKRecentListViewController.m b/MatrixKit/Controllers/MXKRecentListViewController.m index 0f1ae73f0..18a464fcf 100644 --- a/MatrixKit/Controllers/MXKRecentListViewController.m +++ b/MatrixKit/Controllers/MXKRecentListViewController.m @@ -467,7 +467,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if ([cellData conformsToProtocol:@protocol(MXKRecentCellDataStoring)]) { id recentCellData = (id)cellData; - [_delegate recentListViewController:self didSelectRoom:recentCellData.roomSummary.roomId inMatrixSession:recentCellData.roomSummary.room.mxSession]; + [_delegate recentListViewController:self didSelectRoom:recentCellData.roomSummary.roomId inMatrixSession:recentCellData.mxSession]; } } } diff --git a/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m index 8ed044039..4c1e75e62 100644 --- a/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m @@ -230,9 +230,10 @@ - (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath id recentCellData = interleavedCellDataArray[indexPath.row]; // Select the related recent data source - MXKSessionRecentsDataSource *recentsDataSource = recentCellData.recentsDataSource; - if (recentsDataSource) + MXKDataSource *dataSource = recentCellData.dataSource; + if ([dataSource isKindOfClass:[MXKSessionRecentsDataSource class]]) { + MXKSessionRecentsDataSource *recentsDataSource = (MXKSessionRecentsDataSource*)dataSource; // Count the index of this cell data in original data source array NSInteger rank = 0; for (NSInteger index = 0; index < indexPath.row; index++) @@ -417,7 +418,7 @@ - (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes id currentCellData = interleavedCellDataArray[currentCellIndex]; // Remove existing cell data of the updated data source - if (currentCellData.recentsDataSource == dataSource) + if (currentCellData.dataSource == dataSource) { [interleavedCellDataArray removeObjectAtIndex:currentCellIndex]; } diff --git a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m index 42a520757..550a23302 100644 --- a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m @@ -596,7 +596,7 @@ - (MXRoom*)getRoomAtIndexPath:(NSIndexPath *)indexPath if (recentCellData) { - return recentCellData.roomSummary.room; + return [self.mxSession roomWithRoomId:recentCellData.roomSummary.roomId]; } return nil; diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h index 51a6cca53..084880e8a 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h @@ -57,11 +57,6 @@ extern NSString *const kMXKRecentCellIdentifier; #pragma mark - Life cycle -/** - Mark all messages as read for all the recent cells - */ -- (void)markAllAsRead; - /** Filter the current recents list according to the provided patterns. When patterns are not empty, the search result is stored in `filteredCellDataArray`, diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m index 21df37dbb..2f9515bae 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m @@ -222,7 +222,7 @@ - (void)loadData if (!roomSummary.isConferenceUserRoom // @TODO Abstract this condition with roomSummary.hiddenFromUser && !roomSummary.hiddenFromUser) { - id cellData = [[class alloc] initWithRoomSummary:roomSummary andRecentListDataSource:self]; + id cellData = [[class alloc] initWithRoomSummary:roomSummary dataSource:self]; if (cellData) { [internalCellDataArray addObject:cellData]; @@ -293,7 +293,7 @@ - (void)didRoomSummaryChanged2:(NSNotification *)notif { // Create a new instance to not modify the content of 'cellDataArray' (the copy is not a deep copy). Class class = [self cellDataClassForCellIdentifier:kMXKRecentCellIdentifier]; - id cellData = [[class alloc] initWithRoomSummary:roomSummary andRecentListDataSource:self]; + id cellData = [[class alloc] initWithRoomSummary:roomSummary dataSource:self]; if (cellData) { [internalCellDataArray replaceObjectAtIndex:index withObject:cellData]; @@ -335,7 +335,7 @@ - (void)didMXSessionHaveNewRoom:(NSNotification *)notif Class class = [self cellDataClassForCellIdentifier:kMXKRecentCellIdentifier]; MXRoomSummary *roomSummary = [mxSession roomSummaryWithRoomId:roomId]; - id cellData = [[class alloc] initWithRoomSummary:roomSummary andRecentListDataSource:self]; + id cellData = [[class alloc] initWithRoomSummary:roomSummary dataSource:self]; if (cellData) { [internalCellDataArray addObject:cellData]; diff --git a/MatrixKit/Views/RoomList/MXKInterleavedRecentTableViewCell.m b/MatrixKit/Views/RoomList/MXKInterleavedRecentTableViewCell.m index 1da9b9f65..a4b17d16e 100644 --- a/MatrixKit/Views/RoomList/MXKInterleavedRecentTableViewCell.m +++ b/MatrixKit/Views/RoomList/MXKInterleavedRecentTableViewCell.m @@ -49,7 +49,7 @@ - (void)render:(MXKCellData *)cellData // Highlight the room owner by using his tint color. if (roomCellData) { - MXKAccount *account = [[MXKAccountManager sharedManager] accountForUserId:roomCellData.roomSummary.room.mxSession.myUser.userId]; + MXKAccount *account = [[MXKAccountManager sharedManager] accountForUserId:roomCellData.mxSession.myUserId]; if (account) { _userFlag.backgroundColor = account.userTintColor; From d2a0a5085e477efb34b42d6d374296050f71f020 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Thu, 23 Sep 2021 16:52:23 +0300 Subject: [PATCH 04/12] Refactor summary join rule --- MatrixKit/Utils/EventFormatter/MXKEventFormatter.m | 2 +- MatrixKit/Views/RoomList/MXKRecentTableViewCell.m | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index 516f26b77..cff74f1ac 100644 --- a/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -1931,7 +1931,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary } else if (event.eventType == MXEventTypeRoomJoinRules) { - summary.others[@"mxkEventFormatterisJoinRulePublic"] = @(roomState.isJoinRulePublic); + summary.joinRule = roomState.joinRule; } } diff --git a/MatrixKit/Views/RoomList/MXKRecentTableViewCell.m b/MatrixKit/Views/RoomList/MXKRecentTableViewCell.m index b7fbc43f0..3fdce7f75 100644 --- a/MatrixKit/Views/RoomList/MXKRecentTableViewCell.m +++ b/MatrixKit/Views/RoomList/MXKRecentTableViewCell.m @@ -45,8 +45,7 @@ - (void)render:(MXKCellData *)cellData } // Set in bold public room name - if (roomCellData.roomSummary.others[@"mxkEventFormatterisJoinRulePublic"] - && [(NSNumber*)roomCellData.roomSummary.others[@"mxkEventFormatterisJoinRulePublic"] boolValue]) + if ([roomCellData.roomSummary.joinRule isEqualToString:kMXRoomJoinRulePublic]) { _roomTitle.font = [UIFont boldSystemFontOfSize:20]; } From ec88cafc19f163ae3dc430fa62360f7fa12a5d80 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Tue, 28 Sep 2021 17:27:41 +0300 Subject: [PATCH 05/12] Add some transitive fields on MXKCellDataStoring --- .../Controllers/MXKRecentListViewController.m | 7 ++++-- .../MXKInterleavedRecentsDataSource.m | 4 ++-- MatrixKit/Models/RoomList/MXKRecentCellData.m | 22 +++++++++++++++++++ .../RoomList/MXKRecentCellDataStoring.h | 2 ++ .../Models/RoomList/MXKRecentsDataSource.m | 4 ++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/MatrixKit/Controllers/MXKRecentListViewController.m b/MatrixKit/Controllers/MXKRecentListViewController.m index cf4b0c55a..61c48796a 100644 --- a/MatrixKit/Controllers/MXKRecentListViewController.m +++ b/MatrixKit/Controllers/MXKRecentListViewController.m @@ -470,11 +470,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath id recentCellData = (id)cellData; if (recentCellData.isSuggestedRoom) { - [_delegate recentListViewController:self didSelectSuggestedRoom:recentCellData.spaceChildInfo]; + [_delegate recentListViewController:self + didSelectSuggestedRoom:recentCellData.spaceChildInfo]; } else { - [_delegate recentListViewController:self didSelectRoom:recentCellData.roomSummary.roomId inMatrixSession:recentCellData.mxSession]; + [_delegate recentListViewController:self + didSelectRoom:recentCellData.roomIdentifier + inMatrixSession:recentCellData.mxSession]; } } } diff --git a/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m index 4c1e75e62..8477b12d9 100644 --- a/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m @@ -267,7 +267,7 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe for (NSInteger index = 0; index < recentsDataSource.numberOfCells; index ++) { id recentCellData = [recentsDataSource cellDataAtIndex:index]; - if ([roomId isEqualToString:recentCellData.roomSummary.roomId]) + if ([roomId isEqualToString:recentCellData.roomIdentifier]) { // Got it indexPath = [NSIndexPath indexPathForRow:index inSection:0]; @@ -290,7 +290,7 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe for (NSInteger index = 0; index < interleavedCellDataArray.count; index ++) { id recentCellData = interleavedCellDataArray[index]; - if ([roomId isEqualToString:recentCellData.roomSummary.roomId]) + if ([roomId isEqualToString:recentCellData.roomIdentifier]) { // Got it indexPath = [NSIndexPath indexPathForRow:index inSection:0]; diff --git a/MatrixKit/Models/RoomList/MXKRecentCellData.m b/MatrixKit/Models/RoomList/MXKRecentCellData.m index 686c60a10..22fe0bd4e 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellData.m +++ b/MatrixKit/Models/RoomList/MXKRecentCellData.m @@ -90,11 +90,33 @@ - (BOOL)hasUnread return (roomSummary.localUnreadEventCount != 0); } +- (NSString *)roomIdentifier +{ + if (self.isSuggestedRoom) + { + return self.spaceChildInfo.name; + } + return roomSummary.roomId; +} + - (NSString *)roomDisplayname { + if (self.isSuggestedRoom) + { + return self.spaceChildInfo.displayName; + } return roomSummary.displayname; } +- (NSString *)avatarUrl +{ + if (self.isSuggestedRoom) + { + return self.spaceChildInfo.avatarUrl; + } + return roomSummary.avatar; +} + - (NSUInteger)notificationCount { return roomSummary.notificationCount; diff --git a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h index 811df4b1a..faf5ebfd6 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h +++ b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h @@ -45,7 +45,9 @@ */ @property (nonatomic, readonly) MXSpaceChildInfo *spaceChildInfo; +@property (nonatomic, readonly) NSString *roomIdentifier; @property (nonatomic, readonly) NSString *roomDisplayname; +@property (nonatomic, readonly) NSString *avatarUrl; @property (nonatomic, readonly) NSString *lastEventTextMessage; @property (nonatomic, readonly) NSString *lastEventDate; diff --git a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m index 0fccd154d..0da982a1d 100644 --- a/MatrixKit/Models/RoomList/MXKRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKRecentsDataSource.m @@ -354,7 +354,7 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe for (NSInteger index = 0; index < recentsDataSource.numberOfCells; index ++) { id recentCellData = [recentsDataSource cellDataAtIndex:index]; - if ([roomId isEqualToString:recentCellData.roomSummary.roomId]) + if ([roomId isEqualToString:recentCellData.roomIdentifier]) { // Got it indexPath = [NSIndexPath indexPathForRow:index inSection:section]; @@ -605,7 +605,7 @@ - (MXRoom*)getRoomAtIndexPath:(NSIndexPath *)indexPath if (recentCellData) { - return [self.mxSession roomWithRoomId:recentCellData.roomSummary.roomId]; + return [self.mxSession roomWithRoomId:recentCellData.roomIdentifier]; } return nil; From 0cd07bdc21cf926b107440113862f38301a2a427 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Tue, 28 Sep 2021 17:30:09 +0300 Subject: [PATCH 06/12] Fix room identifier for space room --- MatrixKit/Models/RoomList/MXKRecentCellData.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatrixKit/Models/RoomList/MXKRecentCellData.m b/MatrixKit/Models/RoomList/MXKRecentCellData.m index 22fe0bd4e..f08175bd1 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellData.m +++ b/MatrixKit/Models/RoomList/MXKRecentCellData.m @@ -94,7 +94,7 @@ - (NSString *)roomIdentifier { if (self.isSuggestedRoom) { - return self.spaceChildInfo.name; + return self.spaceChildInfo.childRoomId; } return roomSummary.roomId; } From ebcc6daf258a0f239db2143c6b0e71a6c4a3d0be Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Sat, 2 Oct 2021 02:06:52 +0300 Subject: [PATCH 07/12] Refactor recent cell data --- .../Controllers/MXKRecentListViewController.m | 2 +- MatrixKit/Models/RoomList/MXKRecentCellData.m | 62 +++++++------------ .../RoomList/MXKRecentCellDataStoring.h | 19 ------ .../RoomList/MXKSessionRecentsDataSource.m | 5 +- 4 files changed, 27 insertions(+), 61 deletions(-) diff --git a/MatrixKit/Controllers/MXKRecentListViewController.m b/MatrixKit/Controllers/MXKRecentListViewController.m index 61c48796a..0915d5012 100644 --- a/MatrixKit/Controllers/MXKRecentListViewController.m +++ b/MatrixKit/Controllers/MXKRecentListViewController.m @@ -471,7 +471,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (recentCellData.isSuggestedRoom) { [_delegate recentListViewController:self - didSelectSuggestedRoom:recentCellData.spaceChildInfo]; + didSelectSuggestedRoom:recentCellData.roomSummary.spaceChildInfo]; } else { diff --git a/MatrixKit/Models/RoomList/MXKRecentCellData.m b/MatrixKit/Models/RoomList/MXKRecentCellData.m index f08175bd1..c3cf42f6f 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellData.m +++ b/MatrixKit/Models/RoomList/MXKRecentCellData.m @@ -22,7 +22,7 @@ #import @implementation MXKRecentCellData -@synthesize roomSummary, spaceChildInfo, dataSource, roomDisplayname, lastEventTextMessage, lastEventAttributedTextMessage, lastEventDate; +@synthesize roomSummary, dataSource, lastEventDate; - (instancetype)initWithRoomSummary:(id)theRoomSummary dataSource:(MXKDataSource*)theDataSource; @@ -32,47 +32,13 @@ - (instancetype)initWithRoomSummary:(id)theRoomSummary { roomSummary = theRoomSummary; dataSource = theDataSource; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update) name:kMXRoomSummaryDidChangeNotification object:roomSummary]; - - [self update]; - } - return self; -} - -- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)theSpaceChildInfo dataSource:(MXKDataSource*)theDataSource; -{ - self = [self init]; - if (self) - { - spaceChildInfo = theSpaceChildInfo; - dataSource = theDataSource; - - [self update]; } return self; } -- (void)update -{ - // Keep ref on displayed last event - roomDisplayname = spaceChildInfo ? spaceChildInfo.name : roomSummary.displayname; - - lastEventTextMessage = spaceChildInfo ? spaceChildInfo.topic : roomSummary.lastMessage.text; - lastEventAttributedTextMessage = spaceChildInfo ? nil : roomSummary.lastMessage.attributedText; -} - - (void)dealloc { - if (roomSummary) - { - [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXRoomSummaryDidChangeNotification object:roomSummary]; - } roomSummary = nil; - spaceChildInfo = nil; - - lastEventTextMessage = nil; - lastEventAttributedTextMessage = nil; } - (MXSession *)mxSession @@ -94,7 +60,7 @@ - (NSString *)roomIdentifier { if (self.isSuggestedRoom) { - return self.spaceChildInfo.childRoomId; + return self.roomSummary.spaceChildInfo.childRoomId; } return roomSummary.roomId; } @@ -103,7 +69,7 @@ - (NSString *)roomDisplayname { if (self.isSuggestedRoom) { - return self.spaceChildInfo.displayName; + return self.roomSummary.spaceChildInfo.displayName; } return roomSummary.displayname; } @@ -112,11 +78,29 @@ - (NSString *)avatarUrl { if (self.isSuggestedRoom) { - return self.spaceChildInfo.avatarUrl; + return self.roomSummary.spaceChildInfo.avatarUrl; } return roomSummary.avatar; } +- (NSString *)lastEventTextMessage +{ + if (self.isSuggestedRoom) + { + return roomSummary.spaceChildInfo.topic; + } + return roomSummary.lastMessage.text; +} + +- (NSAttributedString *)lastEventAttributedTextMessage +{ + if (self.isSuggestedRoom) + { + return nil; + } + return roomSummary.lastMessage.attributedText; +} + - (NSUInteger)notificationCount { return roomSummary.notificationCount; @@ -140,7 +124,7 @@ - (NSString*)description - (BOOL)isSuggestedRoom { // As off now, we only store MXSpaceChildInfo in case of suggested rooms - return self.spaceChildInfo != nil; + return self.roomSummary.spaceChildInfo != nil; } @end diff --git a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h index faf5ebfd6..8cf046696 100644 --- a/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h +++ b/MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h @@ -40,10 +40,6 @@ The `MXRoomSummaryProtocol` instance of the room for the recent displayed by the cell. */ @property (nonatomic, readonly) id roomSummary; -/** - In case of suggested rooms we store the `MXSpaceChildInfo` instance of the room - */ -@property (nonatomic, readonly) MXSpaceChildInfo *spaceChildInfo; @property (nonatomic, readonly) NSString *roomIdentifier; @property (nonatomic, readonly) NSString *roomDisplayname; @@ -70,21 +66,6 @@ - (instancetype)initWithRoomSummary:(id)roomSummary dataSource:(MXKDataSource*)dataSource; -/** - Create a new `MXKCellData` object for a new recent cell. - - @param spaceChildInfo the `MXSpaceChildInfo` object that has data about the room. - @param recentListDataSource the `MXKSessionRecentsDataSource` object that will use this instance. - @return the newly created instance. - */ -- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)spaceChildInfo - dataSource:(MXKDataSource*)dataSource; - -/** - The `MXKSessionRecentsDataSource` object calls this method when it detects a change in the room. - */ -- (void)update; - @optional /** The `lastEventTextMessage` with sets of attributes. diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m index c995df8e5..aff923109 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m @@ -300,8 +300,9 @@ - (void)loadData for (MXSpaceChildInfo *childInfo in _suggestedRooms) { - id cellData = [[class alloc] initWithSpaceChildInfo:childInfo - dataSource:self]; + id summary = [[MXRoomSummary alloc] initWithSpaceChildInfo:childInfo]; + id cellData = [[class alloc] initWithRoomSummary:summary + dataSource:self]; if (cellData) { [internalCellDataArray addObject:cellData]; From 75c84efe91cd86e2d0e86ff9af0db8267401022f Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Wed, 6 Oct 2021 11:03:42 +0300 Subject: [PATCH 08/12] Fix pod dependency --- Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 7d821c7f2..a0358c7ac 100644 --- a/Podfile +++ b/Podfile @@ -18,7 +18,7 @@ abstract_target 'MatrixKitSamplePods' do # The one used for developping both MatrixSDK and MatrixKit # Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder - pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' + #pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'libPhoneNumber-iOS', '~> 0.9.13' pod 'HPGrowingTextView', '~> 1.1' From 73a28024148cf0777a04eaf1bca3f8605588fcf4 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 8 Oct 2021 14:37:15 +0300 Subject: [PATCH 09/12] Fix Podfile --- Podfile.lock | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 0155f7a26..a1d4b2e1d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -56,6 +56,7 @@ PODS: - Realm (10.7.6): - Realm/Headers (= 10.7.6) - Realm/Headers (10.7.6) + - SwiftGen (6.5.1) - SwiftyBeaver (1.9.5) DEPENDENCIES: @@ -65,6 +66,7 @@ DEPENDENCIES: - JSQMessagesViewController (~> 7.3.5) - libPhoneNumber-iOS (~> 0.9.13) - MatrixSDK (= 0.20.4) + - SwiftGen (~> 6.3) SPEC REPOS: trunk: @@ -78,14 +80,12 @@ SPEC REPOS: - JSQSystemSoundPlayer - libbase58 - libPhoneNumber-iOS + - MatrixSDK - OLMKit - Realm + - SwiftGen - SwiftyBeaver -EXTERNAL SOURCES: - MatrixSDK: - :path: "../matrix-ios-sdk/MatrixSDK.podspec" - SPEC CHECKSUMS: AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce Down: b6ba1bc985c9d2f4e15e3b293d2207766fa12612 @@ -100,8 +100,9 @@ SPEC CHECKSUMS: MatrixSDK: 317928f6ef7bbffebbf7dbf9ca9dad4920695f1e OLMKit: 9fb4799c4a044dd2c06bda31ec31a12191ad30b5 Realm: ed860452717c8db8f4bf832b6807f7f2ce708839 + SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82 -PODFILE CHECKSUM: a2a9b1e23c0e1fa628bfb188c6cf75de2b89676a +PODFILE CHECKSUM: f0a39c91b74a47c44e43cf246f2608d396306796 -COCOAPODS: 1.10.2 +COCOAPODS: 1.10.1 From 082048341c31d85c2d75347b761866c2285e7f1a Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 8 Oct 2021 14:41:48 +0300 Subject: [PATCH 10/12] Revert Podfile.lock changes --- Podfile.lock | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index a1d4b2e1d..72ead947d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -56,7 +56,6 @@ PODS: - Realm (10.7.6): - Realm/Headers (= 10.7.6) - Realm/Headers (10.7.6) - - SwiftGen (6.5.1) - SwiftyBeaver (1.9.5) DEPENDENCIES: @@ -66,7 +65,6 @@ DEPENDENCIES: - JSQMessagesViewController (~> 7.3.5) - libPhoneNumber-iOS (~> 0.9.13) - MatrixSDK (= 0.20.4) - - SwiftGen (~> 6.3) SPEC REPOS: trunk: @@ -83,7 +81,6 @@ SPEC REPOS: - MatrixSDK - OLMKit - Realm - - SwiftGen - SwiftyBeaver SPEC CHECKSUMS: @@ -100,9 +97,8 @@ SPEC CHECKSUMS: MatrixSDK: 317928f6ef7bbffebbf7dbf9ca9dad4920695f1e OLMKit: 9fb4799c4a044dd2c06bda31ec31a12191ad30b5 Realm: ed860452717c8db8f4bf832b6807f7f2ce708839 - SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82 -PODFILE CHECKSUM: f0a39c91b74a47c44e43cf246f2608d396306796 +PODFILE CHECKSUM: a2a9b1e23c0e1fa628bfb188c6cf75de2b89676a COCOAPODS: 1.10.1 From 476a17bd3337379fa588d8fe92884f2fb76ae897 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Mon, 18 Oct 2021 18:25:31 +0300 Subject: [PATCH 11/12] Add changelogs --- changelog.d/4384.api | 1 + changelog.d/4384.change | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog.d/4384.api create mode 100644 changelog.d/4384.change diff --git a/changelog.d/4384.api b/changelog.d/4384.api new file mode 100644 index 000000000..2df2622d8 --- /dev/null +++ b/changelog.d/4384.api @@ -0,0 +1 @@ +MXKRecentsDataSource & MXKSessionRecentsDataSource: Remove `markAllAsRead` methods. diff --git a/changelog.d/4384.change b/changelog.d/4384.change new file mode 100644 index 000000000..ff21fd267 --- /dev/null +++ b/changelog.d/4384.change @@ -0,0 +1 @@ +MXKRecentCellDataStoring: New initializer & `roomIdentifier` and `avatarUrl` properties. From 992ce7d5fd469fc5beebf8ef3ac8a751a37c0c82 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Tue, 19 Oct 2021 16:33:40 +0300 Subject: [PATCH 12/12] Deprecate MXKSessionRecentsDataSource class --- MatrixKit/Models/MXKAppSettings.h | 10 ------- MatrixKit/Models/MXKAppSettings.m | 30 ------------------- .../RoomList/MXKSessionRecentsDataSource.h | 2 ++ .../RoomList/MXKSessionRecentsDataSource.m | 26 ++++------------ MatrixKit/Utils/MXKConstants.h | 3 ++ 5 files changed, 10 insertions(+), 61 deletions(-) diff --git a/MatrixKit/Models/MXKAppSettings.h b/MatrixKit/Models/MXKAppSettings.h index 483f7c6d3..710e1d5db 100644 --- a/MatrixKit/Models/MXKAppSettings.h +++ b/MatrixKit/Models/MXKAppSettings.h @@ -261,16 +261,6 @@ typedef NS_ENUM(NSUInteger, MXKKeyPreSharingStrategy) */ @property (nonatomic, getter=isCallKitEnabled) BOOL enableCallKit; -#pragma mark - Spaces - -/** - Return YES if the user wants to display all rooms in home - - This boolean value is defined in shared settings object with the key: `showAllRoomsInHomeSpace`. - Return NO if no value is defined. - */ -@property (nonatomic) BOOL showAllRoomsInHomeSpace; - #pragma mark - Shared userDefaults /** diff --git a/MatrixKit/Models/MXKAppSettings.m b/MatrixKit/Models/MXKAppSettings.m index 1f3bc5a6f..7365fc8c2 100644 --- a/MatrixKit/Models/MXKAppSettings.m +++ b/MatrixKit/Models/MXKAppSettings.m @@ -48,7 +48,6 @@ @implementation MXKAppSettings @synthesize syncLocalContacts, syncLocalContactsPermissionRequested, syncLocalContactsPermissionOpenedSystemSettings, phonebookCountryCode; @synthesize presenceColorForOnlineUser, presenceColorForUnavailableUser, presenceColorForOfflineUser; @synthesize enableCallKit; -@synthesize showAllRoomsInHomeSpace; @synthesize sharedUserDefaults; + (MXKAppSettings *)standardAppSettings @@ -126,7 +125,6 @@ -(instancetype)init _allowPushKitPushers = NO; _notificationBodyLocalizationKey = @"MESSAGE"; enableCallKit = YES; - showAllRoomsInHomeSpace = NO; eventsFilterForMessages = @[ kMXEventTypeStringRoomCreate, @@ -227,7 +225,6 @@ - (void)reset [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"firstURLDetectionIgnoredHosts"]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableCallKit"]; - [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"showAllRoomsInHomeSpace"]; } else { @@ -252,7 +249,6 @@ - (void)reset httpsLinkScheme = @"https"; enableCallKit = YES; - showAllRoomsInHomeSpace = NO; } } @@ -865,30 +861,4 @@ - (void)setEnableCallKit:(BOOL)enable } } -#pragma mark - Spaces - -- (BOOL)showAllRoomsInHomeSpace -{ - if (self == [MXKAppSettings standardAppSettings]) - { - return [[NSUserDefaults standardUserDefaults] boolForKey:@"showAllRoomsInHomeSpace"]; - } - else - { - return showAllRoomsInHomeSpace; - } -} - -- (void)setShowAllRoomsInHomeSpace:(BOOL)enable -{ - if (self == [MXKAppSettings standardAppSettings]) - { - [[NSUserDefaults standardUserDefaults] setBool:enable forKey:@"showAllRoomsInHomeSpace"]; - } - else - { - showAllRoomsInHomeSpace = enable; - } -} - @end diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h index 78dc64189..e3b1eb9e6 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.h @@ -18,6 +18,7 @@ #import #import +#import "MXKConstants.h" #import "MXKDataSource.h" #import "MXKRecentCellData.h" @@ -31,6 +32,7 @@ extern NSString *const kMXKRecentCellIdentifier; /** The recents data source based on a unique matrix session. */ +MXK_DEPRECATED_ATTRIBUTE_WITH_MSG("See MXSession.roomListDataManager") @interface MXKSessionRecentsDataSource : MXKDataSource { @protected diff --git a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m index 2de40e7f0..494dad58c 100644 --- a/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m +++ b/MatrixKit/Models/RoomList/MXKSessionRecentsDataSource.m @@ -279,6 +279,10 @@ - (CGFloat)cellHeightAtIndex:(NSInteger)index } #pragma mark - Events processing + +/** + Filtering in this method won't have any effect anymore. This class is not maintained. + */ - (void)loadData { [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXRoomSummaryDidChangeNotification object:nil]; @@ -304,8 +308,6 @@ - (void)loadData NSDate *startDate = [NSDate date]; - BOOL showAllRoomsInHomeSpace = [MXKAppSettings standardAppSettings].showAllRoomsInHomeSpace; - for (MXRoomSummary *roomSummary in self.mxSession.roomsSummaries) { // Filter out private rooms with conference users @@ -315,25 +317,7 @@ - (void)loadData id cellData = [[class alloc] initWithRoomSummary:roomSummary dataSource:self]; if (cellData) { - if (self.currentSpace == nil) - { - // In case of home space we show a room if one of the following conditions is true: - // - Show All Rooms is enabled - // - the space service has not been initialised (prevents to have empty rooms list while the space service is loading) - // - It's a direct room - // - The room is a favourite - // - The room is orphaned - if (showAllRoomsInHomeSpace || !self.mxSession.spaceService.isInitialised || roomSummary.isDirect || roomSummary.room.accountData.tags[kMXRoomTagFavourite] || [self.mxSession.spaceService isOrphanedRoomWithId:roomSummary.roomId]) { - [internalCellDataArray addObject:cellData]; - } - } - else - { - if ([self.mxSession.spaceService isRoomWithId:roomSummary.roomId descendantOf:self.currentSpace.spaceId]) - { - [internalCellDataArray addObject:cellData]; - } - } + [internalCellDataArray addObject:cellData]; } } } diff --git a/MatrixKit/Utils/MXKConstants.h b/MatrixKit/Utils/MXKConstants.h index 7a5659b8c..b580d234e 100644 --- a/MatrixKit/Utils/MXKConstants.h +++ b/MatrixKit/Utils/MXKConstants.h @@ -17,6 +17,9 @@ #import +#define MXK_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) +#define MXK_DEPRECATED_ATTRIBUTE_WITH_MSG(msg) __attribute((deprecated((msg)))) + /** The Matrix iOS Kit version. */