Skip to content

Commit

Permalink
RoomVC: Add a re-request keys button on message unable to decrypt
Browse files Browse the repository at this point in the history
The flow has changed a bit.

#1879
  • Loading branch information
manuroe committed Jun 12, 2018
1 parent 8ca0257 commit 62d0057
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
5 changes: 2 additions & 3 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
48 changes: 34 additions & 14 deletions Riot/ViewController/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ - (BOOL)dataSource:(MXKDataSource *)dataSource shouldDoAction:(NSString *)action

if (event)
{
[self showRerequestConfirmationAlert:event];
[self reRequestKeysAndShowExplanationAlert:event];
}
}
}
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 62d0057

Please sign in to comment.