2017-10-10 22:13:54 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ConversationViewLayout.h"
|
|
|
|
#import "OWSAudioAttachmentPlayer.h"
|
|
|
|
|
|
|
|
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_StillImage,
|
|
|
|
OWSMessageCellType_AnimatedImage,
|
|
|
|
OWSMessageCellType_Audio,
|
|
|
|
OWSMessageCellType_Video,
|
|
|
|
OWSMessageCellType_GenericAttachment,
|
|
|
|
OWSMessageCellType_DownloadingAttachment,
|
|
|
|
};
|
|
|
|
|
2017-10-12 19:48:09 +02:00
|
|
|
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
|
|
|
|
2017-10-25 20:53:54 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
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;
|
|
|
|
@class TSAttachmentPointer;
|
|
|
|
@class TSAttachmentStream;
|
|
|
|
@class TSInteraction;
|
2017-11-16 17:22:16 +01:00
|
|
|
@class YapDatabaseReadTransaction;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
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.
|
2017-10-10 22:13:54 +02:00
|
|
|
@interface ConversationViewItem : NSObject <ConversationViewLayoutItem, OWSAudioAttachmentPlayerDelegate>
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) TSInteraction *interaction;
|
|
|
|
|
2017-10-12 05:03:28 +02:00
|
|
|
@property (nonatomic, readonly) BOOL isGroupThread;
|
2017-12-18 18:11:02 +01:00
|
|
|
@property (nonatomic, readonly) BOOL hasText;
|
2017-10-10 22:13:54 +02:00
|
|
|
@property (nonatomic) BOOL shouldShowDate;
|
2017-10-12 06:16:23 +02:00
|
|
|
@property (nonatomic) BOOL shouldHideRecipientStatus;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
2017-10-11 21:23:53 +02:00
|
|
|
@property (nonatomic) NSInteger row;
|
2017-10-17 06:05:29 +02:00
|
|
|
// During updates, we sometimes need the previous row index
|
|
|
|
// (before this update) of this item.
|
2017-10-19 15:53:35 +02:00
|
|
|
//
|
|
|
|
// If NSNotFound, this view item was just created in the
|
|
|
|
// previous update.
|
2017-10-17 06:05:29 +02:00
|
|
|
@property (nonatomic) NSInteger previousRow;
|
2017-10-11 21:23:53 +02:00
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
2017-11-16 17:22:16 +01:00
|
|
|
- (instancetype)initWithInteraction:(TSInteraction *)interaction
|
|
|
|
isGroupThread:(BOOL)isGroupThread
|
|
|
|
transaction:(YapDatabaseReadTransaction *)transaction;
|
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;
|
|
|
|
|
|
|
|
#pragma mark - Audio Playback
|
|
|
|
|
|
|
|
@property (nonatomic, weak) OWSAudioMessageView *lastAudioMessageView;
|
|
|
|
|
2017-11-20 20:50:43 +01:00
|
|
|
@property (nonatomic, readonly) CGFloat audioDurationSeconds;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
- (CGFloat)audioProgressSeconds;
|
|
|
|
|
|
|
|
#pragma mark - View State Caching
|
|
|
|
|
|
|
|
// These methods only apply to text & attachment messages.
|
|
|
|
- (OWSMessageCellType)messageCellType;
|
2017-10-25 20:53:54 +02:00
|
|
|
- (nullable DisplayableText *)displayableText;
|
2017-10-10 22:13:54 +02:00
|
|
|
- (nullable TSAttachmentStream *)attachmentStream;
|
|
|
|
- (nullable TSAttachmentPointer *)attachmentPointer;
|
2017-12-18 18:11:02 +01:00
|
|
|
- (CGSize)mediaSize;
|
2017-10-10 22:13:54 +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;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
#pragma mark - UIMenuController
|
|
|
|
|
2017-12-19 19:35:39 +01:00
|
|
|
- (NSArray<UIMenuItem *> *)textMenuControllerItems;
|
|
|
|
- (NSArray<UIMenuItem *> *)mediaMenuControllerItems;
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
- (BOOL)canPerformAction:(SEL)action;
|
2017-12-19 19:35:39 +01:00
|
|
|
- (void)copyMediaAction;
|
|
|
|
- (void)copyTextAction;
|
|
|
|
- (void)shareMediaAction;
|
|
|
|
- (void)shareTextAction;
|
|
|
|
- (void)saveMediaAction;
|
2017-10-10 22:13:54 +02:00
|
|
|
- (void)deleteAction;
|
|
|
|
- (SEL)metadataActionSelector;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|