Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Lazy Load Room Summaries: Milestone 0 #910

Merged
merged 22 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3042823
Remove unused markAllAsRead methods
ismailgulek Sep 23, 2021
f5d5354
Refactor recent cell data
ismailgulek Sep 23, 2021
2a11972
Adapt cell data changes
ismailgulek Sep 23, 2021
d2a0a50
Refactor summary join rule
ismailgulek Sep 23, 2021
5bfb4b1
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Sep 28, 2021
ec88caf
Add some transitive fields on MXKCellDataStoring
ismailgulek Sep 28, 2021
0cd07bd
Fix room identifier for space room
ismailgulek Sep 28, 2021
8a16b3b
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Sep 30, 2021
ebcc6da
Refactor recent cell data
ismailgulek Oct 1, 2021
3a351f1
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 5, 2021
75c84ef
Fix pod dependency
ismailgulek Oct 6, 2021
58d28ce
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 8, 2021
73a2802
Fix Podfile
ismailgulek Oct 8, 2021
0820483
Revert Podfile.lock changes
ismailgulek Oct 8, 2021
2ca941e
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 8, 2021
267dcb2
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 12, 2021
f25e930
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 13, 2021
10d6d37
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 15, 2021
476a17b
Add changelogs
ismailgulek Oct 18, 2021
a6707e7
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 19, 2021
992ce7d
Deprecate MXKSessionRecentsDataSource class
ismailgulek Oct 19, 2021
5ad7501
Merge branch 'develop' into ismail/4384_room_summary_store
ismailgulek Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions MatrixKit/Controllers/MXKRecentListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
id<MXKRecentCellDataStoring> recentCellData = (id<MXKRecentCellDataStoring>)cellData;
if (recentCellData.isSuggestedRoom)
{
[_delegate recentListViewController:self didSelectSuggestedRoom:recentCellData.spaceChildInfo];
[_delegate recentListViewController:self
didSelectSuggestedRoom:recentCellData.roomSummary.spaceChildInfo];
}
else
{
[_delegate recentListViewController:self didSelectRoom:recentCellData.roomSummary.roomId inMatrixSession:recentCellData.roomSummary.mxSession];
[_delegate recentListViewController:self
didSelectRoom:recentCellData.roomIdentifier
inMatrixSession:recentCellData.mxSession];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ -(void)openSessionWithStore:(id<MXStore>)store
*/
- (void)closeSession:(BOOL)clearStore
{
MXLogDebug(@"[MXKAccount] closeSession (%tu)", clearStore);
MXLogDebug(@"[MXKAccount] closeSession (%u)", clearStore);

if (NSCurrentLocaleDidChangeNotificationObserver)
{
Expand Down
10 changes: 0 additions & 10 deletions MatrixKit/Models/MXKAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
30 changes: 0 additions & 30 deletions MatrixKit/Models/MXKAppSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ @implementation MXKAppSettings
@synthesize syncLocalContacts, syncLocalContactsPermissionRequested, syncLocalContactsPermissionOpenedSystemSettings, phonebookCountryCode;
@synthesize presenceColorForOnlineUser, presenceColorForUnavailableUser, presenceColorForOfflineUser;
@synthesize enableCallKit;
@synthesize showAllRoomsInHomeSpace;
@synthesize sharedUserDefaults;

+ (MXKAppSettings *)standardAppSettings
Expand Down Expand Up @@ -126,7 +125,6 @@ -(instancetype)init
_allowPushKitPushers = NO;
_notificationBodyLocalizationKey = @"MESSAGE";
enableCallKit = YES;
showAllRoomsInHomeSpace = NO;

eventsFilterForMessages = @[
kMXEventTypeStringRoomCreate,
Expand Down Expand Up @@ -227,7 +225,6 @@ - (void)reset
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"firstURLDetectionIgnoredHosts"];

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"enableCallKit"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"showAllRoomsInHomeSpace"];
}
else
{
Expand All @@ -252,7 +249,6 @@ - (void)reset
httpsLinkScheme = @"https";

enableCallKit = YES;
showAllRoomsInHomeSpace = NO;
}
}

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion MatrixKit/Models/MXKDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions MatrixKit/Models/RoomList/MXKInterleavedRecentsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ - (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath
id<MXKRecentCellDataStoring> 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++)
Expand Down Expand Up @@ -257,7 +258,7 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe
for (NSInteger index = 0; index < recentsDataSource.numberOfCells; index ++)
{
id<MXKRecentCellDataStoring> recentCellData = [recentsDataSource cellDataAtIndex:index];
if ([roomId isEqualToString:recentCellData.roomSummary.roomId])
if ([roomId isEqualToString:recentCellData.roomIdentifier])
{
// Got it
indexPath = [NSIndexPath indexPathForRow:index inSection:0];
Expand All @@ -280,7 +281,7 @@ - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSe
for (NSInteger index = 0; index < interleavedCellDataArray.count; index ++)
{
id<MXKRecentCellDataStoring> recentCellData = interleavedCellDataArray[index];
if ([roomId isEqualToString:recentCellData.roomSummary.roomId])
if ([roomId isEqualToString:recentCellData.roomIdentifier])
{
// Got it
indexPath = [NSIndexPath indexPathForRow:index inSection:0];
Expand Down Expand Up @@ -408,7 +409,7 @@ - (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes
id<MXKRecentCellDataStoring> currentCellData = interleavedCellDataArray[currentCellIndex];

// Remove existing cell data of the updated data source
if (currentCellData.recentsDataSource == dataSource)
if (currentCellData.dataSource == dataSource)
{
[interleavedCellDataArray removeObjectAtIndex:currentCellIndex];
}
Expand Down
90 changes: 51 additions & 39 deletions MatrixKit/Models/RoomList/MXKRecentCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,88 @@

#import "MXKRecentCellData.h"

#import "MXKSessionRecentsDataSource.h"
#import "MXKDataSource.h"
#import "MXEvent+MatrixKit.h"
#import <MatrixSDK/MatrixSDK-Swift.h>

@implementation MXKRecentCellData
@synthesize roomSummary, spaceChildInfo, recentsDataSource, roomDisplayname, lastEventTextMessage, lastEventAttributedTextMessage, lastEventDate;
@synthesize roomSummary, dataSource, lastEventDate;

- (instancetype)initWithRoomSummary:(MXRoomSummary*)theRoomSummary andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource
- (instancetype)initWithRoomSummary:(id<MXRoomSummaryProtocol>)theRoomSummary
dataSource:(MXKDataSource*)theDataSource;
{
self = [self init];
if (self)
{
roomSummary = theRoomSummary;
recentsDataSource = recentListDataSource;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update) name:kMXRoomSummaryDidChangeNotification object:roomSummary];

[self update];
dataSource = theDataSource;
}
return self;
}

- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)theSpaceChildInfo andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource
- (void)dealloc
{
self = [self init];
if (self)
{
spaceChildInfo = theSpaceChildInfo;
recentsDataSource = recentListDataSource;
roomSummary = nil;
}

[self update];
}
return self;
- (MXSession *)mxSession
{
return dataSource.mxSession;
}

- (void)update
- (NSString*)lastEventDate
{
// Keep ref on displayed last event
roomDisplayname = spaceChildInfo ? spaceChildInfo.name : roomSummary.displayname;
return (NSString*)roomSummary.lastMessage.others[@"lastEventDate"];
}

lastEventTextMessage = spaceChildInfo ? spaceChildInfo.topic : roomSummary.lastMessage.text;
lastEventAttributedTextMessage = spaceChildInfo ? nil : roomSummary.lastMessage.attributedText;
- (BOOL)hasUnread
{
return (roomSummary.localUnreadEventCount != 0);
}

- (void)dealloc
- (NSString *)roomIdentifier
{
if (roomSummary)
if (self.isSuggestedRoom)
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXRoomSummaryDidChangeNotification object:roomSummary];
return self.roomSummary.spaceChildInfo.childRoomId;
}
roomSummary = nil;
spaceChildInfo = nil;
return roomSummary.roomId;
}

