Merge branch 'mkirk/fix-message-details-media'

pull/1/head
Michael Kirk 7 years ago
commit 13fdfa2db3

@ -52,6 +52,7 @@
#import <SignalMessaging/ContactTableViewCell.h> #import <SignalMessaging/ContactTableViewCell.h>
#import <SignalMessaging/Environment.h> #import <SignalMessaging/Environment.h>
#import <SignalMessaging/NSString+OWS.h> #import <SignalMessaging/NSString+OWS.h>
#import <SignalMessaging/OWSAudioPlayer.h>
#import <SignalMessaging/OWSContactAvatarBuilder.h> #import <SignalMessaging/OWSContactAvatarBuilder.h>
#import <SignalMessaging/OWSContactsManager.h> #import <SignalMessaging/OWSContactsManager.h>
#import <SignalMessaging/OWSFormat.h> #import <SignalMessaging/OWSFormat.h>

@ -16,18 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
@protocol ConversationViewCellDelegate <NSObject> @protocol ConversationViewCellDelegate <NSObject>
- (void)didTapImageViewItem:(ConversationViewItem *)viewItem
attachmentStream:(TSAttachmentStream *)attachmentStream
imageView:(UIView *)imageView;
- (void)didTapVideoViewItem:(ConversationViewItem *)viewItem
attachmentStream:(TSAttachmentStream *)attachmentStream
imageView:(UIView *)imageView;
- (void)didTapAudioViewItem:(ConversationViewItem *)viewItem attachmentStream:(TSAttachmentStream *)attachmentStream;
- (void)didTapTruncatedTextMessage:(ConversationViewItem *)conversationItem;
- (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem
attachmentPointer:(TSAttachmentPointer *)attachmentPointer;
- (void)didTapFailedOutgoingMessage:(TSOutgoingMessage *)message;
- (void)didTapQuotedMessage:(ConversationViewItem *)viewItem quotedMessage:(TSQuotedMessage *)quotedMessage;
- (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer - (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer
viewItem:(ConversationViewItem *)conversationItem; viewItem:(ConversationViewItem *)conversationItem;

@ -5,6 +5,10 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class ConversationViewItem; @class ConversationViewItem;
@class TSAttachmentPointer;
@class TSAttachmentStream;
@class TSOutgoingMessage;
@class TSQuotedMessage;
typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) { typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
// Message text, etc. // Message text, etc.
@ -14,6 +18,29 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
OWSMessageGestureLocation_QuotedReply, OWSMessageGestureLocation_QuotedReply,
}; };
@protocol OWSMessageBubbleViewDelegate
- (void)didTapImageViewItem:(ConversationViewItem *)viewItem
attachmentStream:(TSAttachmentStream *)attachmentStream
imageView:(UIView *)imageView;
- (void)didTapVideoViewItem:(ConversationViewItem *)viewItem
attachmentStream:(TSAttachmentStream *)attachmentStream
imageView:(UIView *)imageView;
- (void)didTapAudioViewItem:(ConversationViewItem *)viewItem attachmentStream:(TSAttachmentStream *)attachmentStream;
- (void)didTapTruncatedTextMessage:(ConversationViewItem *)conversationItem;
- (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem
attachmentPointer:(TSAttachmentPointer *)attachmentPointer;
- (void)didTapFailedOutgoingMessage:(TSOutgoingMessage *)message;
- (void)didTapQuotedMessage:(ConversationViewItem *)viewItem quotedMessage:(TSQuotedMessage *)quotedMessage;
@end
@interface OWSMessageBubbleView : UIView @interface OWSMessageBubbleView : UIView
@property (nonatomic, nullable) ConversationViewItem *viewItem; @property (nonatomic, nullable) ConversationViewItem *viewItem;
@ -26,6 +53,8 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
@property (nonatomic) BOOL alwaysShowBubbleTail; @property (nonatomic) BOOL alwaysShowBubbleTail;
@property (nonatomic, weak) id<OWSMessageBubbleViewDelegate> delegate;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER; - (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;

@ -59,13 +59,17 @@ NS_ASSUME_NONNULL_BEGIN
_viewConstraints = [NSMutableArray new]; _viewConstraints = [NSMutableArray new];
self.layoutMargins = UIEdgeInsetsZero; self.layoutMargins = UIEdgeInsetsZero;
self.userInteractionEnabled = NO; self.userInteractionEnabled = YES;
self.bubbleView = [OWSBubbleView new]; self.bubbleView = [OWSBubbleView new];
self.bubbleView.layoutMargins = UIEdgeInsetsZero; self.bubbleView.layoutMargins = UIEdgeInsetsZero;
[self addSubview:self.bubbleView]; [self addSubview:self.bubbleView];
[self.bubbleView autoPinEdgesToSuperviewEdges]; [self.bubbleView autoPinEdgesToSuperviewEdges];
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self addGestureRecognizer:tap];
self.bodyTextView = [self newTextView]; self.bodyTextView = [self newTextView];
// Setting dataDetectorTypes is expensive. Do it just once. // Setting dataDetectorTypes is expensive. Do it just once.
self.bodyTextView.dataDetectorTypes self.bodyTextView.dataDetectorTypes
@ -150,6 +154,13 @@ NS_ASSUME_NONNULL_BEGIN
return self.viewItem.attachmentPointer; return self.viewItem.attachmentPointer;
} }
- (TSMessage *)message
{
OWSAssert([self.viewItem.interaction isKindOfClass:[TSMessage class]]);
return (TSMessage *)self.viewItem.interaction;
}
- (CGSize)mediaSize - (CGSize)mediaSize
{ {
// This should always be valid for the appropriate cell types. // This should always be valid for the appropriate cell types.
@ -1017,6 +1028,8 @@ NS_ASSUME_NONNULL_BEGIN
[NSLayoutConstraint deactivateConstraints:self.viewConstraints]; [NSLayoutConstraint deactivateConstraints:self.viewConstraints];
self.viewConstraints = [NSMutableArray new]; self.viewConstraints = [NSMutableArray new];
self.delegate = nil;
[self.bodyTextView removeFromSuperview]; [self.bodyTextView removeFromSuperview];
self.bodyTextView.text = nil; self.bodyTextView.text = nil;
self.bodyTextView.hidden = YES; self.bodyTextView.hidden = YES;
@ -1043,6 +1056,104 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gestures #pragma mark - Gestures
- (void)handleTapGesture:(UITapGestureRecognizer *)sender
{
OWSAssert(self.delegate);
if (sender.state != UIGestureRecognizerStateRecognized) {
DDLogVerbose(@"%@ Ignoring tap on message: %@", self.logTag, self.viewItem.interaction.debugDescription);
return;
}
if (self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) {
[self.delegate didTapFailedOutgoingMessage:outgoingMessage];
return;
} else if (outgoingMessage.messageState == TSOutgoingMessageStateAttemptingOut) {
// Ignore taps on outgoing messages being sent.
return;
}
}
CGPoint locationInMessageBubble = [sender locationInView:self];
switch ([self gestureLocationForLocation:locationInMessageBubble]) {
case OWSMessageGestureLocation_Default:
// Do nothing.
return;
case OWSMessageGestureLocation_OversizeText:
[self.delegate didTapTruncatedTextMessage:self.viewItem];
return;
case OWSMessageGestureLocation_Media:
[self handleMediaTapGesture];
break;
case OWSMessageGestureLocation_QuotedReply:
if (self.message.quotedMessage) {
[self.delegate didTapQuotedMessage:self.viewItem quotedMessage:self.message.quotedMessage];
} else {
OWSFail(@"%@ Missing quoted message.", self.logTag)
}
break;
}
}
- (void)handleMediaTapGesture
{
OWSAssert(self.delegate);
TSAttachmentStream *_Nullable attachmentStream = self.viewItem.attachmentStream;
switch (self.cellType) {
case OWSMessageCellType_Unknown:
case OWSMessageCellType_TextMessage:
case OWSMessageCellType_OversizeTextMessage:
break;
case OWSMessageCellType_StillImage:
OWSAssert(self.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.bodyMediaView];
break;
case OWSMessageCellType_AnimatedImage:
OWSAssert(self.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.bodyMediaView];
break;
case OWSMessageCellType_Audio:
OWSAssert(attachmentStream);
[self.delegate didTapAudioViewItem:self.viewItem attachmentStream:attachmentStream];
return;
case OWSMessageCellType_Video:
OWSAssert(self.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapVideoViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.bodyMediaView];
return;
case OWSMessageCellType_GenericAttachment:
OWSAssert(attachmentStream);
[AttachmentSharing showShareUIForAttachment:attachmentStream];
break;
case OWSMessageCellType_DownloadingAttachment: {
TSAttachmentPointer *_Nullable attachmentPointer = self.viewItem.attachmentPointer;
OWSAssert(attachmentPointer);
if (attachmentPointer.state == TSAttachmentPointerStateFailed) {
[self.delegate didTapFailedIncomingAttachment:self.viewItem attachmentPointer:attachmentPointer];
}
break;
}
}
}
- (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble - (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble
{ {
if (self.quotedMessageView) { if (self.quotedMessageView) {

@ -4,10 +4,14 @@
#import "ConversationViewCell.h" #import "ConversationViewCell.h"
@class OWSMessageBubbleView;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageCell : ConversationViewCell @interface OWSMessageCell : ConversationViewCell
@property (nonatomic, readonly) OWSMessageBubbleView *messageBubbleView;
+ (NSString *)cellReuseIdentifier; + (NSString *)cellReuseIdentifier;
@end @end

@ -83,10 +83,6 @@ NS_ASSUME_NONNULL_BEGIN
self.contentView.userInteractionEnabled = YES; self.contentView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[self.contentView addGestureRecognizer:tap];
UILongPressGestureRecognizer *longPress = UILongPressGestureRecognizer *longPress =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.contentView addGestureRecognizer:longPress]; [self.contentView addGestureRecognizer:longPress];
@ -483,104 +479,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Gesture recognizers #pragma mark - Gesture recognizers
- (void)handleTapGesture:(UITapGestureRecognizer *)sender
{
OWSAssert(self.delegate);
if (sender.state != UIGestureRecognizerStateRecognized) {
DDLogVerbose(@"%@ Ignoring tap on message: %@", self.logTag, self.viewItem.interaction.debugDescription);
return;
}
if (self.viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) {
[self.delegate didTapFailedOutgoingMessage:outgoingMessage];
return;
} else if (outgoingMessage.messageState == TSOutgoingMessageStateAttemptingOut) {
// Ignore taps on outgoing messages being sent.
return;
}
}
CGPoint locationInMessageBubble = [sender locationInView:self.messageBubbleView];
switch ([self.messageBubbleView gestureLocationForLocation:locationInMessageBubble]) {
case OWSMessageGestureLocation_Default:
// Do nothing.
return;
case OWSMessageGestureLocation_OversizeText:
[self.delegate didTapTruncatedTextMessage:self.viewItem];
return;
case OWSMessageGestureLocation_Media:
[self handleMediaTapGesture];
break;
case OWSMessageGestureLocation_QuotedReply:
if (self.message.quotedMessage) {
[self.delegate didTapQuotedMessage:self.viewItem quotedMessage:self.message.quotedMessage];
} else {
OWSFail(@"%@ Missing quoted message.", self.logTag)
}
break;
}
}
- (void)handleMediaTapGesture
{
OWSAssert(self.delegate);
TSAttachmentStream *_Nullable attachmentStream = self.viewItem.attachmentStream;
switch (self.cellType) {
case OWSMessageCellType_Unknown:
case OWSMessageCellType_TextMessage:
case OWSMessageCellType_OversizeTextMessage:
break;
case OWSMessageCellType_StillImage:
OWSAssert(self.messageBubbleView.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.messageBubbleView.bodyMediaView];
break;
case OWSMessageCellType_AnimatedImage:
OWSAssert(self.messageBubbleView.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.messageBubbleView.bodyMediaView];
break;
case OWSMessageCellType_Audio:
OWSAssert(attachmentStream);
[self.delegate didTapAudioViewItem:self.viewItem attachmentStream:attachmentStream];
return;
case OWSMessageCellType_Video:
OWSAssert(self.messageBubbleView.bodyMediaView);
OWSAssert(attachmentStream);
[self.delegate didTapVideoViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.messageBubbleView.bodyMediaView];
return;
case OWSMessageCellType_GenericAttachment:
OWSAssert(attachmentStream);
[AttachmentSharing showShareUIForAttachment:attachmentStream];
break;
case OWSMessageCellType_DownloadingAttachment: {
TSAttachmentPointer *_Nullable attachmentPointer = self.viewItem.attachmentPointer;
OWSAssert(attachmentPointer);
if (attachmentPointer.state == TSAttachmentPointerStateFailed) {
[self.delegate didTapFailedIncomingAttachment:self.viewItem attachmentPointer:attachmentPointer];
}
break;
}
}
}
- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)sender
{ {
OWSAssert(self.delegate); OWSAssert(self.delegate);

@ -128,6 +128,7 @@ typedef enum : NSUInteger {
ConversationViewLayoutDelegate, ConversationViewLayoutDelegate,
ConversationViewCellDelegate, ConversationViewCellDelegate,
ConversationInputTextViewDelegate, ConversationInputTextViewDelegate,
OWSMessageBubbleViewDelegate,
UICollectionViewDelegate, UICollectionViewDelegate,
UICollectionViewDataSource, UICollectionViewDataSource,
UIDocumentMenuDelegate, UIDocumentMenuDelegate,
@ -2020,7 +2021,7 @@ typedef enum : NSUInteger {
success:successHandler]; success:successHandler];
} }
#pragma mark - Message Events #pragma mark - OWSMessageBubbleViewDelegate
- (void)didTapImageViewItem:(ConversationViewItem *)viewItem - (void)didTapImageViewItem:(ConversationViewItem *)viewItem
attachmentStream:(TSAttachmentStream *)attachmentStream attachmentStream:(TSAttachmentStream *)attachmentStream
@ -4718,6 +4719,10 @@ typedef enum : NSUInteger {
} }
cell.viewItem = viewItem; cell.viewItem = viewItem;
cell.delegate = self; cell.delegate = self;
if ([cell isKindOfClass:[OWSMessageCell class]]) {
OWSMessageCell *messageCell = (OWSMessageCell *)cell;
messageCell.messageBubbleView.delegate = self;
}
cell.contentWidth = self.layout.contentWidth; cell.contentWidth = self.layout.contentWidth;
[cell loadForDisplay]; [cell loadForDisplay];

@ -560,9 +560,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION", [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"REPLY_ITEM_ACTION",
@"Short name for edit menu item to reply to a message.") @"Short name for edit menu item to reply to a message.")
action:self.replyActionSelector], action:self.replyActionSelector],
// FIXME: when deleting a caption, users will be surprised that it also deletes the attachment.
// We either need to implement a way to remove the caption separate from the attachment
// or make a design change which clarifies that the whole message is getting deleted.
[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION", [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_ITEM_DELETE_ACTION",
@"Short name for edit menu item to delete contents of media message.") @"Short name for edit menu item to delete contents of media message.")
action:self.deleteActionSelector] action:self.deleteActionSelector]

