Merge branch 'charlesmchen/handleCaptions'

pull/1/head
Matthew Chen 8 years ago
commit 8ec9540b8f

@ -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"
@ -227,7 +228,11 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
- (NSString *)debugDescription - (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]; NSString *attachmentId = self.attachmentIds[0];
return [NSString stringWithFormat:@"Media Message with attachmentId:%@", attachmentId]; return [NSString stringWithFormat:@"Media Message with attachmentId:%@", attachmentId];
} else { } else {
@ -235,35 +240,53 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
} }
} }
// TODO: This method contains view-specific logic and probably belongs in NotificationsManager, not in SSK.
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
NSString *_Nullable attachmentDescription = nil;
if ([self hasAttachments]) { 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 {
return self.body; OWSFail(@"%@ message has neither body nor attachment.", self.logTag);
// TODO: We should do better here.
return @"";
} }
} }
// TODO deprecate this and implement something like previewTextWithTransaction: for all TSInteractions // TODO deprecate this and implement something like previewTextWithTransaction: for all TSInteractions
- (NSString *)description - (NSString *)description
{ {
if ([self hasAttachments]) { __block NSString *result;
NSString *attachmentId = self.attachmentIds[0]; [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId]; result = [self previewTextWithTransaction:transaction];
if (attachment) { }];
return attachment.description; return result;
} else {
return NSLocalizedString(@"UNKNOWN_ATTACHMENT_LABEL", @"In Inbox view, last message label for thread with corrupted attachment.");
}
} else {
return self.body;
}
} }
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction

@ -1153,8 +1153,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
[self handleMessageSentLocally:outgoingMessage]; [self handleMessageSentLocally:outgoingMessage];
if (!(outgoingMessage.body || outgoingMessage.hasAttachments)) { if (!(outgoingMessage.body || outgoingMessage.hasAttachments)) {
DDLogDebug( // We only want to "clone" text and attachment messages.
@"%@ Refusing to make incoming copy of non-standard message sent to self:%@", self.logTag, outgoingMessage); //
// 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; return;
} }

Loading…
Cancel
Save