Sending to unconfirmed idnetity presents confirmation

Rather than send/fail

// FREEBIE
This commit is contained in:
Michael Kirk 2017-05-25 10:45:42 -07:00
parent 643301eae6
commit 37e0b1a004
3 changed files with 102 additions and 3 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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";