Improve handling of attachments with captions.

pull/1/head
Matthew Chen 7 years ago
parent 96b5f22799
commit 8576da791c

@ -3,6 +3,7 @@
// //
#import "TSMessage.h" #import "TSMessage.h"
#import "AppContext.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "NSString+SSK.h" #import "NSString+SSK.h"
#import "TSAttachment.h" #import "TSAttachment.h"
@ -241,18 +242,37 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
if (self.body.length > 0) { NSString *_Nullable attachmentDescription = nil;
// Use the message text/caption, if any. if ([self hasAttachments]) {
return self.body;
} else if ([self hasAttachments]) {
NSString *attachmentId = self.attachmentIds[0]; NSString *attachmentId = self.attachmentIds[0];
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
if (attachment) { if (attachment) {
return attachment.description; attachmentDescription = attachment.description;
} else { } 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 { } else {
OWSFail(@"%@ message has neither body nor attachment.", self.logTag);
// TODO: We should do better here. // TODO: We should do better here.
return @""; 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."); return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment.");
} }
} else { } else {
OWSFail(@"%@ message has neither body nor attachment.", self.logTag);
// TODO: We should do better here. // TODO: We should do better here.
return @""; return @"";
} }

@ -1153,7 +1153,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self handleMessageSentLocally:outgoingMessage]; [self handleMessageSentLocally:outgoingMessage];
if (!(outgoingMessage.body || outgoingMessage.hasAttachments)) { 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, self.logTag,
outgoingMessage); outgoingMessage);
return; return;

Loading…
Cancel
Save