From cf091758a5001f3af1d0457553677e78e0128ac1 Mon Sep 17 00:00:00 2001 From: sdkjfhsdkjhfsdlkjhfsdf Date: Tue, 19 Dec 2017 20:23:24 -0600 Subject: [PATCH] Fix oversized text messages // FREEBIE --- .../ConversationView/Cells/OWSMessageCell.m | 15 ++++--- .../ConversationView/ConversationViewItem.m | 1 + .../MessageDetailViewController.swift | 45 ++++++++++++++----- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 47a21a25d..7bd7c7722 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -522,6 +522,9 @@ NS_ASSUME_NONNULL_BEGIN // cell is no longer visible. - (void)ensureViewMediaState { + CGSize mediaSize = [self mediaBubbleSizeForContentWidth:self.contentWidth]; + [self.contentConstraints addObjectsFromArray:[self.mediaMaskingView autoSetDimensionsToSize:mediaSize]]; + if (!self.isCellVisible) { // Eagerly unload. self.stillImageView.image = nil; @@ -781,6 +784,9 @@ NS_ASSUME_NONNULL_BEGIN self.textView.shouldIgnoreEvents = NO; } + OWSAssert(self.contentWidth); + CGSize textBubbleSize = [self textBubbleSizeForContentWidth:self.contentWidth]; + if (self.displayableText.isTextTruncated) { self.tapForMoreLabel = [UILabel new]; self.tapForMoreLabel.text = NSLocalizedString(@"CONVERSATION_VIEW_OVERSIZE_TEXT_TAP_FOR_MORE", @@ -791,6 +797,8 @@ NS_ASSUME_NONNULL_BEGIN [self.textBubbleImageView addSubview:self.tapForMoreLabel]; [self.contentConstraints addObjectsFromArray:@[ + [self.textBubbleImageView autoSetDimension:ALDimensionWidth toSize:textBubbleSize.width], + [self.textBubbleImageView autoSetDimension:ALDimensionHeight toSize:textBubbleSize.height], [self.textView autoPinLeadingToSuperviewWithMargin:self.textLeadingMargin], [self.textView autoPinTrailingToSuperviewWithMargin:self.textTrailingMargin], [self.textView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textVMargin], @@ -802,9 +810,6 @@ NS_ASSUME_NONNULL_BEGIN [self.tapForMoreLabel autoSetDimension:ALDimensionHeight toSize:self.tapForMoreHeight], ]]; } else { - OWSAssert(self.contentWidth); - CGSize textBubbleSize = [self textBubbleSizeForContentWidth:self.contentWidth]; - [self.contentConstraints addObjectsFromArray:@[ [self.textBubbleImageView autoSetDimension:ALDimensionWidth toSize:textBubbleSize.width], [self.textBubbleImageView autoSetDimension:ALDimensionHeight toSize:textBubbleSize.height], @@ -934,12 +939,10 @@ NS_ASSUME_NONNULL_BEGIN view.userInteractionEnabled = NO; [self.mediaMaskingView addSubview:view]; - CGSize mediaSize = [self mediaBubbleSizeForContentWidth:self.contentWidth]; - [self.contentConstraints addObject:[self.mediaMaskingView autoPinEdgeToSuperviewEdge:(self.isIncoming ? ALEdgeLeading : ALEdgeTrailing)]]; - [self.contentConstraints addObjectsFromArray:[self.mediaMaskingView autoSetDimensionsToSize:mediaSize]]; + [self.contentConstraints addObjectsFromArray:[view autoPinEdgesToSuperviewMargins]]; [self cropMediaViewToBubbbleShape:view]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 00b129185..ae6886cfa 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -377,6 +377,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) self.messageCellType = OWSMessageCellType_OversizeTextMessage; self.displayableText = [self displayableTextForAttachmentStream:self.attachmentStream interactionId:message.uniqueId]; + self.hasText = YES; } else if ([self.attachmentStream isAnimated] || [self.attachmentStream isImage] || [self.attachmentStream isVideo]) { if ([self.attachmentStream isAnimated]) { diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 33b81955f..c62f0baf8 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -148,9 +148,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { contentView.autoPinEdge(toSuperviewEdge: .bottom) scrollView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) - let hasAttachment = message.attachmentIds.count > 0 - - if hasAttachment { + if hasMediaAttachment { let footer = UIToolbar() footer.barTintColor = UIColor.ows_materialBlue() view.addSubview(footer) @@ -325,7 +323,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { private func contentRows() -> [UIView] { var rows = [UIView]() - if message.attachmentIds.count > 0 { + if hasMediaAttachment { rows += addAttachmentRows() } @@ -401,19 +399,27 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { return rows } - private func addAttachmentRows() -> [UIView] { - var rows = [UIView]() - + private func fetchAttachment(transaction: YapDatabaseReadTransaction) -> TSAttachment? { guard let attachmentId = message.attachmentIds[0] as? String else { owsFail("Invalid attachment") - return rows + return nil } - guard let attachment = TSAttachment.fetch(uniqueId: attachmentId) else { + guard let attachment = TSAttachment.fetch(uniqueId: attachmentId, transaction: transaction) else { owsFail("Missing attachment") + return nil + } + + return attachment + } + + private func addAttachmentRows() -> [UIView] { + var rows = [UIView]() + + guard let attachment = self.attachment else { + owsFail("no attachment to add.") return rows } - self.attachment = attachment guard let attachmentStream = attachment as? TSAttachmentStream else { rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_NOT_YET_DOWNLOADED", @@ -445,7 +451,25 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { return rows } + var hasMediaAttachment: Bool { + guard let attachment = self.attachment else { + return false + } + + guard attachment.contentType != OWSMimeTypeOversizeTextMessage else { + // to the user, oversized text attachments should behave + // just like regular text messages. + return false + } + + return true + } + private func addAttachmentMetadataRows() -> [UIView] { + guard hasMediaAttachment else { + return [] + } + var rows = [UIView]() if let attachment = self.attachment { @@ -575,6 +599,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { return } self.message = newMessage + self.attachment = self.fetchAttachment(transaction: transaction) } }