Add link previews to converastion view items.
This commit is contained in:
parent
f62e48f4bb
commit
c7053aa36d
|
@ -341,6 +341,8 @@ private class MockConversationViewItem: NSObject, ConversationViewItem {
|
||||||
var hasMediaActionContent: Bool = false
|
var hasMediaActionContent: Bool = false
|
||||||
var mediaAlbumItems: [ConversationMediaAlbumItem]?
|
var mediaAlbumItems: [ConversationMediaAlbumItem]?
|
||||||
var hasCachedLayoutState: Bool = false
|
var hasCachedLayoutState: Bool = false
|
||||||
|
var linkPreview: OWSLinkPreview?
|
||||||
|
var linkPreviewAttachment: TSAttachment?
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
|
@ -26,6 +26,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
||||||
@class ConversationViewCell;
|
@class ConversationViewCell;
|
||||||
@class DisplayableText;
|
@class DisplayableText;
|
||||||
@class OWSAudioMessageView;
|
@class OWSAudioMessageView;
|
||||||
|
@class OWSLinkPreview;
|
||||||
@class OWSQuotedReplyModel;
|
@class OWSQuotedReplyModel;
|
||||||
@class OWSUnreadIndicator;
|
@class OWSUnreadIndicator;
|
||||||
@class TSAttachment;
|
@class TSAttachment;
|
||||||
|
@ -121,6 +122,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
||||||
|
|
||||||
@property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare;
|
@property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare;
|
||||||
|
|
||||||
|
@property (nonatomic, readonly, nullable) OWSLinkPreview *linkPreview;
|
||||||
|
@property (nonatomic, readonly, nullable) TSAttachment *linkPreviewAttachment;
|
||||||
|
|
||||||
@property (nonatomic, readonly, nullable) NSString *systemMessageText;
|
@property (nonatomic, readonly, nullable) NSString *systemMessageText;
|
||||||
|
|
||||||
// NOTE: This property is only set for incoming messages.
|
// NOTE: This property is only set for incoming messages.
|
||||||
|
|
|
@ -97,6 +97,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
||||||
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
|
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
|
||||||
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
|
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
|
||||||
@property (nonatomic, nullable) ContactShareViewModel *contactShare;
|
@property (nonatomic, nullable) ContactShareViewModel *contactShare;
|
||||||
|
@property (nonatomic, nullable) OWSLinkPreview *linkPreview;
|
||||||
|
@property (nonatomic, nullable) TSAttachment *linkPreviewAttachment;
|
||||||
@property (nonatomic, nullable) NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems;
|
@property (nonatomic, nullable) NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems;
|
||||||
@property (nonatomic, nullable) NSString *systemMessageText;
|
@property (nonatomic, nullable) NSString *systemMessageText;
|
||||||
@property (nonatomic, nullable) TSThread *incomingMessageAuthorThread;
|
@property (nonatomic, nullable) TSThread *incomingMessageAuthorThread;
|
||||||
|
@ -158,10 +160,14 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
||||||
self.displayableBodyText = nil;
|
self.displayableBodyText = nil;
|
||||||
self.attachmentStream = nil;
|
self.attachmentStream = nil;
|
||||||
self.attachmentPointer = nil;
|
self.attachmentPointer = nil;
|
||||||
|
self.mediaAlbumItems = nil;
|
||||||
self.displayableQuotedText = nil;
|
self.displayableQuotedText = nil;
|
||||||
self.quotedReply = nil;
|
self.quotedReply = nil;
|
||||||
|
self.contactShare = nil;
|
||||||
self.systemMessageText = nil;
|
self.systemMessageText = nil;
|
||||||
self.mediaAlbumItems = nil;
|
self.authorConversationColorName = nil;
|
||||||
|
self.linkPreview = nil;
|
||||||
|
self.linkPreviewAttachment = nil;
|
||||||
|
|
||||||
[self updateAuthorConversationColorNameWithTransaction:transaction];
|
[self updateAuthorConversationColorNameWithTransaction:transaction];
|
||||||
|
|
||||||
|
@ -660,6 +666,17 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
||||||
OWSAssertDebug(self.displayableBodyText);
|
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) {
|
if (self.messageCellType == OWSMessageCellType_Unknown) {
|
||||||
// Messages of unknown type (including messages with missing attachments)
|
// Messages of unknown type (including messages with missing attachments)
|
||||||
// are rendered like empty text messages, but without any interactivity.
|
// are rendered like empty text messages, but without any interactivity.
|
||||||
|
|
|
@ -369,11 +369,11 @@ public class LinkPreviewView: UIStackView {
|
||||||
self.alignment = .center
|
self.alignment = .center
|
||||||
self.autoSetDimension(.height, toSize: approvalHeight)
|
self.autoSetDimension(.height, toSize: approvalHeight)
|
||||||
|
|
||||||
let label = UILabel()
|
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||||
label.text = NSLocalizedString("LINK_PREVIEW_LOADING", comment: "Indicates that the link preview is being loaded.")
|
activityIndicator.startAnimating()
|
||||||
label.textColor = Theme.secondaryColor
|
addArrangedSubview(activityIndicator)
|
||||||
label.font = UIFont.ows_dynamicTypeBody
|
let activityIndicatorSize: CGFloat = 25
|
||||||
addArrangedSubview(label)
|
activityIndicator.autoSetDimensions(to: CGSize(width: activityIndicatorSize, height: activityIndicatorSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Events
|
// MARK: Events
|
||||||
|
|
Loading…
Reference in New Issue