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)
if conversationViewItem.hasMediaActionContent {
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)

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

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

@ -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:
return NO;
case OWSMessageCellType_DownloadingAttachment: {
case OWSMessageCellType_DownloadingAttachment:
case OWSMessageCellType_MediaGallery:
return NO;
}
}
- (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) {

Loading…
Cancel
Save