Properly dismiss file view after proceeding with share to no-longer

verified identity

// FREEBIE
This commit is contained in:
Michael Kirk 2017-06-07 15:31:54 -04:00
parent 4e995b76f3
commit f7468acad2
5 changed files with 65 additions and 67 deletions

View File

@ -29,3 +29,8 @@ import Foundation
static let missedCallWithIdentityChangeNotificationBodyWithoutCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITHOUT_CALLER_NAME", comment: "notification title")
static let missedCallWithIdentityChangeNotificationBodyWithCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITH_CALLER_NAME", comment: "notification title. Embeds {{caller's name or phone number}}")
}
@objc class SafetyNumberStrings: NSObject {
static let confirmSendButton = NSLocalizedString("SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION",
comment: "button title to confirm sending to a recipient whose safety number recently changed")
}

View File

@ -1281,14 +1281,28 @@ typedef enum : NSUInteger {
return;
}
BOOL didShowSNAlert =
[self showSafetyNumberConfirmationIfNecessaryWithConfirmationText:[SafetyNumberStrings confirmSendButton]
completion:^(BOOL didConfirmIdentity) {
if (didConfirmIdentity) {
[weakSelf didPressSendButton:button
withMessageText:text
senderId:senderId
senderDisplayName:senderDisplayName
date:date
updateKeyboardState:NO];
}
}];
if (didShowSNAlert) {
return;
}
text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (text.length > 0) {
if ([Environment.preferences soundInForeground]) {
[JSQSystemSoundPlayer jsq_playMessageSentSound];
}
TSOutgoingMessage *_Nullable outgoingMessage;
// Limit outgoing text messages to 16kb.
//
// We convert large text messages to attachments
@ -1299,24 +1313,21 @@ typedef enum : NSUInteger {
[SignalAttachment attachmentWithData:[text dataUsingEncoding:NSUTF8StringEncoding]
dataUTI:SignalAttachment.kOversizeTextAttachmentUTI
filename:nil];
outgoingMessage =
[ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread messageSender:self.messageSender];
if (outgoingMessage != nil) {
[self updateLastVisibleTimestamp:outgoingMessage.timestampForSorting];
}
[self updateLastVisibleTimestamp:[ThreadUtil sendMessageWithAttachment:attachment
inThread:self.thread
messageSender:self.messageSender]
.timestampForSorting];
} else {
outgoingMessage =
[ThreadUtil sendMessageWithText:text inThread:self.thread messageSender:self.messageSender];
if (outgoingMessage != nil) {
[self updateLastVisibleTimestamp:outgoingMessage.timestampForSorting];
}
[self updateLastVisibleTimestamp:[ThreadUtil sendMessageWithText:text
inThread:self.thread
messageSender:self.messageSender]
.timestampForSorting];
}
self.lastMessageSentDate = [NSDate new];
[self clearUnreadMessagesIndicator];
// Don't pop keyboard if we popped the SN alert, else it obscures the SN alert.
if (outgoingMessage != nil && updateKeyboardState) {
if (updateKeyboardState) {
[self toggleDefaultKeyboard];
}
[self clearDraft];
@ -3688,6 +3699,18 @@ typedef enum : NSUInteger {
return;
}
BOOL didShowSNAlert = [self
showSafetyNumberConfirmationIfNecessaryWithConfirmationText:[SafetyNumberStrings confirmSendButton]
completion:^(BOOL didConfirmIdentity) {
if (didConfirmIdentity) {
[weakSelf
tryToSendAttachmentIfApproved:attachment];
}
}];
if (didShowSNAlert) {
return;
}
if (attachment == nil || [attachment hasError]) {
DDLogWarn(@"%@ %s Invalid attachment: %@.",
self.tag,

View File

@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SendExternalFileViewController () <SelectThreadViewControllerDelegate>
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@end
@ -35,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
{
[super loadView];
_contactsManager = [Environment getCurrent].contactsManager;
_messageSender = [Environment getCurrent].messageSender;
self.title = NSLocalizedString(@"SEND_EXTERNAL_FILE_VIEW_TITLE", @"Title for the 'send external file' view.");
@ -47,13 +49,22 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.attachment);
OWSAssert(thread);
TSOutgoingMessage *outgoingMessage =
[ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender];
// Don't pop to thread if we were blocked from creating an outgoing message by untrusted SN.
if (outgoingMessage != nil) {
[Environment messageThreadId:thread.uniqueId];
BOOL didShowSNAlert =
[SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:thread.recipientIdentifiers
confirmationText:[SafetyNumberStrings confirmSendButton]
contactsManager:self.contactsManager
completion:^(BOOL didConfirm) {
if (didConfirm) {
[self threadWasSelected:thread];
}
}];
if (didShowSNAlert) {
return;
}
[ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender];
[Environment messageThreadId:thread.uniqueId];
}
- (BOOL)canSelectBlockedContact

View File

@ -50,9 +50,9 @@ NS_ASSUME_NONNULL_BEGIN
inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender;
+ (nullable TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender;
+ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender;
// This method will create and/or remove any offers and indicators
// necessary for this thread. This includes:

View File

@ -41,26 +41,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread);
OWSAssert(messageSender);
OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager;
OWSAssert(contactsManager);
BOOL didShowSNAlert = [SafetyNumberConfirmationAlert
presentAlertIfNecessaryWithRecipientIds:thread.recipientIdentifiers
confirmationText:NSLocalizedString(@"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION",
@"button title to confirm sending to a recipient whose safety "
@"number recently changed")
contactsManager:contactsManager
completion:^(BOOL didConfirmIdentity) {
if (didConfirmIdentity) {
[self sendMessageWithText:text
inThread:thread
messageSender:messageSender];
}
}];
if (didShowSNAlert) {
return nil;
}
OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
TSOutgoingMessage *message =
@ -81,9 +61,9 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (nullable TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender
+ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender
{
OWSAssert([NSThread isMainThread]);
OWSAssert(attachment);
@ -92,27 +72,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread);
OWSAssert(messageSender);
OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager;
OWSAssert(contactsManager);
BOOL didShowSNAlert = [SafetyNumberConfirmationAlert
presentAlertIfNecessaryWithRecipientIds:thread.recipientIdentifiers
confirmationText:NSLocalizedString(@"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION",
@"button title to confirm sending to a recipient whose safety "
@"number recently changed")
contactsManager:contactsManager
completion:^(BOOL didConfirmIdentity) {
if (didConfirmIdentity) {
[self sendMessageWithAttachment:attachment
inThread:thread
messageSender:messageSender];
}
}];
if (didShowSNAlert) {
return nil;
}
OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
TSOutgoingMessage *message =