RoomVC: Add a re-request keys button on message unable to decrypt

The flow has changed a bit.

#1879
This commit is contained in:
manuroe
2018-06-12 16:28:26 +02:00
parent 96cc8df856
commit 1f45b233d7
2 changed files with 37 additions and 18 deletions
+35 -15
View File
@@ -2692,7 +2692,7 @@
if (event)
{
[self showRerequestConfirmationAlert:event];
[self reRequestKeysAndShowExplanationAlert:event];
}
}
}
@@ -4600,31 +4600,51 @@
#pragma mark - Re-request encryption keys
- (void)showRerequestConfirmationAlert:(MXEvent*)event
- (void)reRequestKeysAndShowExplanationAlert:(MXEvent*)event
{
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"rerequest_keys_alert_title", @"Vector", nil)
MXWeakify(self);
__block UIAlertController *alert;
// Make the re-request
[self.mainSession.crypto reRequestRoomKeyForEvent:event];
// Observe kMXEventDidDecryptNotification to remove automatically the dialog
// if the user has shared the keys from another device
id didDecryptObserver;
didDecryptObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXEventDidDecryptNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
MXEvent *decryptedEvent = notif.object;
if ([decryptedEvent.eventId isEqualToString:event.eventId])
{
[[NSNotificationCenter defaultCenter] removeObserver:didDecryptObserver];
MXStrongifyAndReturnIfNil(self);
if (self->currentAlert == alert)
{
[self->currentAlert dismissViewControllerAnimated:YES completion:nil];
self->currentAlert = nil;
}
}
}];
// Show the explanation dialog
alert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"rerequest_keys_alert_title", @"Vector", nil)
message:NSLocalizedStringFromTable(@"rerequest_keys_alert_message", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
currentAlert = alert;
MXWeakify(self);
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
[alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[[NSNotificationCenter defaultCenter] removeObserver:didDecryptObserver];
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
}]];
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"rerequest_keys_alert_button", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
[self.mainSession.crypto reRequestRoomKeyForEvent:event];
}]];
[self presentViewController:currentAlert animated:YES completion:nil];
}