diff --git a/Signal/src/ViewControllers/ColorPickerViewController.swift b/Signal/src/ViewControllers/ColorPickerViewController.swift index b0513e804..c72f2a14c 100644 --- a/Signal/src/ViewControllers/ColorPickerViewController.swift +++ b/Signal/src/ViewControllers/ColorPickerViewController.swift @@ -341,6 +341,8 @@ private class MockConversationViewItem: NSObject, ConversationViewItem { var hasMediaActionContent: Bool = false var mediaAlbumItems: [ConversationMediaAlbumItem]? var hasCachedLayoutState: Bool = false + var linkPreview: OWSLinkPreview? + var linkPreviewAttachment: TSAttachment? override init() { super.init() diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h index 487d5a7f5..4a980afb9 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h @@ -26,6 +26,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); @class ConversationViewCell; @class DisplayableText; @class OWSAudioMessageView; +@class OWSLinkPreview; @class OWSQuotedReplyModel; @class OWSUnreadIndicator; @class TSAttachment; @@ -121,6 +122,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); @property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare; +@property (nonatomic, readonly, nullable) OWSLinkPreview *linkPreview; +@property (nonatomic, readonly, nullable) TSAttachment *linkPreviewAttachment; + @property (nonatomic, readonly, nullable) NSString *systemMessageText; // NOTE: This property is only set for incoming messages. diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 92687819a..539788ee5 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -97,6 +97,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) @property (nonatomic, nullable) TSAttachmentStream *attachmentStream; @property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer; @property (nonatomic, nullable) ContactShareViewModel *contactShare; +@property (nonatomic, nullable) OWSLinkPreview *linkPreview; +@property (nonatomic, nullable) TSAttachment *linkPreviewAttachment; @property (nonatomic, nullable) NSArray *mediaAlbumItems; @property (nonatomic, nullable) NSString *systemMessageText; @property (nonatomic, nullable) TSThread *incomingMessageAuthorThread; @@ -158,10 +160,14 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) self.displayableBodyText = nil; self.attachmentStream = nil; self.attachmentPointer = nil; + self.mediaAlbumItems = nil; self.displayableQuotedText = nil; self.quotedReply = nil; + self.contactShare = nil; self.systemMessageText = nil; - self.mediaAlbumItems = nil; + self.authorConversationColorName = nil; + self.linkPreview = nil; + self.linkPreviewAttachment = nil; [self updateAuthorConversationColorNameWithTransaction:transaction]; @@ -660,6 +666,17 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) OWSAssertDebug(self.displayableBodyText); } + if (self.hasBodyText && attachment == nil && message.linkPreview) { + self.linkPreview = message.linkPreview; + if (message.linkPreview.imageAttachmentId.length > 0) { + self.linkPreviewAttachment = + [TSAttachment fetchObjectWithUniqueID:message.linkPreview.imageAttachmentId transaction:transaction]; + if (!self.linkPreviewAttachment) { + OWSFailDebug(@"Could not load link preview image attachment."); + } + } + } + if (self.messageCellType == OWSMessageCellType_Unknown) { // Messages of unknown type (including messages with missing attachments) // are rendered like empty text messages, but without any interactivity. diff --git a/Signal/src/views/LinkPreviewView.swift b/Signal/src/views/LinkPreviewView.swift index 85dfb62cb..6afa8a4ff 100644 --- a/Signal/src/views/LinkPreviewView.swift +++ b/Signal/src/views/LinkPreviewView.swift @@ -369,11 +369,11 @@ public class LinkPreviewView: UIStackView { self.alignment = .center self.autoSetDimension(.height, toSize: approvalHeight) - let label = UILabel() - label.text = NSLocalizedString("LINK_PREVIEW_LOADING", comment: "Indicates that the link preview is being loaded.") - label.textColor = Theme.secondaryColor - label.font = UIFont.ows_dynamicTypeBody - addArrangedSubview(label) + let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) + activityIndicator.startAnimating() + addArrangedSubview(activityIndicator) + let activityIndicatorSize: CGFloat = 25 + activityIndicator.autoSetDimensions(to: CGSize(width: activityIndicatorSize, height: activityIndicatorSize)) } // MARK: Events