From ad554877aad32251475f7e8a51881364d984d61b Mon Sep 17 00:00:00 2001 From: Michelle Linington Date: Fri, 7 Aug 2020 10:43:47 -0700 Subject: [PATCH] IOS-723: Crash when trying to send memoji from the emoji keyboard Fixes a bug where a nil MessageBody was passed to a Swift initializer expecting non-nil. To fix, OutgoingMessagePreparer.init will now accept a nil MessageBody and process it correctly. --- .../ConversationView/ConversationViewController.m | 4 ---- SignalMessaging/utils/OutboundMessage+OWS.swift | 15 ++++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index cef9913914..b2e99df73e 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3748,8 +3748,6 @@ typedef enum : NSUInteger { - (void)didPasteAttachment:(SignalAttachment *_Nullable)attachment { - OWSLogError(@""); - // If the thing we pasted is sticker-like, send it immediately // and render it borderless. if (attachment.isBorderless) { @@ -3781,8 +3779,6 @@ typedef enum : NSUInteger { - (void)tryToSendAttachments:(NSArray *)attachments messageBody:(MessageBody *_Nullable)messageBody { - OWSLogError(@""); - DispatchMainThreadSafe(^{ __weak ConversationViewController *weakSelf = self; if ([self isBlockedConversation]) { diff --git a/SignalMessaging/utils/OutboundMessage+OWS.swift b/SignalMessaging/utils/OutboundMessage+OWS.swift index b8b6799d45..bdf65b58e0 100644 --- a/SignalMessaging/utils/OutboundMessage+OWS.swift +++ b/SignalMessaging/utils/OutboundMessage+OWS.swift @@ -6,7 +6,7 @@ import Foundation extension OutgoingMessagePreparer { @objc - public convenience init(messageBody: MessageBody, + public convenience init(messageBody: MessageBody?, mediaAttachments: [SignalAttachment], thread: TSThread, quotedReplyModel: OWSQuotedReplyModel?, @@ -14,18 +14,19 @@ extension OutgoingMessagePreparer { var attachments = mediaAttachments let truncatedText: String? - if messageBody.text.lengthOfBytes(using: .utf8) <= kOversizeTextMessageSizeThreshold { - truncatedText = messageBody.text - } else { - truncatedText = messageBody.text.truncated(toByteCount: kOversizeTextMessageSizeThreshold) - if let dataSource = DataSourceValue.dataSource(withOversizeText: messageBody.text) { + if let messageText = messageBody?.text, messageText.lengthOfBytes(using: .utf8) <= kOversizeTextMessageSizeThreshold { + truncatedText = messageText.truncated(toByteCount: kOversizeTextMessageSizeThreshold) + + if let dataSource = DataSourceValue.dataSource(withOversizeText: messageText) { let attachment = SignalAttachment.attachment(dataSource: dataSource, dataUTI: kOversizeTextAttachmentUTI) attachments.append(attachment) } else { owsFailDebug("dataSource was unexpectedly nil") } + } else { + truncatedText = messageBody?.text } let expiresInSeconds: UInt32 @@ -67,7 +68,7 @@ extension OutgoingMessagePreparer { let message = TSOutgoingMessageBuilder(thread: thread, messageBody: truncatedText, - bodyRanges: messageBody.ranges, + bodyRanges: messageBody?.ranges, expiresInSeconds: expiresInSeconds, isVoiceMessage: isVoiceMessage, quotedMessage: quotedMessage,