diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 9592084c4..8b875d411 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -393,3 +393,6 @@ // Crash report "google_analytics_use_prompt" = "Would you like to help improve %@ by automatically reporting anonymous crash reports and usage data?"; +// Crypto +"e2e_enabling_on_app_update" = "Riot now supports end-to-end encryption but you need to log in again to enable it.\n\nYou can do it now or later from the application settings."; + diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index b55cbd156..b68d0f51b 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -311,6 +311,9 @@ // Do not go to search mode when first opening the home [self hideSearch:NO]; + + // Do the one time check on device id + [self checkDeviceId]; } } @@ -668,6 +671,63 @@ createNewRoomImageView.hidden = (hidden ? YES : !self.searchBarHidden); } +/** + Check the existence of device id. + */ +- (void)checkDeviceId +{ + // In case of the app update for the e2e encryption, the app starts with + // no device id provided by the homeserver. + // Ask the user to login again in order to enable e2e. Ask it once + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"deviceIdAtStartupChecked"]) + { + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"deviceIdAtStartupChecked"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + // Check if there is a device id + if (!self.mainSession.matrixRestClient.credentials.deviceId) + { + NSLog(@"WARNING: The user has no device. Prompt for login again"); + + NSString *msg = NSLocalizedStringFromTable(@"e2e_enabling_on_app_update", @"Vector", nil); + + __weak typeof(self) weakSelf = self; + [currentAlert dismiss:NO]; + currentAlert = [[MXKAlert alloc] initWithTitle:nil message:msg style:MXKAlertStyleAlert]; + + currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"later"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + if (weakSelf) + { + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + } + + }]; + + [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + if (weakSelf) + { + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + [strongSelf startActivityIndicator]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + + [[MXKAccountManager sharedManager] logout]; + + }); + } + + }]; + + [currentAlert showInViewController:self]; + } + } +} + #pragma mark - Navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender