2017-10-10 22:13:54 +02:00
|
|
|
//
|
2018-02-23 21:44:46 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-10-10 22:13:54 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "ConversationViewLayout.h"
|
2018-02-23 21:44:46 +01:00
|
|
|
#import "OWSAudioPlayer.h"
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, OWSMessageCellType) {
|
2017-12-18 18:11:02 +01:00
|
|
|
OWSMessageCellType_Unknown,
|
2017-10-10 22:13:54 +02:00
|
|
|
OWSMessageCellType_TextMessage,
|
|
|
|
OWSMessageCellType_OversizeTextMessage,
|
|
|
|
OWSMessageCellType_Audio,
|
|
|
|
OWSMessageCellType_GenericAttachment,
|
|
|
|
OWSMessageCellType_DownloadingAttachment,
|
2018-05-02 17:01:23 +02:00
|
|
|
OWSMessageCellType_ContactShare,
|
2018-11-07 17:52:34 +01:00
|
|
|
OWSMessageCellType_MediaAlbum,
|
2017-10-10 22:13:54 +02:00
|
|
|
};
|
|
|
|
|
2017-10-12 19:48:09 +02:00
|
|
|
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
|
|
|
|
2017-10-25 20:53:54 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
2018-05-05 02:46:00 +02:00
|
|
|
@class ContactShareViewModel;
|
2017-10-10 22:13:54 +02:00
|
|
|
@class ConversationViewCell;
|
2017-10-26 18:09:36 +02:00
|
|
|
@class DisplayableText;
|
2017-10-10 22:13:54 +02:00
|
|
|
@class OWSAudioMessageView;
|
2018-04-06 22:53:16 +02:00
|
|
|
@class OWSQuotedReplyModel;
|
2018-07-11 20:12:58 +02:00
|
|
|
@class OWSUnreadIndicator;
|
2018-11-05 17:07:00 +01:00
|
|
|
@class TSAttachment;
|
2017-10-10 22:13:54 +02:00
|
|
|
@class TSAttachmentPointer;
|
|
|
|
@class TSAttachmentStream;
|
|
|
|
@class TSInteraction;
|
2018-09-25 22:05:53 +02:00
|
|
|
@class TSThread;
|
2017-11-16 17:22:16 +01:00
|
|
|
@class YapDatabaseReadTransaction;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2018-11-07 17:52:34 +01:00
|
|
|
@interface ConversationMediaAlbumItem : NSObject
|
2018-11-05 17:07:00 +01:00
|
|
|
|
|
|
|
@property (nonatomic, readonly) TSAttachment *attachment;
|
|
|
|
|
|
|
|
// This property will only be set if the attachment is downloaded.
|
|
|
|
@property (nonatomic, readonly, nullable) TSAttachmentStream *attachmentStream;
|
|
|
|
|
|
|
|
// This property will be non-zero if the attachment is valid.
|
|
|
|
@property (nonatomic, readonly) CGSize mediaSize;
|
|
|
|
|
2018-11-06 23:30:09 +01:00
|
|
|
@property (nonatomic, readonly, nullable) NSString *caption;
|
|
|
|
|
2018-11-05 17:07:00 +01:00
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2017-10-11 15:44:10 +02:00
|
|
|
// This is a ViewModel for cells in the conversation view.
|
|
|
|
//
|
|
|
|
// The lifetime of this class is the lifetime of that cell
|
|
|
|
// in the load window of the conversation view.
|
|
|
|
//
|
|
|
|
// Critically, this class implements ConversationViewLayoutItem
|
|
|
|
// and does caching of the cell's size.
|
2018-09-28 00:49:01 +02:00
|
|
|
@protocol ConversationViewItem <NSObject, ConversationViewLayoutItem, OWSAudioPlayerDelegate>
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
@property (nonatomic, readonly) TSInteraction *interaction;
|
2018-09-25 22:05:53 +02:00
|
|
|
|
2018-04-06 22:53:16 +02:00
|
|
|
@property (nonatomic, readonly, nullable) OWSQuotedReplyModel *quotedReply;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2017-10-12 05:03:28 +02:00
|
|
|
@property (nonatomic, readonly) BOOL isGroupThread;
|
2018-04-03 16:32:15 +02:00
|
|
|
|
2018-03-29 17:25:19 +02:00
|
|
|
@property (nonatomic, readonly) BOOL hasBodyText;
|
2018-04-03 16:32:15 +02:00
|
|
|
|
|
|
|
@property (nonatomic, readonly) BOOL isQuotedReply;
|
|
|
|
@property (nonatomic, readonly) BOOL hasQuotedAttachment;
|
|
|
|
@property (nonatomic, readonly) BOOL hasQuotedText;
|
2018-07-11 20:12:58 +02:00
|
|
|
@property (nonatomic, readonly) BOOL hasCellHeader;
|
2018-04-03 16:32:15 +02:00
|
|
|
|
2018-07-11 21:43:25 +02:00
|
|
|
@property (nonatomic, readonly) BOOL isExpiringMessage;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
@property (nonatomic) BOOL shouldShowDate;
|
2018-06-26 22:04:09 +02:00
|
|
|
@property (nonatomic) BOOL shouldShowSenderAvatar;
|
2018-07-02 15:42:48 +02:00
|
|
|
@property (nonatomic, nullable) NSAttributedString *senderName;
|
2018-06-26 22:04:09 +02:00
|
|
|
@property (nonatomic) BOOL shouldHideFooter;
|
2018-07-06 21:08:56 +02:00
|
|
|
@property (nonatomic) BOOL isFirstInCluster;
|
|
|
|
@property (nonatomic) BOOL isLastInCluster;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2018-07-11 20:12:58 +02:00
|
|
|
@property (nonatomic, nullable) OWSUnreadIndicator *unreadIndicator;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
- (ConversationViewCell *)dequeueCellForCollectionView:(UICollectionView *)collectionView
|
|
|
|
indexPath:(NSIndexPath *)indexPath;
|
|
|
|
|
2017-11-16 17:22:16 +01:00
|
|
|
- (void)replaceInteraction:(TSInteraction *)interaction transaction:(YapDatabaseReadTransaction *)transaction;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
- (void)clearCachedLayoutState;
|
|
|
|
|
2018-12-10 17:59:00 +01:00
|
|
|
@property (nonatomic, readonly) BOOL hasCachedLayoutState;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
#pragma mark - Audio Playback
|
|
|
|
|
|
|
|
@property (nonatomic, weak) OWSAudioMessageView *lastAudioMessageView;
|
|
|
|
|
2017-11-20 20:50:43 +01:00
|
|
|
@property (nonatomic, readonly) CGFloat audioDurationSeconds;
|
2018-09-28 00:49:01 +02:00
|
|
|
@property (nonatomic, readonly) CGFloat audioProgressSeconds;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
#pragma mark - View State Caching
|
|
|
|
|
|
|
|
// These methods only apply to text & attachment messages.
|
2018-09-28 00:49:01 +02:00
|
|
|
@property (nonatomic, readonly) OWSMessageCellType messageCellType;
|
|
|
|
@property (nonatomic, readonly, nullable) DisplayableText *displayableBodyText;
|
|
|
|
@property (nonatomic, readonly, nullable) TSAttachmentStream *attachmentStream;
|
|
|
|
@property (nonatomic, readonly, nullable) TSAttachmentPointer *attachmentPointer;
|
2018-11-07 17:52:34 +01:00
|
|
|
@property (nonatomic, readonly, nullable) NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2018-09-28 00:49:01 +02:00
|
|
|
@property (nonatomic, readonly, nullable) DisplayableText *displayableQuotedText;
|
|
|
|
@property (nonatomic, readonly, nullable) NSString *quotedAttachmentMimetype;
|
|
|
|
@property (nonatomic, readonly, nullable) NSString *quotedRecipientId;
|
2018-04-03 16:32:15 +02:00
|
|
|
|
2017-10-18 21:11:19 +02:00
|
|
|
// We don't want to try to load the media for this item (if any)
|
|
|
|
// if a load has previously failed.
|
2017-10-16 16:39:52 +02:00
|
|
|
@property (nonatomic) BOOL didCellMediaFailToLoad;
|
|
|
|
|
2018-05-05 02:46:00 +02:00
|
|
|
@property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare;
|
2018-04-30 20:22:04 +02:00
|
|
|
|
2018-09-26 15:19:12 +02:00
|
|
|
@property (nonatomic, readonly, nullable) NSString *systemMessageText;
|
|
|
|
|
|
|
|
// NOTE: This property is only set for incoming messages.
|
|
|
|
@property (nonatomic, readonly, nullable) NSString *authorConversationColorName;
|
2018-08-09 16:47:43 +02:00
|
|
|
|
2018-07-12 05:47:37 +02:00
|
|
|
#pragma mark - MessageActions
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2018-07-12 05:29:35 +02:00
|
|
|
@property (nonatomic, readonly) BOOL hasBodyTextActionContent;
|
2018-07-12 06:11:36 +02:00
|
|
|
@property (nonatomic, readonly) BOOL hasMediaActionContent;
|
2018-07-12 05:29:35 +02:00
|
|
|
|
2018-07-12 06:35:54 +02:00
|
|
|
- (void)copyMediaAction;
|
2017-12-19 19:35:39 +01:00
|
|
|
- (void)copyTextAction;
|
|
|
|
- (void)shareMediaAction;
|
|
|
|
- (void)saveMediaAction;
|
2018-07-12 05:55:04 +02:00
|
|
|
- (void)deleteAction;
|
2018-07-12 05:47:37 +02:00
|
|
|
|
2018-11-06 16:08:14 +01:00
|
|
|
- (BOOL)canCopyMedia;
|
2018-08-07 23:38:59 +02:00
|
|
|
- (BOOL)canSaveMedia;
|
|
|
|
|
2018-10-31 15:05:24 +01:00
|
|
|
// For view items that correspond to interactions, this is the interaction's unique id.
|
|
|
|
// For other view views (like the typing indicator), this is a unique, stable string.
|
|
|
|
- (NSString *)itemId;
|
|
|
|
|
2018-11-07 18:39:40 +01:00
|
|
|
- (nullable TSAttachmentStream *)firstValidAlbumAttachment;
|
2018-11-06 16:02:13 +01:00
|
|
|
|
2018-11-08 19:20:14 +01:00
|
|
|
- (BOOL)mediaAlbumHasFailedAttachment;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
@end
|
|
|
|
|
2018-10-31 15:05:24 +01:00
|
|
|
#pragma mark -
|
|
|
|
|
2018-09-28 00:49:01 +02:00
|
|
|
@interface ConversationInteractionViewItem
|
|
|
|
: NSObject <ConversationViewItem, ConversationViewLayoutItem, OWSAudioPlayerDelegate>
|
|
|
|
|
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
|
|
|
- (instancetype)initWithInteraction:(TSInteraction *)interaction
|
|
|
|
isGroupThread:(BOOL)isGroupThread
|
|
|
|
transaction:(YapDatabaseReadTransaction *)transaction
|
|
|
|
conversationStyle:(ConversationStyle *)conversationStyle;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
NS_ASSUME_NONNULL_END
|