From 7e5256856c230547b866c6275caca97bb8dc72ee Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 22 Feb 2019 17:37:03 -0700 Subject: [PATCH] render media+longText message --- .../Cells/OWSMessageBubbleView.m | 29 +-------------- .../ConversationView/ConversationViewItem.h | 1 - .../ConversationView/ConversationViewItem.m | 37 ++++++------------- .../AttachmentApprovalViewController.swift | 4 +- SignalMessaging/utils/ThreadUtil.m | 2 +- .../src/Messages/Attachments/TSAttachment.h | 3 +- .../src/Messages/Attachments/TSAttachment.m | 7 +++- .../src/Messages/Interactions/TSMessage.h | 2 - .../src/Messages/Interactions/TSMessage.m | 14 ------- 9 files changed, 23 insertions(+), 76 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 11d84f1bd..ad71ee1ab 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -217,28 +217,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes return self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage; } -#pragma mark - - -- (BOOL)hasBodyTextContent -{ - switch (self.cellType) { - case OWSMessageCellType_Unknown: - case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: - return YES; - case OWSMessageCellType_GenericAttachment: - case OWSMessageCellType_DownloadingAttachment: - case OWSMessageCellType_Audio: - // Is there a caption? - return self.hasBodyText; - case OWSMessageCellType_ContactShare: - return NO; - case OWSMessageCellType_MediaAlbum: - // Is there an album title? - return self.hasBodyText; - } -} - #pragma mark - Load - (void)configureViews @@ -296,7 +274,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes switch (self.cellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: break; case OWSMessageCellType_Audio: OWSAssertDebug(self.viewItem.attachmentStream); @@ -593,7 +570,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes switch (self.cellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_Audio: case OWSMessageCellType_GenericAttachment: case OWSMessageCellType_DownloadingAttachment: @@ -608,7 +584,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes switch (self.cellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: return NO; case OWSMessageCellType_Audio: case OWSMessageCellType_GenericAttachment: @@ -1000,8 +975,7 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes CGSize result = CGSizeZero; switch (self.cellType) { case OWSMessageCellType_Unknown: - case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: { + case OWSMessageCellType_TextMessage: { return nil; } case OWSMessageCellType_Audio: @@ -1397,7 +1371,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes switch (self.cellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: break; case OWSMessageCellType_Audio: OWSAssertDebug(self.viewItem.attachmentStream); diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h index 4a980afb9..4a04b5133 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h @@ -10,7 +10,6 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSInteger, OWSMessageCellType) { OWSMessageCellType_Unknown, OWSMessageCellType_TextMessage, - OWSMessageCellType_OversizeTextMessage, OWSMessageCellType_Audio, OWSMessageCellType_GenericAttachment, OWSMessageCellType_DownloadingAttachment, diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 49844d050..b1d5a3f04 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -22,8 +22,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (cellType) { case OWSMessageCellType_TextMessage: return @"OWSMessageCellType_TextMessage"; - case OWSMessageCellType_OversizeTextMessage: - return @"OWSMessageCellType_OversizeTextMessage"; case OWSMessageCellType_Audio: return @"OWSMessageCellType_Audio"; case OWSMessageCellType_GenericAttachment: @@ -592,27 +590,21 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) } } - NSString *_Nullable bodyText = [message bodyTextWithTransaction:transaction]; - if (bodyText) { - self.displayableBodyText = [self displayableBodyTextForText:bodyText interactionId:message.uniqueId]; - } - - // Even though displayableBodyText could have already been assigned from the oversized text - // attachment, it's also possible that for new messages we'd first cached the truncated body - // text. So if an AttachmentStream now exists we explicitly use the text from the attachment. TSAttachment *_Nullable oversizeTextAttachment = [message oversizeTextAttachmentWithTransaction:transaction]; if (oversizeTextAttachment != nil && [oversizeTextAttachment isKindOfClass:[TSAttachmentStream class]]) { TSAttachmentStream *oversizeTextAttachmentStream = (TSAttachmentStream *)oversizeTextAttachment; - self.messageCellType = OWSMessageCellType_OversizeTextMessage; self.displayableBodyText = [self displayableBodyTextForOversizeTextAttachment:oversizeTextAttachmentStream interactionId:message.uniqueId]; + } else { + NSString *_Nullable bodyText = [message bodyTextWithTransaction:transaction]; + if (bodyText) { + self.displayableBodyText = [self displayableBodyTextForText:bodyText interactionId:message.uniqueId]; + } } NSArray *mediaAttachments = [message mediaAttachmentsWithTransaction:transaction]; - if ([message isMediaAlbumWithTransaction:transaction]) { - OWSAssertDebug(mediaAttachments.count > 0); - NSArray *mediaAlbumItems = [self mediaAlbumItemsForAttachments:mediaAttachments]; - + NSArray *mediaAlbumItems = [self mediaAlbumItemsForAttachments:mediaAttachments]; + if (mediaAlbumItems.count > 0) { if (mediaAlbumItems.count == 1) { ConversationMediaAlbumItem *mediaAlbumItem = mediaAlbumItems.firstObject; if (mediaAlbumItem.attachmentStream && !mediaAlbumItem.attachmentStream.isValidVisualMedia) { @@ -629,6 +621,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) // Only media galleries should have more than one attachment. OWSAssertDebug(mediaAttachments.count <= 1); + TSAttachment *_Nullable mediaAttachment = mediaAttachments.firstObject; if (mediaAttachment) { if ([mediaAttachment isKindOfClass:[TSAttachmentStream class]]) { @@ -653,10 +646,10 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) } if (self.hasBodyText) { - // If we haven't already assigned an attachment type at this point, message.body isn't a caption, - // it's a stand-alone text message. if (self.messageCellType == OWSMessageCellType_Unknown) { - OWSAssertDebug(message.attachmentIds.count == 0); + OWSAssertDebug(message.attachmentIds.count == 0 + || (message.attachmentIds.count == 1 && + [message oversizeTextAttachmentWithTransaction:transaction] != nil)); self.messageCellType = OWSMessageCellType_TextMessage; } OWSAssertDebug(self.displayableBodyText); @@ -696,7 +689,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) - (NSArray *)mediaAlbumItemsForAttachments:(NSArray *)attachments { OWSAssertIsOnMainThread(); - OWSAssertDebug(attachments.count > 0); NSMutableArray *mediaAlbumItems = [NSMutableArray new]; for (TSAttachment *attachment in attachments) { @@ -852,7 +844,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) { switch (self.messageCellType) { case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_Audio: case OWSMessageCellType_MediaAlbum: case OWSMessageCellType_GenericAttachment: { @@ -881,7 +872,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: { OWSFailDebug(@"No media to copy"); break; @@ -932,7 +922,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: OWSFailDebug(@"No media to share."); break; @@ -968,7 +957,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: return NO; case OWSMessageCellType_Audio: @@ -992,7 +980,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: return NO; case OWSMessageCellType_Audio: @@ -1028,7 +1015,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: OWSFailDebug(@"Cannot save text data."); break; @@ -1111,7 +1097,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) switch (self.messageCellType) { case OWSMessageCellType_Unknown: case OWSMessageCellType_TextMessage: - case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_ContactShare: return NO; case OWSMessageCellType_Audio: diff --git a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift index 61b3c3918..cb179cc56 100644 --- a/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/AttachmentApprovalViewController.swift @@ -1866,7 +1866,7 @@ class MediaMessageTextToolbar: UIView, UITextViewDelegate { let proposedText: String = (existingText as NSString).replacingCharacters(in: range, with: text) // Don't complicate things by mixing media attachments with oversize text attachments - guard proposedText.utf8.count <= kOversizeTextMessageSizeThreshold else { + guard proposedText.utf8.count < kOversizeTextMessageSizeThreshold else { Logger.debug("long text was truncated") self.lengthLimitLabel.isHidden = false @@ -1887,7 +1887,7 @@ class MediaMessageTextToolbar: UIView, UITextViewDelegate { self.lengthLimitLabel.isHidden = true // After verifying the byte-length is sufficiently small, verify the character count is within bounds. - guard proposedText.count <= kMaxMessageBodyCharacterCount else { + guard proposedText.count < kMaxMessageBodyCharacterCount else { Logger.debug("hit attachment message body character count limit") self.lengthLimitLabel.isHidden = false diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index 99a0b714f..de3fd3e95 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -110,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *truncatedText; NSArray *attachments = attachmentsParam; - if ([fullMessageText lengthOfBytesUsingEncoding:NSUTF8StringEncoding] < kOversizeTextMessageSizeThreshold) { + if ([fullMessageText lengthOfBytesUsingEncoding:NSUTF8StringEncoding] <= kOversizeTextMessageSizeThreshold) { truncatedText = fullMessageText; } else { if (SSKFeatureFlags.sendingMediaWithOversizeText) { diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h index 01bb3c40f..fea89979b 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSYapDatabaseObject.h" @@ -93,6 +93,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) { @property (nonatomic, readonly) BOOL isAudio; @property (nonatomic, readonly) BOOL isVoiceMessage; @property (nonatomic, readonly) BOOL isVisualMedia; +@property (nonatomic, readonly) BOOL isOversizeText; + (NSString *)emojiForMimeType:(NSString *)contentType; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m index 29842075f..692f1ac52 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "TSAttachment.h" @@ -273,6 +273,11 @@ NSUInteger const TSAttachmentSchemaVersion = 4; return [MIMETypeUtil isVisualMedia:self.contentType]; } +- (BOOL)isOversizeText +{ + return [self.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]; +} + - (nullable NSString *)sourceFilename { return _sourceFilename.filterFilename; diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.h b/SignalServiceKit/src/Messages/Interactions/TSMessage.h index 83155957f..9f836b04c 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.h @@ -55,8 +55,6 @@ NS_ASSUME_NONNULL_BEGIN // quoted reply thumbnails, contact share avatars, link preview images, etc. - (NSArray *)allAttachmentIds; -- (BOOL)isMediaAlbumWithTransaction:(YapDatabaseReadTransaction *)transaction; - - (void)setQuotedMessageThumbnailAttachmentStream:(TSAttachmentStream *)attachmentStream; - (nullable NSString *)oversizeTextWithTransaction:(YapDatabaseReadTransaction *)transaction; diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index 0b44980da..8ccd7d19d 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -249,20 +249,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4; [self saveWithTransaction:transaction]; } -- (BOOL)isMediaAlbumWithTransaction:(YapDatabaseReadTransaction *)transaction -{ - NSArray *attachments = [self attachmentsWithTransaction:transaction]; - if (attachments.count < 1) { - return NO; - } - for (TSAttachment *attachment in attachments) { - if (!attachment.isVisualMedia) { - return NO; - } - } - return YES; -} - - (NSString *)debugDescription { if ([self hasAttachments] && self.body.length > 0) {