From 08c9aabfd9b13fcc52c56a9de71aae4f6d14a636 Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 15 Mar 2017 15:54:50 +0100 Subject: [PATCH 1/2] UsersDeviceViewController: Add an onComplete param to the displayUsersDevices method --- Riot/ViewController/RoomViewController.m | 2 +- Riot/ViewController/UsersDevicesViewController.h | 7 ++++++- Riot/ViewController/UsersDevicesViewController.m | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Riot/ViewController/RoomViewController.m b/Riot/ViewController/RoomViewController.m index 606c01007..78f0ec942 100644 --- a/Riot/ViewController/RoomViewController.m +++ b/Riot/ViewController/RoomViewController.m @@ -2285,7 +2285,7 @@ if (unknownDevices) { UsersDevicesViewController *usersDevicesViewController = (UsersDevicesViewController *)segue.destinationViewController.childViewControllers.firstObject; - [usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.roomDataSource.mxSession]; + [usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.roomDataSource.mxSession onComplete:nil]; unknownDevices = nil; } diff --git a/Riot/ViewController/UsersDevicesViewController.h b/Riot/ViewController/UsersDevicesViewController.h index 620bee7da..4020c40fc 100644 --- a/Riot/ViewController/UsersDevicesViewController.h +++ b/Riot/ViewController/UsersDevicesViewController.h @@ -25,8 +25,13 @@ Display a map of users/devices. @param usersDevices the map to display. + @param mxSession the Matrix session. + @param onComplete a block called when the user quits the screen + doneButtonPressed is: + - YES if the user clicked the Done button, meaning he acknowledges all unknown devices. + - NO if the user clicked the Cancel button, meaning he prefers to cancel the current request. */ -- (void)displayUsersDevices:(MXUsersDevicesMap*)usersDevices andMatrixSession:(MXSession*)mxSession; +- (void)displayUsersDevices:(MXUsersDevicesMap*)usersDevices andMatrixSession:(MXSession*)mxSession onComplete:(void (^)(BOOL doneButtonPressed))onComplete; @property (weak, nonatomic) IBOutlet UITableView *tableView; diff --git a/Riot/ViewController/UsersDevicesViewController.m b/Riot/ViewController/UsersDevicesViewController.m index cbd56f45c..d07017d05 100644 --- a/Riot/ViewController/UsersDevicesViewController.m +++ b/Riot/ViewController/UsersDevicesViewController.m @@ -26,16 +26,19 @@ { MXUsersDevicesMap *usersDevices; MXSession *mxSession; + + void (^onCompleteBlock)(BOOL doneButtonPressed); } @end @implementation UsersDevicesViewController -- (void)displayUsersDevices:(MXUsersDevicesMap*)theUsersDevices andMatrixSession:(MXSession*)matrixSession; +- (void)displayUsersDevices:(MXUsersDevicesMap*)theUsersDevices andMatrixSession:(MXSession*)matrixSession onComplete:(void (^)(BOOL doneButtonPressed))onComplete { usersDevices = theUsersDevices; mxSession = matrixSession; + onCompleteBlock = onComplete; } - (void)finalizeInit @@ -228,12 +231,22 @@ [self stopActivityIndicator]; [self dismissViewControllerAnimated:YES completion:nil]; + + if (onCompleteBlock) + { + onCompleteBlock(YES); + } }]; } - (IBAction)onCancel:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; + + if (onCompleteBlock) + { + onCompleteBlock(NO); + } } #pragma mark - Private methods From 3f73d18679bb217ac701053f09822932d1b9e8f6 Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 15 Mar 2017 15:56:26 +0100 Subject: [PATCH 2/2] E2E: manage unknown devices when placing or answering a call (#1058). --- Riot/Assets/en.lproj/Vector.strings | 2 + Riot/Base.lproj/Main.storyboard | 6 +- Riot/ViewController/CallViewController.m | 111 +++++++++++++++++++++++ 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 2f180d932..f66690fef 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -226,6 +226,8 @@ "unknown_devices_alert_title" = "Room contains unknown devices"; "unknown_devices_alert" = "This room contains unknown devices which have not been verified.\nThis means there is no guarantee that the devices belong to the users they claim to.\nWe recommend you go through the verification process for each device before continuing, but you can resend the message without verifying if you prefer."; "unknown_devices_send_anyway" = "Send Anyway"; +"unknown_devices_call_anyway" = "Call Anyway"; +"unknown_devices_answer_anyway" = "Answer Anyway"; "unknown_devices_verify" = "Verify..."; "unknown_devices_title" = "Unknown devices"; diff --git a/Riot/Base.lproj/Main.storyboard b/Riot/Base.lproj/Main.storyboard index 33a924ba8..69d4e5105 100644 --- a/Riot/Base.lproj/Main.storyboard +++ b/Riot/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -116,7 +116,7 @@ - + @@ -355,7 +355,7 @@ - + diff --git a/Riot/ViewController/CallViewController.m b/Riot/ViewController/CallViewController.m index b89c17190..07380eb21 100644 --- a/Riot/ViewController/CallViewController.m +++ b/Riot/ViewController/CallViewController.m @@ -26,10 +26,17 @@ #import "MXRoom+Riot.h" +#import "UsersDevicesViewController.h" + @interface CallViewController () { // Display a gradient view above the screen CAGradientLayer* gradientMaskLayer; + + /** + Current alert (if any). + */ + MXKAlert *currentAlert; } @end @@ -160,6 +167,17 @@ self.callerImageView.clipsToBounds = YES; } +- (void)viewWillDisappear:(BOOL)animated +{ + if (currentAlert) + { + [currentAlert dismiss:NO]; + currentAlert = nil; + } + + [super viewWillDisappear:animated]; +} + - (void)dealloc { } @@ -174,6 +192,99 @@ gradientMaskLayer = nil; } +#pragma mark - MXCallDelegate + +- (void)call:(MXCall *)call didEncounterError:(NSError *)error +{ + if ([error.domain isEqualToString:MXEncryptingErrorDomain] + && error.code == MXEncryptingErrorUnknownDeviceCode) + { + // There are unknown devices, check what the user wants to do + __weak __typeof(self) weakSelf = self; + + MXUsersDevicesMap *unknownDevices = error.userInfo[MXEncryptingErrorUnknownDeviceDevicesKey]; + + [currentAlert dismiss:NO]; + currentAlert = [[MXKAlert alloc] initWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert_title"] + message:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert"] + style:MXKAlertStyleAlert]; + + [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_verify"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + + // Get the UsersDevicesViewController from the storyboard + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; + UsersDevicesViewController *usersDevicesViewController = [storyboard instantiateViewControllerWithIdentifier:@"UsersDevicesViewControllerStoryboardId"]; + + [usersDevicesViewController displayUsersDevices:unknownDevices andMatrixSession:self.mainSession onComplete:^(BOOL doneButtonPressed) { + + if (doneButtonPressed) + { + // Retry the call + if (call.isIncoming) + { + [call answer]; + } + else + { + [call callWithVideo:call.isVideoCall]; + } + } + else + { + // Ignore the call + [call hangup]; + } + }]; + + // Show this screen within a navigation controller + UINavigationController *usersDevicesNavigationController = [[UINavigationController alloc] init]; + [usersDevicesNavigationController pushViewController:usersDevicesViewController animated:NO]; + + [self presentViewController:usersDevicesNavigationController animated:YES completion:nil]; + + } + }]; + + [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:(call.isIncoming ? @"unknown_devices_answer_anyway":@"unknown_devices_call_anyway")] + style:MXKAlertActionStyleDefault + handler:^(MXKAlert *alert) { + if (weakSelf) + { + typeof(self) self = weakSelf; + self->currentAlert = nil; + + // Acknowledge the existence of all devices + [self startActivityIndicator]; + [self.mainSession.crypto setDevicesKnown:unknownDevices complete:^{ + + [self stopActivityIndicator]; + + // Retry the call + if (call.isIncoming) + { + [call answer]; + } + else + { + [call callWithVideo:call.isVideoCall]; + } + }]; + } + }]; + + currentAlert.mxkAccessibilityIdentifier = @"CallVCUnknownDevicesAlert"; + [currentAlert showInViewController:self]; + } + else + { + [super call:call didEncounterError:error]; + } +} + #pragma mark - Properties - (UIImage*)picturePlaceholder