From 96b5f22799853e5391c894fac0414e010f99a607 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 15 Feb 2018 11:02:26 -0500 Subject: [PATCH] Improve handling of attachments with captions. --- .../src/Messages/Interactions/TSMessage.m | 22 ++++++++++++++----- .../src/Messages/OWSMessageSender.m | 5 +++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index 13f5512f7..cc6af66cc 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -227,7 +227,11 @@ static const NSUInteger OWSMessageSchemaVersion = 4; - (NSString *)debugDescription { - if ([self hasAttachments]) { + if ([self hasAttachments] && self.body.length > 0) { + NSString *attachmentId = self.attachmentIds[0]; + return [NSString + stringWithFormat:@"Media Message with attachmentId: %@ and caption: '%@'", attachmentId, self.body]; + } else if ([self hasAttachments]) { NSString *attachmentId = self.attachmentIds[0]; return [NSString stringWithFormat:@"Media Message with attachmentId:%@", attachmentId]; } else { @@ -237,7 +241,10 @@ static const NSUInteger OWSMessageSchemaVersion = 4; - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction { - if ([self hasAttachments]) { + if (self.body.length > 0) { + // Use the message text/caption, if any. + return self.body; + } else if ([self hasAttachments]) { NSString *attachmentId = self.attachmentIds[0]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; if (attachment) { @@ -246,14 +253,18 @@ static const NSUInteger OWSMessageSchemaVersion = 4; return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment."); } } else { - return self.body; + // TODO: We should do better here. + return @""; } } // TODO deprecate this and implement something like previewTextWithTransaction: for all TSInteractions - (NSString *)description { - if ([self hasAttachments]) { + if (self.body.length > 0) { + // Use the message text/caption, if any. + return self.body; + } else if ([self hasAttachments]) { NSString *attachmentId = self.attachmentIds[0]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId]; if (attachment) { @@ -262,7 +273,8 @@ static const NSUInteger OWSMessageSchemaVersion = 4; return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment."); } } else { - return self.body; + // TODO: We should do better here. + return @""; } } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index cb1da141c..0d0d181a9 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1153,8 +1153,9 @@ 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:%@", self.logTag, outgoingMessage); + DDLogDebug(@"%@ Refusing to make incoming copy of non-standard message sent to self: %@", + self.logTag, + outgoingMessage); return; }