Don't try to share file to untrusted identity

There's a problem with this approach - specifically we need to dismiss
the external file share view controller eventually.

But more generally, because SN can present a view controller, it's kind
success/retry handling is contextual to it's presenting view controller.

So, probably the thing to do is duplicate this logic at it's various
presentation contexts.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent a1d3e360df
commit 4e995b76f3

@ -1167,8 +1167,7 @@ typedef enum : NSUInteger {
* NO if there were no unconfirmed identities * NO if there were no unconfirmed identities
*/ */
- (BOOL)showSafetyNumberConfirmationIfNecessaryWithConfirmationText:(NSString *)confirmationText - (BOOL)showSafetyNumberConfirmationIfNecessaryWithConfirmationText:(NSString *)confirmationText
completion: completion:(void (^)(BOOL didConfirmIdentity))completionHandler
(void (^)(BOOL didConfirmedIdentity))completionHandler
{ {
return [SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:self.thread.recipientIdentifiers return [SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:self.thread.recipientIdentifiers
confirmationText:confirmationText confirmationText:confirmationText
@ -1282,31 +1281,14 @@ typedef enum : NSUInteger {
return; return;
} }
BOOL didShowSNAlert =
[self showSafetyNumberConfirmationIfNecessaryWithConfirmationText:
NSLocalizedString(@"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION",
@"button title to confirm sending to a recipient whose "
@"safety number recently changed")
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]]; text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (text.length > 0) { if (text.length > 0) {
if ([Environment.preferences soundInForeground]) { if ([Environment.preferences soundInForeground]) {
[JSQSystemSoundPlayer jsq_playMessageSentSound]; [JSQSystemSoundPlayer jsq_playMessageSentSound];
} }
TSOutgoingMessage *_Nullable outgoingMessage;
// Limit outgoing text messages to 16kb. // Limit outgoing text messages to 16kb.
// //
// We convert large text messages to attachments // We convert large text messages to attachments
@ -1317,21 +1299,24 @@ typedef enum : NSUInteger {
[SignalAttachment attachmentWithData:[text dataUsingEncoding:NSUTF8StringEncoding] [SignalAttachment attachmentWithData:[text dataUsingEncoding:NSUTF8StringEncoding]
dataUTI:SignalAttachment.kOversizeTextAttachmentUTI dataUTI:SignalAttachment.kOversizeTextAttachmentUTI
filename:nil]; filename:nil];
[self updateLastVisibleTimestamp:[ThreadUtil sendMessageWithAttachment:attachment outgoingMessage =
inThread:self.thread [ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread messageSender:self.messageSender];
messageSender:self.messageSender] if (outgoingMessage != nil) {
.timestampForSorting]; [self updateLastVisibleTimestamp:outgoingMessage.timestampForSorting];
}
} else { } else {
[self updateLastVisibleTimestamp:[ThreadUtil sendMessageWithText:text outgoingMessage =
inThread:self.thread [ThreadUtil sendMessageWithText:text inThread:self.thread messageSender:self.messageSender];
messageSender:self.messageSender] if (outgoingMessage != nil) {
.timestampForSorting]; [self updateLastVisibleTimestamp:outgoingMessage.timestampForSorting];
}
} }
self.lastMessageSentDate = [NSDate new]; self.lastMessageSentDate = [NSDate new];
[self clearUnreadMessagesIndicator]; [self clearUnreadMessagesIndicator];
if (updateKeyboardState) { // Don't pop keyboard if we popped the SN alert, else it obscures the SN alert.
if (outgoingMessage != nil && updateKeyboardState) {
[self toggleDefaultKeyboard]; [self toggleDefaultKeyboard];
} }
[self clearDraft]; [self clearDraft];
@ -3703,21 +3688,6 @@ typedef enum : NSUInteger {
return; return;
} }
BOOL didShowSNAlert = [self
showSafetyNumberConfirmationIfNecessaryWithConfirmationText:
NSLocalizedString(@"SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION",
@"button title to confirm sending to a recipient whose "
@"safety number recently changed")
completion:^(BOOL didConfirmIdentity) {
if (didConfirmIdentity) {
[weakSelf
tryToSendAttachmentIfApproved:attachment];
}
}];
if (didShowSNAlert) {
return;
}
if (attachment == nil || [attachment hasError]) { if (attachment == nil || [attachment hasError]) {
DDLogWarn(@"%@ %s Invalid attachment: %@.", DDLogWarn(@"%@ %s Invalid attachment: %@.",
self.tag, self.tag,

@ -47,9 +47,13 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.attachment); OWSAssert(self.attachment);
OWSAssert(thread); OWSAssert(thread);
TSOutgoingMessage *outgoingMessage =
[ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender]; [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]; [Environment messageThreadId:thread.uniqueId];
}
} }
- (BOOL)canSelectBlockedContact - (BOOL)canSelectBlockedContact

@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender; messageSender:(OWSMessageSender *)messageSender;
+ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment + (nullable TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender; messageSender:(OWSMessageSender *)messageSender;

@ -41,6 +41,26 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread); OWSAssert(thread);
OWSAssert(messageSender); 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 *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
TSOutgoingMessage *message = TSOutgoingMessage *message =
@ -61,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
+ (TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment + (nullable TSOutgoingMessage *)sendMessageWithAttachment:(SignalAttachment *)attachment
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageSender:(OWSMessageSender *)messageSender messageSender:(OWSMessageSender *)messageSender
{ {
@ -72,6 +92,27 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread); OWSAssert(thread);
OWSAssert(messageSender); 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 *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
TSOutgoingMessage *message = TSOutgoingMessage *message =

Loading…
Cancel
Save