Skip to content

Commit

Permalink
Merge pull request #509 from vector-im/vector_443
Browse files Browse the repository at this point in the history
Redacting membership events should immediately reset the displayname …
  • Loading branch information
giomfo authored Aug 12, 2016
2 parents 5f2ba4a + e11b365 commit 2b94bd5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Vector/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,15 @@ - (void)initMatrixSessions

}];

[[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];

Expand Down
28 changes: 28 additions & 0 deletions Vector/ViewController/RoomParticipantsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ @interface RoomParticipantsViewController ()

// 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;

Expand Down Expand Up @@ -151,6 +154,12 @@ - (void)destroy
leaveRoomNotificationObserver = nil;
}

if (roomDidFlushDataNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver];
roomDidFlushDataNotificationObserver = nil;
}

if (membersListener)
{
[self.mxRoom.liveTimeline removeListener:membersListener];
Expand Down Expand Up @@ -257,6 +266,11 @@ - (void)setMxRoom:(MXRoom *)mxRoom
[[NSNotificationCenter defaultCenter] removeObserver:leaveRoomNotificationObserver];
leaveRoomNotificationObserver = nil;
}
if (roomDidFlushDataNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:roomDidFlushDataNotificationObserver];
roomDidFlushDataNotificationObserver = nil;
}
if (membersListener)
{
[_mxRoom.liveTimeline removeListener:membersListener];
Expand Down Expand Up @@ -285,6 +299,20 @@ - (void)setMxRoom:(MXRoom *)mxRoom
}
}];

// 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) {
Expand Down

0 comments on commit 2b94bd5

Please # to comment.