@ -12,7 +12,7 @@ enum MessageMetadataViewMode: UInt {
case focusOnMetadata case focusOnMetadata
} }
class MessageDetailViewController: OWSViewController, MediaDetailPresenter, MediaGalleryDataSourceDelegate { class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDelegate, OWSMessageBubbleViewDelegate {
// MARK: Properties // MARK: Properties
@ -318,30 +318,28 @@ class MessageDetailViewController: OWSViewController, MediaDetailPresenter, Medi
rows += addAttachmentRows() rows += addAttachmentRows()
} }
if true { let messageBubbleView = OWSMessageBubbleView(frame: CGRect.zero)
let messageBubbleView = OWSMessageBubbleView(frame: CGRect.zero) messageBubbleView.delegate = self
self.messageBubbleView = messageBubbleView self.messageBubbleView = messageBubbleView
messageBubbleView.viewItem = viewItem messageBubbleView.viewItem = viewItem
messageBubbleView.cellMediaCache = NSCache() messageBubbleView.cellMediaCache = NSCache()
messageBubbleView.contentWidth = contentWidth() messageBubbleView.contentWidth = contentWidth()
messageBubbleView.alwaysShowBubbleTail = true messageBubbleView.alwaysShowBubbleTail = true
messageBubbleView.configureViews() messageBubbleView.configureViews()
messageBubbleView.loadContent() messageBubbleView.loadContent()
messageBubbleView.isUserInteractionEnabled = true assert(messageBubbleView.isUserInteractionEnabled)
messageBubbleView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(messageBubbleTapped)))
let row = UIView() let row = UIView()
row.addSubview(messageBubbleView) row.addSubview(messageBubbleView)
messageBubbleView.autoPinHeightToSuperview() messageBubbleView.autoPinHeightToSuperview()
let isIncoming = self.message as? TSIncomingMessage != nil let isIncoming = self.message as? TSIncomingMessage != nil
messageBubbleView.autoPinEdge(toSuperviewEdge: isIncoming ? .leading : .trailing, withInset: bubbleViewHMargin) messageBubbleView.autoPinEdge(toSuperviewEdge: isIncoming ? .leading : .trailing, withInset: bubbleViewHMargin)
self.messageBubbleViewWidthLayoutConstraint = messageBubbleView.autoSetDimension(.width, toSize: 0) self.messageBubbleViewWidthLayoutConstraint = messageBubbleView.autoSetDimension(.width, toSize: 0)
self.messageBubbleViewHeightLayoutConstraint = messageBubbleView.autoSetDimension(.height, toSize: 0) self.messageBubbleViewHeightLayoutConstraint = messageBubbleView.autoSetDimension(.height, toSize: 0)
rows.append(row) rows.append(row)
}
if rows.count == 0 { if rows.count == 0 {
// Neither attachment nor body. // Neither attachment nor body.
@ -587,40 +585,76 @@ class MessageDetailViewController: OWSViewController, MediaDetailPresenter, Medi
messageBubbleViewHeightLayoutConstraint.constant = messageBubbleSize.height messageBubbleViewHeightLayoutConstraint.constant = messageBubbleSize.height
} }
// MARK: - Event Handlers // MARK: OWSMessageBubbleViewDelegate
func messageBubbleTapped(sender: UIGestureRecognizer) { func didTapImageViewItem(_ viewItem: ConversationViewItem, attachmentStream: TSAttachmentStream, imageView: UIView) {
guard let messageBubbleView = messageBubbleView else { let mediaGalleryViewController = MediaGalleryViewController(thread: self.thread, uiDatabaseConnection: self.uiDatabaseConnection)
mediaGalleryViewController.addDataSourceDelegate(self)
mediaGalleryViewController.presentDetailView(fromViewController: self, mediaMessage: self.message, replacingView: imageView)
}
func didTapVideoViewItem(_ viewItem: ConversationViewItem, attachmentStream: TSAttachmentStream, imageView: UIView) {
let mediaGalleryViewController = MediaGalleryViewController(thread: self.thread, uiDatabaseConnection: self.uiDatabaseConnection)
mediaGalleryViewController.addDataSourceDelegate(self)
mediaGalleryViewController.presentDetailView(fromViewController: self, mediaMessage: self.message, replacingView: imageView)
}
var audioAttachmentPlayer: OWSAudioPlayer?
func didTapAudioViewItem(_ viewItem: ConversationViewItem, attachmentStream: TSAttachmentStream) {
AssertIsOnMainThread()
guard let mediaURL = attachmentStream.mediaURL() else {
owsFail("\(logTag) in \(#function) mediaURL was unexpectedly nil for attachment: \(attachmentStream)")
return return
} }
guard sender.state == .recognized else {
guard FileManager.default.fileExists(atPath: mediaURL.path) else {
owsFail("\(logTag) in \(#function) audio file missing at path: \(mediaURL)")
return return
} }
if let outgoingMessage = viewItem.interaction as? TSOutgoingMessage {
switch outgoingMessage.messageState { if let audioAttachmentPlayer = self.audioAttachmentPlayer {
case .attemptingOut, // Is this player associated with this media adapter?
.unsent: if (audioAttachmentPlayer.owner as? ConversationViewItem == viewItem) {
// Ignore taps on "unsent" and "sending" messages. // Tap to pause & unpause.
audioAttachmentPlayer.togglePlayState()
return return
default:
break
} }
audioAttachmentPlayer.stop()
self.audioAttachmentPlayer = nil
} }
let locationInMessageBubble = sender.location(in: messageBubbleView) let audioAttachmentPlayer = OWSAudioPlayer(mediaUrl: mediaURL, delegate: viewItem)
switch messageBubbleView.gestureLocation(forLocation: locationInMessageBubble) { self.audioAttachmentPlayer = audioAttachmentPlayer
case .default:
break // Associate the player with this media adapter.
case .oversizeText: audioAttachmentPlayer.owner = viewItem
let viewController = LongTextViewController(viewItem: viewItem) audioAttachmentPlayer.playWithPlaybackAudioCategory()
self.navigationController?.pushViewController(viewController, animated: true) }
break
case .media: func didTapTruncatedTextMessage(_ conversationItem: ConversationViewItem) {
// TODO: We could show MediaGalleryViewController? guard let navigationController = self.navigationController else {
break owsFail("\(logTag) in \(#function) navigationController was unexpectedly nil")
case .quotedReply: return
break
} }
let viewController = LongTextViewController(viewItem: viewItem)
navigationController.pushViewController(viewController, animated: true)
}
func didTapFailedIncomingAttachment(_ viewItem: ConversationViewItem, attachmentPointer: TSAttachmentPointer) {
// no - op
}
func didTapFailedOutgoingMessage(_ message: TSOutgoingMessage) {
// no - op
}
func didTapQuotedMessage(_ viewItem: ConversationViewItem, quotedMessage: TSQuotedMessage) {
// no - op
} }
// MediaGalleryDataSourceDelegate // MediaGalleryDataSourceDelegate
@ -642,17 +676,4 @@ class MessageDetailViewController: OWSViewController, MediaDetailPresenter, Medi
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
} }
// MARK: MediaDetailPresenter
public func presentDetails(mediaMessageView: MediaMessageView, fromView: UIView) {
guard self.attachmentStream != nil else {
owsFail("attachment stream unexpectedly nil")
return
}
let mediaGalleryViewController = MediaGalleryViewController(thread: self.thread, uiDatabaseConnection: self.uiDatabaseConnection)
mediaGalleryViewController.addDataSourceDelegate(self)
mediaGalleryViewController.presentDetailView(fromViewController: self, mediaMessage: self.message, replacingView: fromView)
}
} }

