Crypto: Show a popup when log out and in is required

This commit is contained in:
manuroe 2016-12-16 13:43:08 +01:00
parent 5f0fe9f654
commit 5649a7f58c
2 changed files with 61 additions and 0 deletions

View file

@ -147,6 +147,11 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
Currently displayed "Call not supported" alert.
*/
MXKAlert *noCallSupportAlert;
/**
Prompt to ask the user to log in again.
*/
MXKAlert *cryptoDataCorruptedAlert;
}
@property (strong, nonatomic) MXKAlert *mxInAppNotification;
@ -356,6 +361,12 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
[noCallSupportAlert dismiss:NO];
noCallSupportAlert = nil;
}
if (cryptoDataCorruptedAlert)
{
[cryptoDataCorruptedAlert dismiss:NO];
cryptoDataCorruptedAlert = nil;
}
}
- (void)applicationDidEnterBackground:(UIApplication *)application
@ -467,6 +478,9 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
[self showErrorAsAlert:note.object];
}];
// Observe crypto data storage corruption
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSessionCryptoDidCorruptData:) name:kMXSessionCryptoDidCorruptDataNotification object:nil];
// Resume all existing matrix sessions
NSArray *mxAccounts = [MXKAccountManager sharedManager].activeAccounts;
@ -545,6 +559,11 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
NSLog(@"[AppDelegate] restoreInitialDisplay: keep visible noCall support alert");
[self showNotificationAlert:noCallSupportAlert];
}
else if (cryptoDataCorruptedAlert)
{
NSLog(@"[AppDelegate] restoreInitialDisplay: keep visible log in again");
[self showNotificationAlert:cryptoDataCorruptedAlert];
}
// Check whether an error notification is pending
else if (_errorNotification)
{
@ -641,6 +660,47 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
}
}
- (void)onSessionCryptoDidCorruptData:(NSNotification *)notification
{
NSString *userId = notification.object;
MXKAccount *account = [[MXKAccountManager sharedManager] accountForUserId:userId];
if (account)
{
if (cryptoDataCorruptedAlert)
{
[cryptoDataCorruptedAlert dismiss:NO];
}
cryptoDataCorruptedAlert = [[MXKAlert alloc] initWithTitle:nil
message:NSLocalizedStringFromTable(@"e2e_need_log_in_again", @"Vector", nil)
style:MXKAlertStyleAlert];
__weak typeof(self) weakSelf = self;
cryptoDataCorruptedAlert.cancelButtonIndex = [cryptoDataCorruptedAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"later"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->cryptoDataCorruptedAlert = nil;
}
}];
[cryptoDataCorruptedAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"settings_sign_out"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->cryptoDataCorruptedAlert = nil;
[[MXKAccountManager sharedManager] removeAccount:account completion:nil];
}];
[self showNotificationAlert:cryptoDataCorruptedAlert];
}
}
#pragma mark
- (void)popToHomeViewControllerAnimated:(BOOL)animated completion:(void (^)())completion

View file

@ -377,4 +377,5 @@
// 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.";
"e2e_need_log_in_again" = "You need to log back in to generate end-to-end encryption keys for this device and submit the public key to your homeserver.\nThis is a once off; sorry for the inconvenience.";