diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index c556d8efd..d449d5cad 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -1361,6 +1361,15 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN }]; + [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionDidCorruptDataNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) { + + NSLog(@"[AppDelegate] kMXSessionDidCorruptDataNotification received. Reload the app"); + + // Reload entirely the app when a session has corrupted its data + [[AppDelegate theDelegate] reloadMatrixSessions:YES]; + + }]; + // Observe settings changes [[MXKAppSettings standardAppSettings] addObserver:self forKeyPath:@"showAllEventsInRoomHistory" options:0 context:nil]; diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index 024ea39c1..fd2a0796b 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -58,6 +58,9 @@ // Observe kMXSessionWillLeaveRoomNotification to be notified if the user leaves the current room. id leaveRoomNotificationObserver; + + // Observe kMXRoomDidFlushDataNotification to take into account the updated room members when the room history is flushed. + id roomDidFlushDataNotificationObserver; RoomMemberDetailsViewController *memberDetailsViewController; @@ -151,6 +154,12 @@ leaveRoomNotificationObserver = nil; } + if (roomDidFlushDataNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver]; + roomDidFlushDataNotificationObserver = nil; + } + if (membersListener) { [self.mxRoom.liveTimeline removeListener:membersListener]; @@ -257,6 +266,11 @@ [[NSNotificationCenter defaultCenter] removeObserver:leaveRoomNotificationObserver]; leaveRoomNotificationObserver = nil; } + if (roomDidFlushDataNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver]; + roomDidFlushDataNotificationObserver = nil; + } if (membersListener) { [_mxRoom.liveTimeline removeListener:membersListener]; @@ -285,6 +299,20 @@ } }]; + // Observe room history flush (sync with limited timeline, or state event redaction) + roomDidFlushDataNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomDidFlushDataNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + MXRoom *room = notif.object; + if (_mxRoom.mxSession == room.mxSession && [_mxRoom.state.roomId isEqualToString:room.state.roomId]) + { + // The existing room history has been flushed during server sync. Take into account the updated room members list. + [self refreshParticipantsFromRoomMembers]; + + [self.tableView reloadData]; + } + + }]; + // Register a listener for events that concern room members NSArray *mxMembersEvents = @[kMXEventTypeStringRoomMember, kMXEventTypeStringRoomThirdPartyInvite, kMXEventTypeStringRoomPowerLevels]; membersListener = [_mxRoom.liveTimeline listenToEventsOfTypes:mxMembersEvents onEvent:^(MXEvent *event, MXTimelineDirection direction, id customObject) {