diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 6cd859aed..dbf93d256 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 0e45eaf38..7d6630516 100644 --- a/Riot/ViewController/RoomViewController.m +++ b/Riot/ViewController/RoomViewController.m @@ -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]; }