Improve handling of attachments with captions.

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

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

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

Loading…
Cancel
Save