Skip to content

Commit

Permalink
Warn that logging out will lose E2E keys (#950).
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Jan 24, 2017
1 parent 3609426 commit d31df07
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Vector/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
59 changes: 49 additions & 10 deletions Vector/ViewController/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1594,16 +1594,55 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath

- (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
Expand Down

0 comments on commit d31df07

Please sign in to comment.