From c536f4f5a0898792589f4e89096fb54b1b523eeb Mon Sep 17 00:00:00 2001 From: giomfo Date: Fri, 12 Aug 2016 11:13:48 +0200 Subject: [PATCH 1/2] Redacting membership events should immediately reset the displayname & avatar of room members. vector-im/vector-ios#443 Refresh Room members list on state event redaction --- .../RoomParticipantsViewController.m | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Vector/ViewController/RoomParticipantsViewController.m b/Vector/ViewController/RoomParticipantsViewController.m index 024ea39c1..15351389b 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 kMXRoomDidFlushMessagesNotification to take into account the updated room members when the room history is flushed. + id roomDidFlushMessagesNotificationObserver; RoomMemberDetailsViewController *memberDetailsViewController; @@ -151,6 +154,12 @@ leaveRoomNotificationObserver = nil; } + if (roomDidFlushMessagesNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushMessagesNotificationObserver]; + roomDidFlushMessagesNotificationObserver = nil; + } + if (membersListener) { [self.mxRoom.liveTimeline removeListener:membersListener]; @@ -257,6 +266,11 @@ [[NSNotificationCenter defaultCenter] removeObserver:leaveRoomNotificationObserver]; leaveRoomNotificationObserver = nil; } + if (roomDidFlushMessagesNotificationObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushMessagesNotificationObserver]; + roomDidFlushMessagesNotificationObserver = nil; + } if (membersListener) { [_mxRoom.liveTimeline removeListener:membersListener]; @@ -285,6 +299,20 @@ } }]; + // Observe room history flush (sync with limited timeline, or state event redaction) + roomDidFlushMessagesNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomDidFlushMessagesNotification 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) { From b534f51cbf3734ecf096f066ff53f0f6e39feaff Mon Sep 17 00:00:00 2001 From: giomfo Date: Fri, 12 Aug 2016 16:50:27 +0200 Subject: [PATCH 2/2] Redacting membership events should immediately reset the displayname & avatar of room members. #443 Fix Manu's comments (https://github.com/matrix-org/matrix-ios-sdk/pull/118) --- Vector/AppDelegate.m | 9 +++++++++ .../RoomParticipantsViewController.m | 18 +++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) 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 15351389b..fd2a0796b 100644 --- a/Vector/ViewController/RoomParticipantsViewController.m +++ b/Vector/ViewController/RoomParticipantsViewController.m @@ -59,8 +59,8 @@ // Observe kMXSessionWillLeaveRoomNotification to be notified if the user leaves the current room. id leaveRoomNotificationObserver; - // Observe kMXRoomDidFlushMessagesNotification to take into account the updated room members when the room history is flushed. - id roomDidFlushMessagesNotificationObserver; + // Observe kMXRoomDidFlushDataNotification to take into account the updated room members when the room history is flushed. + id roomDidFlushDataNotificationObserver; RoomMemberDetailsViewController *memberDetailsViewController; @@ -154,10 +154,10 @@ leaveRoomNotificationObserver = nil; } - if (roomDidFlushMessagesNotificationObserver) + if (roomDidFlushDataNotificationObserver) { - [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushMessagesNotificationObserver]; - roomDidFlushMessagesNotificationObserver = nil; + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver]; + roomDidFlushDataNotificationObserver = nil; } if (membersListener) @@ -266,10 +266,10 @@ [[NSNotificationCenter defaultCenter] removeObserver:leaveRoomNotificationObserver]; leaveRoomNotificationObserver = nil; } - if (roomDidFlushMessagesNotificationObserver) + if (roomDidFlushDataNotificationObserver) { - [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushMessagesNotificationObserver]; - roomDidFlushMessagesNotificationObserver = nil; + [[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver]; + roomDidFlushDataNotificationObserver = nil; } if (membersListener) { @@ -300,7 +300,7 @@ }]; // Observe room history flush (sync with limited timeline, or state event redaction) - roomDidFlushMessagesNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomDidFlushMessagesNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + 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])