|
|
|
@ -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 @"";
|
|
|
|
|
}
|
|
|
|
|