From a8b97fb529af202c2a5b2c6117fa7b7d4ff2fac5 Mon Sep 17 00:00:00 2001 From: giomfo Date: Thu, 11 Aug 2016 17:52:43 +0200 Subject: [PATCH] Redacting membership events should immediately reset the displayname & avatar of room members. vector-im/vector-ios#443 - remove FIXME (the blocker issue SYN-724 has been fixed on server side). --- MatrixSDK/Data/MXEventTimeline.m | 13 ++++++------- MatrixSDK/Data/MXRoomState.m | 21 ++++++++------------- MatrixSDK/MXSession.h | 8 ++++++++ MatrixSDK/MXSession.m | 1 + 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/MatrixSDK/Data/MXEventTimeline.m b/MatrixSDK/Data/MXEventTimeline.m index f155626ba6..d51e7f4953 100644 --- a/MatrixSDK/Data/MXEventTimeline.m +++ b/MatrixSDK/Data/MXEventTimeline.m @@ -568,7 +568,6 @@ - (void)handleRedaction:(MXEvent*)redactionEvent // Check whether the current room state depends on this redacted event. if (!redactedEvent || redactedEvent.isState) { - // FIXME: Is @autoreleasepool block required or not here? NSMutableArray *stateEvents = [NSMutableArray arrayWithArray:_state.stateEvents]; for (NSInteger index = 0; index < stateEvents.count; index++) @@ -585,7 +584,7 @@ - (void)handleRedaction:(MXEvent*)redactionEvent [stateEvents replaceObjectAtIndex:index withObject:redactedEvent]; - // Reset the room state. //FIXME: is it possible to handle only the redacted event? + // Reset the room state. _state = [[MXRoomState alloc] initWithRoomId:room.roomId andMatrixSession:room.mxSession andDirection:YES]; [self initialiseState:stateEvents]; @@ -596,7 +595,7 @@ - (void)handleRedaction:(MXEvent*)redactionEvent } // Reset the current pagination - // FIXME: Shall we let the kMXRoomStateHasBeenRedactedNotification listener trigger this reset? (like [MXKRoomDataSource reload] do) + // FIXME: Shall we let the kMXRoomDidFlushMessagesNotification listener trigger this reset? (like [MXKRoomDataSource reload] do) [self resetPagination]; // Notify that room history has been flushed @@ -686,10 +685,10 @@ - (void)forceRoomServerSync NSLog(@"[MXEventTimeline] forceRoomServerSync failed."); - // FIXME: Reload entirely the app? -// [[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionIgnoredUsersDidChangeNotification -// object:room.mxSession -// userInfo:nil]; + // Reload entirely the app + [[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionDidCorruptDataNotification + object:room.mxSession + userInfo:nil]; }]; } diff --git a/MatrixSDK/Data/MXRoomState.m b/MatrixSDK/Data/MXRoomState.m index 8174f9c1a4..41722b21a0 100644 --- a/MatrixSDK/Data/MXRoomState.m +++ b/MatrixSDK/Data/MXRoomState.m @@ -462,8 +462,7 @@ - (void)handleStateEvent:(MXEvent*)event membersWithThirdPartyInviteTokenCache[roomMember.thirdPartyInviteToken] = roomMember; } } - else// FIXME: In case of redacted membership event (prev_content is missing see SYN-724), - // the room member is then nil: the client considers by mistake the user is no more part of the room... + else { // The user is no more part of the room. Remove him. // This case happens during back pagination: we remove here users when they are not in the room yet. @@ -568,17 +567,13 @@ - (NSString*)memberName:(NSString*)userId if (!member) { - // FIXME: In case of redacted membership event (prev_content is missing see SYN-724), - // the client considers by mistake that some users are no more part of the room. - // PATCH: we comment the following, else some redacted information re-appear spontaneously. - -// // The user may not have joined the room yet. So try to resolve display name from presence data -// // Note: This data may not be available -// MXUser* user = [mxSession userWithUserId:userId]; -// if (user && user.displayname.length) -// { -// displayName = user.displayname; -// } + // The user may not have joined the room yet. So try to resolve display name from presence data + // Note: This data may not be available + MXUser* user = [mxSession userWithUserId:userId]; + if (user && user.displayname.length) + { + displayName = user.displayname; + } } else if (member.displayname.length) { diff --git a/MatrixSDK/MXSession.h b/MatrixSDK/MXSession.h index 01c9af6353..0c2641c2e9 100644 --- a/MatrixSDK/MXSession.h +++ b/MatrixSDK/MXSession.h @@ -161,9 +161,17 @@ FOUNDATION_EXPORT NSString *const kMXSessionNotificationEventKey; /** Posted when MXSession has detected a change in the `ignoredUsers` property. + + The notification object is the concerned session (MXSession instance). */ FOUNDATION_EXPORT NSString *const kMXSessionIgnoredUsersDidChangeNotification; +/** + Posted when MXSession data have been corrupted. The listener must reload the session data with a full server sync. + + The notification object is the concerned session (MXSession instance). + */ +FOUNDATION_EXPORT NSString *const kMXSessionDidCorruptDataNotification; #pragma mark - Other constants /** diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 1f8fa8816c..6f83879992 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -40,6 +40,7 @@ NSString *const kMXSessionNotificationRoomIdKey = @"roomId"; NSString *const kMXSessionNotificationEventKey = @"event"; NSString *const kMXSessionIgnoredUsersDidChangeNotification = @"kMXSessionIgnoredUsersDidChangeNotification"; +NSString *const kMXSessionDidCorruptDataNotification = @"kMXSessionDidCorruptDataNotification"; NSString *const kMXSessionNoRoomTag = @"m.recent"; // Use the same value as matrix-react-sdk /**