render media+longText message

This commit is contained in:
Michael Kirk 2019-02-22 17:37:03 -07:00
parent b7989e9384
commit 7e5256856c
9 changed files with 23 additions and 76 deletions

View File

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

View File

@ -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,

View File

@ -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<TSAttachment *> *mediaAttachments = [message mediaAttachmentsWithTransaction:transaction];
if ([message isMediaAlbumWithTransaction:transaction]) {
OWSAssertDebug(mediaAttachments.count > 0);
NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems = [self mediaAlbumItemsForAttachments:mediaAttachments];
NSArray<ConversationMediaAlbumItem *> *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<ConversationMediaAlbumItem *> *)mediaAlbumItemsForAttachments:(NSArray<TSAttachment *> *)attachments
{
OWSAssertIsOnMainThread();
OWSAssertDebug(attachments.count > 0);
NSMutableArray<ConversationMediaAlbumItem *> *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:

View File

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

View File

@ -110,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *truncatedText;
NSArray<SignalAttachment *> *attachments = attachmentsParam;
if ([fullMessageText lengthOfBytesUsingEncoding:NSUTF8StringEncoding] < kOversizeTextMessageSizeThreshold) {
if ([fullMessageText lengthOfBytesUsingEncoding:NSUTF8StringEncoding] <= kOversizeTextMessageSizeThreshold) {
truncatedText = fullMessageText;
} else {
if (SSKFeatureFlags.sendingMediaWithOversizeText) {

View File

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

View File

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

View File

@ -55,8 +55,6 @@ NS_ASSUME_NONNULL_BEGIN
// quoted reply thumbnails, contact share avatars, link preview images, etc.
- (NSArray<NSString *> *)allAttachmentIds;
- (BOOL)isMediaAlbumWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (void)setQuotedMessageThumbnailAttachmentStream:(TSAttachmentStream *)attachmentStream;
- (nullable NSString *)oversizeTextWithTransaction:(YapDatabaseReadTransaction *)transaction;

View File

@ -249,20 +249,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
[self saveWithTransaction:transaction];
}
- (BOOL)isMediaAlbumWithTransaction:(YapDatabaseReadTransaction *)transaction
{
NSArray<TSAttachment *> *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) {