From 62d0057af11ec481aa23ea4a932c1d9cf90687cd Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 12 Jun 2018 16:28:26 +0200 Subject: [PATCH] RoomVC: Add a re-request keys button on message unable to decrypt The flow has changed a bit. #1879 --- Riot/Assets/en.lproj/Vector.strings | 5 +-- Riot/ViewController/RoomViewController.m | 48 +++++++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 6cd859aed9..dbf93d256b 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -626,6 +626,5 @@ "deactivate_account_password_alert_message" = "To continue, please enter your password"; // Re-request confirmation dialog -"rerequest_keys_alert_title" = "Re-request encryption keys"; -"rerequest_keys_alert_message" = "Your key share request has been sent - please check your other devices for key share requests.\n\nKey share requests are sent to your other devices automatically. If you rejected or dismissed the key share request on your other devices, you can request the keys for this session again."; -"rerequest_keys_alert_button" = "Re-request"; +"rerequest_keys_alert_title" = "Request Sent"; +"rerequest_keys_alert_message" = "Please check your other devices for key share requests."; diff --git a/Riot/ViewController/RoomViewController.m b/Riot/ViewController/RoomViewController.m index 0e45eaf38f..7d6630516d 100644 --- a/Riot/ViewController/RoomViewController.m +++ b/Riot/ViewController/RoomViewController.m @@ -2692,7 +2692,7 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action if (event) { - [self showRerequestConfirmationAlert:event]; + [self reRequestKeysAndShowExplanationAlert:event]; } } } @@ -4600,29 +4600,49 @@ - (void)contactsTableViewController:(ContactsTableViewController *)contactsTable #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"] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) - { - MXStrongifyAndReturnIfNil(self); - self->currentAlert = nil; - }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"rerequest_keys_alert_button", @"Vector", nil) + [alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [[NSNotificationCenter defaultCenter] removeObserver:didDecryptObserver]; + MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; - - [self.mainSession.crypto reRequestRoomKeyForEvent:event]; }]]; [self presentViewController:currentAlert animated:YES completion:nil];