Fix media gallery cell edge cases.

pull/1/head
Matthew Chen 7 years ago
parent 34e85dd90e
commit d538301632

@ -99,8 +99,10 @@ class ConversationViewItemActions: NSObject {
actions.append(replyAction) actions.append(replyAction)
if conversationViewItem.hasMediaActionContent { if conversationViewItem.hasMediaActionContent {
let copyMediaAction = MessageActionBuilder.copyMedia(conversationViewItem: conversationViewItem, delegate: delegate) if conversationViewItem.canCopyMedia() {
actions.append(copyMediaAction) let copyMediaAction = MessageActionBuilder.copyMedia(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(copyMediaAction)
}
if conversationViewItem.canSaveMedia() { if conversationViewItem.canSaveMedia() {
let saveMediaAction = MessageActionBuilder.saveMedia(conversationViewItem: conversationViewItem, delegate: delegate) let saveMediaAction = MessageActionBuilder.saveMedia(conversationViewItem: conversationViewItem, delegate: delegate)
actions.append(saveMediaAction) actions.append(saveMediaAction)

@ -394,6 +394,11 @@ private class MockConversationViewItem: NSObject, ConversationViewItem {
return return
} }
func canCopyMedia() -> Bool {
owsFailDebug("unexpected invocation")
return false
}
func canSaveMedia() -> Bool { func canSaveMedia() -> Bool {
owsFailDebug("unexpected invocation") owsFailDebug("unexpected invocation")
return false return false

@ -135,6 +135,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
- (void)saveMediaAction; - (void)saveMediaAction;
- (void)deleteAction; - (void)deleteAction;
- (BOOL)canCopyMedia;
- (BOOL)canSaveMedia; - (BOOL)canSaveMedia;
// For view items that correspond to interactions, this is the interaction's unique id. // For view items that correspond to interactions, this is the interaction's unique id.

@ -877,15 +877,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
break; break;
} }
case OWSMessageCellType_MediaGallery: { case OWSMessageCellType_MediaGallery: {
// AFAIK UIPasteboard only supports "multiple representations OWSFailDebug(@"Can't copy media gallery");
// 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];
break; break;
} }
} }
@ -947,7 +939,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
} }
} }
- (BOOL)canSaveMedia - (BOOL)canCopyMedia
{ {
switch (self.messageCellType) { switch (self.messageCellType) {
case OWSMessageCellType_Unknown: case OWSMessageCellType_Unknown:
@ -963,10 +955,30 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
return UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.attachmentStream.originalFilePath); return UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.attachmentStream.originalFilePath);
case OWSMessageCellType_GenericAttachment: case OWSMessageCellType_GenericAttachment:
case OWSMessageCellType_DownloadingAttachment:
case OWSMessageCellType_MediaGallery:
return NO; 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; return NO;
}
case OWSMessageCellType_MediaGallery: { case OWSMessageCellType_MediaGallery: {
for (ConversationMediaGalleryItem *mediaGalleryItem in self.mediaGalleryItems) { for (ConversationMediaGalleryItem *mediaGalleryItem in self.mediaGalleryItems) {
if (!mediaGalleryItem.attachmentStream) { if (!mediaGalleryItem.attachmentStream) {

Loading…
Cancel
Save