From f04123dba63a104a9ccc73bcee9a73e3883bb4a5 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 27 Mar 2018 09:24:15 +0200 Subject: [PATCH 1/2] BF: Room summary is not updated after redaction of the room display name https://github.com/vector-im/riot-ios/issues/1822 --- MatrixSDK/Data/MXRoomSummary.m | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/MatrixSDK/Data/MXRoomSummary.m b/MatrixSDK/Data/MXRoomSummary.m index 64d64a84ad..50ed0f0ba7 100644 --- a/MatrixSDK/Data/MXRoomSummary.m +++ b/MatrixSDK/Data/MXRoomSummary.m @@ -42,14 +42,10 @@ - (instancetype)initWithRoomId:(NSString *)theRoomId andMatrixSession:(MXSession if (self) { _roomId = theRoomId; - _mxSession = matrixSession; _lastMessageOthers = [NSMutableDictionary dictionary]; _others = [NSMutableDictionary dictionary]; - // Listen to the event sent state changes - // This is used to follow evolution of local echo events - // (ex: when a sentState change from sending to sentFailed) - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventDidChangeSentState:) name:kMXEventDidChangeSentStateNotification object:nil]; + [self setMatrixSession:matrixSession]; } return self; @@ -60,12 +56,26 @@ - (void)destroy NSLog(@"[MXKRoomSummary] Destroy %p - room id: %@", self, _roomId); [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXEventDidChangeSentStateNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXRoomDidFlushDataNotification object:nil]; } - (void)setMatrixSession:(MXSession *)mxSession { - _mxSession = mxSession; -} + if (!_mxSession) + { + _mxSession = mxSession; + + // Listen to the event sent state changes + // This is used to follow evolution of local echo events + // (ex: when a sentState change from sending to sentFailed) + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventDidChangeSentState:) name:kMXEventDidChangeSentStateNotification object:nil]; + + // Listen to data being flush in a room + // This is used to update the room summary in case of a state event redaction + // We may need to update the room displayname when it happens + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomDidFlushData:) name:kMXRoomDidFlushDataNotification object:nil]; + } + } - (void)save:(BOOL)commit { @@ -314,6 +324,19 @@ - (void)eventDidChangeSentState:(NSNotification *)notif } } +- (void)roomDidFlushData:(NSNotification *)notif +{ + MXRoom *room = notif.object; + if (_mxSession == room.mxSession && [_roomId isEqualToString:room.state.roomId]) + { + NSLog(@"[MXRoomSummary] roomDidFlushData: %@", _roomId); + + if ([_mxSession.roomSummaryUpdateDelegate session:_mxSession updateRoomSummary:self withStateEvents:room.state.stateEvents]) + { + [self save:YES]; + } + } +} #pragma mark - Others - (NSUInteger)localUnreadEventCount From bc4386d8c9fab11dff757af5f7400b0d766286f1 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 27 Mar 2018 15:53:12 +0200 Subject: [PATCH 2/2] BF: Room summary is not updated after redaction of the room display name Updated after Giom's remark --- MatrixSDK/Data/MXRoomSummary.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MatrixSDK/Data/MXRoomSummary.m b/MatrixSDK/Data/MXRoomSummary.m index 50ed0f0ba7..4a5c770a1c 100644 --- a/MatrixSDK/Data/MXRoomSummary.m +++ b/MatrixSDK/Data/MXRoomSummary.m @@ -331,10 +331,7 @@ - (void)roomDidFlushData:(NSNotification *)notif { NSLog(@"[MXRoomSummary] roomDidFlushData: %@", _roomId); - if ([_mxSession.roomSummaryUpdateDelegate session:_mxSession updateRoomSummary:self withStateEvents:room.state.stateEvents]) - { - [self save:YES]; - } + [self resetRoomStateData]; } }