Fix media gallery cell edge cases.

This commit is contained in:
Matthew Chen 2018-11-06 10:08:14 -05:00
parent 34e85dd90e
commit d538301632
4 changed files with 34 additions and 14 deletions

View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -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,6 +939,28 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
}
}
- (BOOL)canCopyMedia
{
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:
case OWSMessageCellType_MediaGallery:
return NO;
}
}
- (BOOL)canSaveMedia
{
switch (self.messageCellType) {
@ -963,10 +977,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
case OWSMessageCellType_Video:
return UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.attachmentStream.originalFilePath);
case OWSMessageCellType_GenericAttachment:
case OWSMessageCellType_DownloadingAttachment:
return NO;
case OWSMessageCellType_DownloadingAttachment: {
return NO;
}
case OWSMessageCellType_MediaGallery: {
for (ConversationMediaGalleryItem *mediaGalleryItem in self.mediaGalleryItems) {
if (!mediaGalleryItem.attachmentStream) {