From 37e0b1a0048769ded656cfe376d7109a2c2e308d Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 25 May 2017 10:45:42 -0700 Subject: [PATCH] Sending to unconfirmed idnetity presents confirmation Rather than send/fail // FREEBIE --- Podfile.lock | 2 +- .../ViewControllers/MessagesViewController.m | 92 ++++++++++++++++++- .../translations/en.lproj/Localizable.strings | 11 ++- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 235a7ed58..016feb45b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -136,7 +136,7 @@ CHECKOUT OPTIONS: :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :git: https://github.com/WhisperSystems/JSQMessagesViewController.git SignalServiceKit: - :commit: 0201fa34ce760351149dd33674353d9e7edea32f + :commit: 0eef7ccb8fdaad7a119468b4b66f6bc565cfa346 :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index 65b5ceb9d..edf04c49d 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -1519,7 +1519,80 @@ typedef enum : NSUInteger { } -#pragma mark - Fingerprints +#pragma mark - Identity + +/** + * Returns the first unconfirmed recipient identity in the thread. + */ +- (nullable OWSRecipientIdentity *)unconfirmedIdentityThatShouldBlockSending +{ + for (NSString *recipientId in self.thread.recipientIdentifiers) { + OWSRecipientIdentity *unconfirmedIdentity = + [self.storageManager unconfirmedIdentityThatShouldBlockSendingForRecipientId:recipientId]; + if (unconfirmedIdentity != nil) { + DDLogInfo(@"%@ unconfirmedIdentityThatShouldBlockSending: %@", self.tag, recipientId); + return unconfirmedIdentity; + } + } + return nil; +} + +- (void)showConfirmIdentityUIForRecipientIdentity:(OWSRecipientIdentity *)recipientIdentity + completion:(void (^)(BOOL didConfirmedIdentity))completionHandler +{ + NSString *displayName = [self.contactsManager displayNameForPhoneIdentifier:recipientIdentity.recipientId]; + + NSString *titleFormat = NSLocalizedString(@"CONFIRM_SENDING_TO_CHANGED_IDENTITY_TITLE_FORMAT", + @"Action sheet title presented when a users's SN have recently changed. Embeds {{contact's name or phone " + @"number}}"); + NSString *title = [NSString stringWithFormat:titleFormat, displayName]; + + NSString *bodyFormat = NSLocalizedString(@"CONFIRM_SENDING_TO_CHANGED_IDENTITY_BODY_FORMAT", + @"Action sheet body presented when a users's SN have recently changed. Embeds {{contact's name or phone " + @"number}}"); + NSString *body = [NSString stringWithFormat:bodyFormat, displayName]; + + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:title + message:body + preferredStyle:UIAlertControllerStyleActionSheet]; + + [actionSheet + addAction:[UIAlertAction + actionWithTitle: + NSLocalizedString(@"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION", + @"button title to confirm sending to a recipient whose safety number recently changed") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + DDLogInfo(@"%@ Confirmed sending identity: %@", self.tag, recipientIdentity); + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] saveRemoteIdentity:recipientIdentity.identityKey + recipientId:recipientIdentity.recipientId + approvedForBlockingUse:YES + approvedForNonBlockingUse:YES]; + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(YES); + }); + }); + }]]; + + [actionSheet addAction:[UIAlertAction + actionWithTitle:NSLocalizedString(@"VERIFY_PRIVACY", @"Action sheet item") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + DDLogInfo(@"%@ verifying sending identity: %@", self.tag, recipientIdentity); + [self showFingerprintWithTheirIdentityKey:recipientIdentity.identityKey + theirSignalId:recipientIdentity.recipientId]; + completionHandler(NO); + }]]; + + [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) + style:UIAlertActionStyleCancel + handler:^(UIAlertAction *_Nonnull action) { + completionHandler(NO); + }]]; + + [self presentViewController:actionSheet animated:YES completion:nil]; +} - (void)showFingerprintWithTheirIdentityKey:(NSData *)theirIdentityKey theirSignalId:(NSString *)theirSignalId { @@ -1615,6 +1688,23 @@ typedef enum : NSUInteger { return; } + OWSRecipientIdentity *unconfirmedIdentityThatShouldBlockSending = [self unconfirmedIdentityThatShouldBlockSending]; + if (unconfirmedIdentityThatShouldBlockSending != nil) { + __weak MessagesViewController *weakSelf = self; + [self showConfirmIdentityUIForRecipientIdentity:unconfirmedIdentityThatShouldBlockSending + completion:^(BOOL didConfirmedIdentity) { + if (didConfirmedIdentity) { + [weakSelf didPressSendButton:button + withMessageText:text + senderId:senderId + senderDisplayName:senderDisplayName + date:date + updateKeyboardState:NO]; + } + }]; + return; + } + text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if (text.length > 0) { diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 4e94cb32d..1d9df0ede 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -241,6 +241,12 @@ /* Button text */ "CONFIRM_LINK_NEW_DEVICE_ACTION" = "Link New Device"; +/* Action sheet body presented when a users's SN have recently changed. Embeds {{contact's name or phone number}} */ +"CONFIRM_SENDING_TO_CHANGED_IDENTITY_BODY_FORMAT" = "%@ may have reinstalled or changed devices. Verify your Safety Number with them to ensure privacy."; + +/* Action sheet title presented when a users's SN have recently changed. Embeds {{contact's name or phone number}} */ +"CONFIRM_SENDING_TO_CHANGED_IDENTITY_TITLE_FORMAT" = "Safety Number with %@ has Changed"; + /* No comment provided by engineer. */ "CONFIRMATION_TITLE" = "Confirm"; @@ -1036,6 +1042,9 @@ /* Generic text for button that retries whatever the last action was. */ "RETRY_BUTTON_TEXT" = "Retry"; +/* button title to confirm sending to a recipient whose safety number recently changed */ +"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION" = "Confirm and Send"; + /* Snippet to share {{safety number}} with a friend. sent e.g. via SMS */ "SAFETY_NUMBER_SHARE_FORMAT" = "Our Signal Safety Number:\n%@"; @@ -1346,7 +1355,7 @@ "VERIFICATION_PHONE_NUMBER_FORMAT" = "Enter the verification code we sent to %@."; /* table cell label in conversation settings */ -"VERIFY_PRIVACY" = "Verify Safety Number"; +"VERIFY_PRIVACY" = "Show Safety Number"; /* Indicates how to cancel a voice message. */ "VOICE_MESSAGE_CANCEL_INSTRUCTIONS" = "Slide to Cancel";