Skip to content

Commit

Permalink
fix issue on timeline bubbles not showing proper content after decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio Alescio committed Mar 1, 2023
1 parent 37a2bf0 commit a1f8ccd
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSourceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ @interface MXKRoomDataSourceManager()
*/
NSMutableDictionary *roomDataSources;

/**
The list of rooms with a late event decrypt. Causing bubbles issues
Each element is a room ID.
*/
NSMutableSet *roomDataSourcesToDestroy;

/**
Observe UIApplicationDidReceiveMemoryWarningNotification to dispose of any resources that can be recreated.
*/
id UIApplicationDidReceiveMemoryWarningNotificationObserver;

/**
Observe kMXEventDidDecryptNotification to get late decrypted events.
*/
id mxEventDidDecryptNotificationObserver;
}

@end
Expand Down Expand Up @@ -119,6 +130,7 @@ - (instancetype)initWithMatrixSession:(MXSession *)matrixSession
{
mxSession = matrixSession;
roomDataSources = [NSMutableDictionary dictionary];
roomDataSourcesToDestroy = [NSMutableSet set];
_releasePolicy = MXKRoomDataSourceManagerReleasePolicyNeverRelease;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionDidLeaveRoom:) name:kMXSessionDidLeaveRoomNotification object:nil];
Expand All @@ -138,6 +150,12 @@ - (instancetype)initWithMatrixSession:(MXSession *)matrixSession
}

}];

// Observe late decrypted events, and store rooms ids in memory
mxEventDidDecryptNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXEventDidDecryptNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
MXEvent *decryptedEvent = notif.object;
[self->roomDataSourcesToDestroy addObject:decryptedEvent.roomId];
}];
}
return self;
}
Expand All @@ -156,6 +174,11 @@ - (void)destroy
[[NSNotificationCenter defaultCenter] removeObserver:UIApplicationDidReceiveMemoryWarningNotificationObserver];
UIApplicationDidReceiveMemoryWarningNotificationObserver = nil;
}
if (mxEventDidDecryptNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:mxEventDidDecryptNotificationObserver];
mxEventDidDecryptNotificationObserver = nil;
}
}

#pragma mark
Expand Down Expand Up @@ -202,9 +225,19 @@ - (void)roomDataSourceForRoom:(NSString *)roomId create:(BOOL)create onComplete:

// If not available yet, create the room data source
MXKRoomDataSource *roomDataSource = roomDataSources[roomId];


// check if the room's dataSource has events with late decryption issues and destroys it
BOOL roomDataSourceToBeDestroyed = [roomDataSourcesToDestroy containsObject:roomId];

if (roomDataSource && roomDataSourceToBeDestroyed && create) {
[roomDataSource destroy];
roomDataSources[roomId] = nil;
roomDataSource = nil;
}

if (!roomDataSource && create && roomId)
{
[roomDataSourcesToDestroy removeObject:roomId];
[_roomDataSourceClass loadRoomDataSourceWithRoomId:roomId threadId:nil andMatrixSession:mxSession onComplete:^(id roomDataSource) {
[self addRoomDataSource:roomDataSource];
onComplete(roomDataSource);
Expand Down

0 comments on commit a1f8ccd

Please sign in to comment.