diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 004deaee1..4c4dbd38b 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -237,6 +237,8 @@ "settings_cryptography" = "CRYPTOGRAPHY"; "settings_sign_out" = "Sign Out"; +"settings_sign_out_confirmation" = "Are you sure?"; +"settings_sign_out_e2e_warn" = "You will lose your end-to-end encryption keys. That means you will be no more able to read old messages in encrypted rooms on this device."; "settings_profile_picture" = "Profile Picture"; "settings_display_name" = "Display Name"; "settings_first_name" = "First Name"; diff --git a/Vector/ViewController/SettingsViewController.m b/Vector/ViewController/SettingsViewController.m index afa326d6b..14d81a39d 100644 --- a/Vector/ViewController/SettingsViewController.m +++ b/Vector/ViewController/SettingsViewController.m @@ -1594,16 +1594,55 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); - (void)onSignout:(id)sender { - // Feedback: disable button and run activity indicator - UIButton *button = (UIButton*)sender; - button.enabled = NO; - [self startActivityIndicator]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - - [[MXKAccountManager sharedManager] logout]; - - }); + + [currentAlert dismiss:NO]; + + __weak typeof(self) weakSelf = self; + + NSString *message = NSLocalizedStringFromTable(@"settings_sign_out_confirmation", @"Vector", nil); + + // If the user has encrypted rooms, warn he will lose his e2e keys + MXSession* session = [[AppDelegate theDelegate].mxSessions objectAtIndex:0]; + for (MXRoom *room in session.rooms) + { + if (room.state.isEncrypted) + { + message = [message stringByAppendingString:[NSString stringWithFormat:@"\n\n%@", NSLocalizedStringFromTable(@"settings_sign_out_e2e_warn", @"Vector", nil)]]; + break; + + } + } + + // Ask confirmation + currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"settings_sign_out", @"Vector", nil) + message:message + style:MXKAlertStyleAlert]; + + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"settings_sign_out", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + // Feedback: disable button and run activity indicator + UIButton *button = (UIButton*)sender; + button.enabled = NO; + [strongSelf startActivityIndicator]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + + [[MXKAccountManager sharedManager] logout]; + + }); + }]; + + currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert){ + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + }]; + + [currentAlert showInViewController:self]; } - (void)togglePushNotifications:(id)sender