Dismiss room member view controller when user leaves the related room.

This commit is contained in:
giomfo 2015-04-16 14:20:40 +02:00
parent 49f933eb3a
commit 66277b6158
2 changed files with 23 additions and 2 deletions

View file

@ -31,6 +31,9 @@
// mask view while processing a request
UIView* pendingRequestMask;
UIActivityIndicatorView * pendingMaskSpinnerView;
// Observe left rooms
id kMXSessionWillLeaveRoomNotificationObserver;
}
// graphical objects
@ -111,14 +114,29 @@
}
}
}];
// Observe kMXSessionWillLeaveRoomNotification to be notified if the user leaves the current room.
kMXSessionWillLeaveRoomNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionWillLeaveRoomNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
// Check whether the user will leave the room related to the displayed member
if (notif.object == self.mxSession) {
NSString *roomId = notif.userInfo[@"roomId"];
if (roomId && [roomId isEqualToString:mxRoom.state.roomId]) {
// We must dismiss the current view controller.
[self dismiss];
}
}
}];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// Remove any pending observers
// Remove observers
[[NSNotificationCenter defaultCenter] removeObserver:kMXSessionWillLeaveRoomNotificationObserver];
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (imageLoader) {
[imageLoader cancel];
imageLoader = nil;
@ -158,8 +176,10 @@
membersListener = nil;
}
// Remove any pending observers
// Remove observers
[[NSNotificationCenter defaultCenter] removeObserver:kMXSessionWillLeaveRoomNotificationObserver];
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (imageLoader) {
[imageLoader cancel];
imageLoader = nil;

View file

@ -81,6 +81,7 @@
if ([[segue destinationViewController] isKindOfClass:[MemberViewController class]]) {
if (selectedMember) {
currentMemberViewController = (MemberViewController *)[segue destinationViewController];
currentMemberViewController.mxSession = self.mxSession;
currentMemberViewController.mxRoomMember = selectedMember;
currentMemberViewController.mxRoom = [[MatrixSDKHandler sharedHandler].mxSession roomWithRoomId:self.dataSource.roomId];
}