@ -30,6 +30,7 @@ FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[];
#import <SignalMessaging/OWSLogger.h> #import <SignalMessaging/OWSLogger.h>
#import <SignalMessaging/OWSMath.h> #import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSProfileManager.h> #import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/OWSQuotedReplyModel.h>
#import <SignalMessaging/OWSSounds.h> #import <SignalMessaging/OWSSounds.h>
#import <SignalMessaging/OWSTableViewController.h> #import <SignalMessaging/OWSTableViewController.h>
#import <SignalMessaging/OWSUserProfile.h> #import <SignalMessaging/OWSUserProfile.h>

@ -14,11 +14,6 @@ public enum MediaMessageViewMode: UInt {
case attachmentApproval case attachmentApproval
} }
@objc
public protocol MediaDetailPresenter: class {
func presentDetails(mediaMessageView: MediaMessageView, fromView: UIView)
}
@objc @objc
public class MediaMessageView: UIView, OWSAudioPlayerDelegate { public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
@ -59,8 +54,6 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
@objc @objc
public var contentView: UIView? public var contentView: UIView?
private weak var mediaDetailPresenter: MediaDetailPresenter?
// MARK: Initializers // MARK: Initializers
@available(*, unavailable, message:"use other constructor instead.") @available(*, unavailable, message:"use other constructor instead.")
@ -68,16 +61,13 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
fatalError("\(#function) is unimplemented.") fatalError("\(#function) is unimplemented.")
} }
// Currently we only use one mode (AttachmentApproval), so we could simplify this class, but it's kind
// of nice that it's written in a flexible way in case we'd want to use it elsewhere again in the future.
@objc @objc
public convenience init(attachment: SignalAttachment, mode: MediaMessageViewMode) { public required init(attachment: SignalAttachment, mode: MediaMessageViewMode) {
self.init(attachment: attachment, mode: mode, mediaDetailPresenter: nil)
}
public required init(attachment: SignalAttachment, mode: MediaMessageViewMode, mediaDetailPresenter: MediaDetailPresenter?) {
assert(!attachment.hasError) assert(!attachment.hasError)
self.attachment = attachment self.attachment = attachment
self.mode = mode self.mode = mode
self.mediaDetailPresenter = mediaDetailPresenter
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
createViews() createViews()
@ -203,9 +193,6 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
let aspectRatio = image.size.width / image.size.height let aspectRatio = image.size.width / image.size.height
addSubviewWithScaleAspectFitLayout(view: animatedImageView, aspectRatio: aspectRatio) addSubviewWithScaleAspectFitLayout(view: animatedImageView, aspectRatio: aspectRatio)
contentView = animatedImageView contentView = animatedImageView
animatedImageView.isUserInteractionEnabled = true
animatedImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageTapped)))
} }
private func addSubviewWithScaleAspectFitLayout(view: UIView, aspectRatio: CGFloat) { private func addSubviewWithScaleAspectFitLayout(view: UIView, aspectRatio: CGFloat) {
@ -237,9 +224,6 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
let aspectRatio = image.size.width / image.size.height let aspectRatio = image.size.width / image.size.height
addSubviewWithScaleAspectFitLayout(view: imageView, aspectRatio: aspectRatio) addSubviewWithScaleAspectFitLayout(view: imageView, aspectRatio: aspectRatio)
contentView = imageView contentView = imageView
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageTapped)))
} }
private func createVideoPreview() { private func createVideoPreview() {
@ -268,9 +252,6 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
videoPlayButton.contentMode = .scaleAspectFit videoPlayButton.contentMode = .scaleAspectFit
self.addSubview(videoPlayButton) self.addSubview(videoPlayButton)
videoPlayButton.autoCenterInSuperview() videoPlayButton.autoCenterInSuperview()
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(videoTapped)))
} }
} }
@ -445,44 +426,4 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
audioPlayButton?.setImage(image, for: .normal) audioPlayButton?.setImage(image, for: .normal)
audioPlayButton?.imageView?.tintColor = controlTintColor audioPlayButton?.imageView?.tintColor = controlTintColor
} }
// MARK: - Full Screen Image
@objc
func imageTapped(sender: UIGestureRecognizer) {
// Approval view handles it's own zooming gesture
guard mode != .attachmentApproval else {
return
}
guard sender.state == .recognized else {
return
}
guard let fromView = sender.view else {
return
}
showMediaDetailViewController(fromView: fromView)
}
// MARK: - Video Playback
@objc
func videoTapped(sender: UIGestureRecognizer) {
// Approval view handles it's own play gesture
guard mode != .attachmentApproval else {
return
}
guard sender.state == .recognized else {
return
}
guard let fromView = sender.view else {
return
}
showMediaDetailViewController(fromView: fromView)
}
func showMediaDetailViewController(fromView: UIView) {
self.mediaDetailPresenter?.presentDetails(mediaMessageView: self, fromView: fromView)
}
} }

Loading…
Cancel
Save