lastEventTextMessage = nil;
lastEventAttributedTextMessage = nil;
- (NSString *)roomDisplayname
{
if (self.isSuggestedRoom)
{
return self.roomSummary.spaceChildInfo.displayName;
}
return roomSummary.displayname;
}

- (NSString*)lastEventDate
- (NSString *)avatarUrl
{
return (NSString*)roomSummary.lastMessage.others[@"lastEventDate"];
if (self.isSuggestedRoom)
{
return self.roomSummary.spaceChildInfo.avatarUrl;
}
return roomSummary.avatar;
}

- (BOOL)hasUnread
- (NSString *)lastEventTextMessage
{
return (roomSummary.localUnreadEventCount != 0);
if (self.isSuggestedRoom)
{
return roomSummary.spaceChildInfo.topic;
}
return roomSummary.lastMessage.text;
}

- (NSAttributedString *)lastEventAttributedTextMessage
{
if (self.isSuggestedRoom)
{
return nil;
}
return roomSummary.lastMessage.attributedText;
}

- (NSUInteger)notificationCount
Expand All @@ -99,11 +116,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];
Expand All @@ -112,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
42 changes: 12 additions & 30 deletions MatrixKit/Models/RoomList/MXKRecentCellDataStoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#import "MXKCellData.h"

@class MXKSessionRecentsDataSource;
@class MXKDataSource;
@class MXSpaceChildInfo;

/**
Expand All @@ -34,18 +34,16 @@
/**
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.
The `MXRoomSummaryProtocol` instance of the room for the recent displayed by the cell.
*/
@property (nonatomic, readonly) MXRoomSummary *roomSummary;
/**
In case of suggested rooms we store the `MXSpaceChildInfo` instance of the room
*/
@property (nonatomic, readonly) MXSpaceChildInfo *spaceChildInfo;
@property (nonatomic, readonly) id<MXRoomSummaryProtocol> roomSummary;

@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;

Expand All @@ -55,34 +53,18 @@
@property (nonatomic, readonly) NSString *notificationCountStringValue;
@property (nonatomic, readonly) BOOL isSuggestedRoom;

#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.
@return the newly created instance.
*/
- (instancetype)initWithRoomSummary:(MXRoomSummary*)roomSummary andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource;
@property (nonatomic, readonly) MXSession *mxSession;

#pragma mark - Public methods
/**
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.
@param roomSummary the `id<MXRoomSummaryProtocol>` object that has data about the room.
@param dataSource the `MXKDataSource` object that will use this instance.
@return the newly created instance.
*/
- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)spaceChildInfo andRecentListDataSource:(MXKSessionRecentsDataSource*)recentListDataSource;

/**
The `MXKSessionRecentsDataSource` object calls this method when it detects a change in the room.
*/
- (void)update;

/**
Mark all messages as read
*/
- (void)markAllAsRead;
- (instancetype)initWithRoomSummary:(id<MXRoomSummaryProtocol>)roomSummary
dataSource:(MXKDataSource*)dataSource;

@optional
/**
Expand Down
5 changes: 0 additions & 5 deletions MatrixKit/Models/RoomList/MXKRecentsDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,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.

Expand Down
Loading