From a48b963bbb6df87f8f76b464a31f95a5c149b92f Mon Sep 17 00:00:00 2001 From: Arash Tabrizian Date: Fri, 30 Mar 2018 17:53:11 +0430 Subject: [PATCH 1/2] fixes issue #1793 Confirmation popup when leaving room --- Riot/ViewController/HomeViewController.m | 36 +++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Riot/ViewController/HomeViewController.m b/Riot/ViewController/HomeViewController.m index 3c1766bb5..1c25a2f5f 100644 --- a/Riot/ViewController/HomeViewController.m +++ b/Riot/ViewController/HomeViewController.m @@ -591,7 +591,41 @@ - (IBAction)onLeaveButtonPressed:(id)sender { - [self leaveEditedRoom]; + __weak typeof(self) weakSelf = self; + + // confirm leave + NSString *promptMessage = NSLocalizedStringFromTable(@"room_participants_leave_prompt_msg", @"Vector", nil); + currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_participants_leave_prompt_title", @"Vector", nil) + message:promptMessage + preferredStyle:UIAlertControllerStyleAlert]; + + [currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + } + + }]]; + + [currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"leave", @"Vector", nil) + style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + + [self leaveEditedRoom]; + } + + }]]; + + [currentAlert mxk_setAccessibilityIdentifier:@"RoomMemberDetailsVCKickAlert"]; + [self presentViewController:currentAlert animated:YES completion:nil]; } @end From 5bff992446aba1ddbec42f21df8cd83758620d5b Mon Sep 17 00:00:00 2001 From: Arash Tabrizian Date: Wed, 11 Apr 2018 12:06:57 +0430 Subject: [PATCH 2/2] fixes 1973 - move leave confirmation to [RecentsViewController leaveEditedRoom] function --- Riot/ViewController/HomeViewController.m | 36 +------ Riot/ViewController/RecentsViewController.m | 114 +++++++++++++------- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/Riot/ViewController/HomeViewController.m b/Riot/ViewController/HomeViewController.m index 1c25a2f5f..3c1766bb5 100644 --- a/Riot/ViewController/HomeViewController.m +++ b/Riot/ViewController/HomeViewController.m @@ -591,41 +591,7 @@ - (IBAction)onLeaveButtonPressed:(id)sender { - __weak typeof(self) weakSelf = self; - - // confirm leave - NSString *promptMessage = NSLocalizedStringFromTable(@"room_participants_leave_prompt_msg", @"Vector", nil); - currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_participants_leave_prompt_title", @"Vector", nil) - message:promptMessage - preferredStyle:UIAlertControllerStyleAlert]; - - [currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { - - if (weakSelf) - { - typeof(self) self = weakSelf; - self->currentAlert = nil; - } - - }]]; - - [currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"leave", @"Vector", nil) - style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { - - if (weakSelf) - { - typeof(self) self = weakSelf; - self->currentAlert = nil; - - [self leaveEditedRoom]; - } - - }]]; - - [currentAlert mxk_setAccessibilityIdentifier:@"RoomMemberDetailsVCKickAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [self leaveEditedRoom]; } @end diff --git a/Riot/ViewController/RecentsViewController.m b/Riot/ViewController/RecentsViewController.m index 60e64e640..757348943 100644 --- a/Riot/ViewController/RecentsViewController.m +++ b/Riot/ViewController/RecentsViewController.m @@ -950,45 +950,81 @@ { if (editedRoomId) { - // Check whether the user didn't leave the room yet - MXRoom *room = [self.mainSession roomWithRoomId:editedRoomId]; - if (room) - { - [self startActivityIndicator]; - - // cancel pending uploads/downloads - // they are useless by now - [MXMediaManager cancelDownloadsInCacheFolder:room.state.roomId]; - - // TODO GFO cancel pending uploads related to this room - - NSLog(@"[RecentsViewController] Leave room (%@)", room.state.roomId); - - [room leave:^{ - - [self stopActivityIndicator]; - - // Force table refresh - [self cancelEditionMode:YES]; - - } failure:^(NSError *error) { - - NSLog(@"[RecentsViewController] Failed to leave room (%@)", room.state.roomId); - - // Notify MatrixKit user - [[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error]; - - [self stopActivityIndicator]; - - // Leave editing mode - [self cancelEditionMode:isRefreshPending]; - }]; - } - else - { - // Leave editing mode - [self cancelEditionMode:isRefreshPending]; - } + NSString *currentRoomId = editedRoomId; + + __weak typeof(self) weakSelf = self; + + // confirm leave + NSString *promptMessage = NSLocalizedStringFromTable(@"room_participants_leave_prompt_msg", @"Vector", nil); + currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_participants_leave_prompt_title", @"Vector", nil) + message:promptMessage + preferredStyle:UIAlertControllerStyleAlert]; + + [currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + } + + }]]; + + [currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"leave", @"Vector", nil) + style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + + // Check whether the user didn't leave the room yet + MXRoom *room = [self.mainSession roomWithRoomId:currentRoomId]; + if (room) + { + [self startActivityIndicator]; + + // cancel pending uploads/downloads + // they are useless by now + [MXMediaManager cancelDownloadsInCacheFolder:room.state.roomId]; + + // TODO GFO cancel pending uploads related to this room + + NSLog(@"[RecentsViewController] Leave room (%@)", room.state.roomId); + + [room leave:^{ + + [self stopActivityIndicator]; + + // Force table refresh + [self cancelEditionMode:YES]; + + } failure:^(NSError *error) { + + NSLog(@"[RecentsViewController] Failed to leave room (%@)", room.state.roomId); + + // Notify MatrixKit user + [[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error]; + + [self stopActivityIndicator]; + + // Leave editing mode + [self cancelEditionMode:isRefreshPending]; + }]; + } + else + { + // Leave editing mode + [self cancelEditionMode:isRefreshPending]; + } + } + + }]]; + + [currentAlert mxk_setAccessibilityIdentifier:@"LeaveEditedRoomAlert"]; + [self presentViewController:currentAlert animated:YES completion:nil]; } }