From d538301632ec10eee81521168db844d60198f881 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 6 Nov 2018 10:08:14 -0500 Subject: [PATCH] Fix media gallery cell edge cases. --- Signal/src/Models/MessageActions.swift | 6 ++-- .../ColorPickerViewController.swift | 5 +++ .../ConversationView/ConversationViewItem.h | 1 + .../ConversationView/ConversationViewItem.m | 36 ++++++++++++------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Signal/src/Models/MessageActions.swift b/Signal/src/Models/MessageActions.swift index 48785f652..07c65f42a 100644 --- a/Signal/src/Models/MessageActions.swift +++ b/Signal/src/Models/MessageActions.swift @@ -99,8 +99,10 @@ class ConversationViewItemActions: NSObject { actions.append(replyAction) if conversationViewItem.hasMediaActionContent { - let copyMediaAction = MessageActionBuilder.copyMedia(conversationViewItem: conversationViewItem, delegate: delegate) - actions.append(copyMediaAction) + if conversationViewItem.canCopyMedia() { + let copyMediaAction = MessageActionBuilder.copyMedia(conversationViewItem: conversationViewItem, delegate: delegate) + actions.append(copyMediaAction) + } if conversationViewItem.canSaveMedia() { let saveMediaAction = MessageActionBuilder.saveMedia(conversationViewItem: conversationViewItem, delegate: delegate) actions.append(saveMediaAction) diff --git a/Signal/src/ViewControllers/ColorPickerViewController.swift b/Signal/src/ViewControllers/ColorPickerViewController.swift index 5baad56ae..7bbe2e38e 100644 --- a/Signal/src/ViewControllers/ColorPickerViewController.swift +++ b/Signal/src/ViewControllers/ColorPickerViewController.swift @@ -394,6 +394,11 @@ private class MockConversationViewItem: NSObject, ConversationViewItem { return } + func canCopyMedia() -> Bool { + owsFailDebug("unexpected invocation") + return false + } + func canSaveMedia() -> Bool { owsFailDebug("unexpected invocation") return false diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h index edb0a2585..394219d2a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h @@ -135,6 +135,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); - (void)saveMediaAction; - (void)deleteAction; +- (BOOL)canCopyMedia; - (BOOL)canSaveMedia; // For view items that correspond to interactions, this is the interaction's unique id. diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 0c86c59e8..521a72ce5 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -877,15 +877,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) break; } case OWSMessageCellType_MediaGallery: { - // AFAIK UIPasteboard only supports "multiple representations - // of a single item", not "multiple different items". - TSAttachmentStream *_Nullable firstAttachment = self.firstValidGalleryAttachment; - if (!firstAttachment) { - OWSLogWarn(@"Ignoring copy for gallery without any valid attachments."); - return; - } - // - [self copyAttachmentToPasteboard:firstAttachment]; + OWSFailDebug(@"Can't copy media gallery"); break; } } @@ -947,7 +939,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) } } -- (BOOL)canSaveMedia +- (BOOL)canCopyMedia { switch (self.messageCellType) { case OWSMessageCellType_Unknown: @@ -963,10 +955,30 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) case OWSMessageCellType_Video: return UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.attachmentStream.originalFilePath); case OWSMessageCellType_GenericAttachment: + case OWSMessageCellType_DownloadingAttachment: + case OWSMessageCellType_MediaGallery: return NO; - case OWSMessageCellType_DownloadingAttachment: { + } +} + +- (BOOL)canSaveMedia +{ + switch (self.messageCellType) { + case OWSMessageCellType_Unknown: + case OWSMessageCellType_TextMessage: + case OWSMessageCellType_OversizeTextMessage: + case OWSMessageCellType_ContactShare: + return NO; + case OWSMessageCellType_StillImage: + case OWSMessageCellType_AnimatedImage: + return YES; + case OWSMessageCellType_Audio: + return NO; + case OWSMessageCellType_Video: + return UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.attachmentStream.originalFilePath); + case OWSMessageCellType_GenericAttachment: + case OWSMessageCellType_DownloadingAttachment: return NO; - } case OWSMessageCellType_MediaGallery: { for (ConversationMediaGalleryItem *mediaGalleryItem in self.mediaGalleryItems) { if (!mediaGalleryItem.attachmentStream) {