diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index cc6af66cc..8d2f09126 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -3,6 +3,7 @@ // #import "TSMessage.h" +#import "AppContext.h" #import "NSDate+OWS.h" #import "NSString+SSK.h" #import "TSAttachment.h" @@ -241,18 +242,37 @@ static const NSUInteger OWSMessageSchemaVersion = 4; - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction { - if (self.body.length > 0) { - // Use the message text/caption, if any. - return self.body; - } else if ([self hasAttachments]) { + NSString *_Nullable attachmentDescription = nil; + if ([self hasAttachments]) { NSString *attachmentId = self.attachmentIds[0]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; if (attachment) { - return attachment.description; + attachmentDescription = attachment.description; } else { - return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment."); + attachmentDescription = NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", + @"In Inbox view, last message label for thread with corrupted attachment."); + } + } + + NSString *_Nullable bodyDescription = nil; + if (self.body.length > 0) { + // TODO: Filter this text using something like DisplayableText. + bodyDescription = self.body; + } + + if (attachmentDescription.length > 0 && bodyDescription.length > 0) { + // Attachment with caption. + if ([CurrentAppContext() isRTL]) { + return [[bodyDescription stringByAppendingString:@": "] stringByAppendingString:attachmentDescription]; + } else { + return [[attachmentDescription stringByAppendingString:@": "] stringByAppendingString:bodyDescription]; } + } else if (bodyDescription.length > 0) { + return bodyDescription; + } else if (attachmentDescription.length > 0) { + return attachmentDescription; } else { + OWSFail(@"%@ message has neither body nor attachment.", self.logTag); // TODO: We should do better here. return @""; } @@ -273,6 +293,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4; return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment."); } } else { + OWSFail(@"%@ message has neither body nor attachment.", self.logTag); // TODO: We should do better here. return @""; } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 0d0d181a9..bbdb82ccf 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1153,7 +1153,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self handleMessageSentLocally:outgoingMessage]; if (!(outgoingMessage.body || outgoingMessage.hasAttachments)) { - DDLogDebug(@"%@ Refusing to make incoming copy of non-standard message sent to self: %@", + // We only want to "clone" text and attachment messages. + // + // This method shouldn't be called for sync messages, so this + // probably represents a bug. + OWSFail(@"%@ Refusing to make incoming copy of non-standard message sent to self: %@", self.logTag, outgoingMessage); return;