Fix media gallery cell edge cases.

pull/1/head
Matthew Chen 7 years ago
parent cfcb6cb15b
commit ee3bdca336

@ -76,6 +76,10 @@ public class ConversationMediaView: UIView {
return return
} }
let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in
guard attachmentStream.isValidImage else {
owsFailDebug("Ignoring invalid attachment.")
return nil
}
guard let filePath = attachmentStream.originalFilePath else { guard let filePath = attachmentStream.originalFilePath else {
owsFailDebug("Attachment stream missing original file path.") owsFailDebug("Attachment stream missing original file path.")
return nil return nil
@ -120,6 +124,10 @@ public class ConversationMediaView: UIView {
return return
} }
let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in
guard attachmentStream.isValidImage else {
owsFailDebug("Ignoring invalid attachment.")
return nil
}
return attachmentStream.thumbnailImageMedium(success: { (image) in return attachmentStream.thumbnailImageMedium(success: { (image) in
stillImageView.image = image stillImageView.image = image
}, failure: { }, failure: {
@ -170,6 +178,10 @@ public class ConversationMediaView: UIView {
return return
} }
let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in let cachedValue = strongSelf.tryToLoadMedia(loadMediaBlock: { () -> AnyObject? in
guard attachmentStream.isValidVideo else {
owsFailDebug("Ignoring invalid attachment.")
return nil
}
return attachmentStream.thumbnailImageMedium(success: { (image) in return attachmentStream.thumbnailImageMedium(success: { (image) in
stillImageView.image = image stillImageView.image = image
}, failure: { }, failure: {

@ -241,8 +241,8 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
case OWSMessageCellType_ContactShare: case OWSMessageCellType_ContactShare:
return NO; return NO;
case OWSMessageCellType_MediaGallery: case OWSMessageCellType_MediaGallery:
// TODO: How will media gallery captions work? // Is there a gallery title?
return NO; return self.hasBodyText;
} }
} }
@ -1250,29 +1250,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
return [self.conversationStyle bubbleTextColorWithMessage:message]; return [self.conversationStyle bubbleTextColorWithMessage:message];
} }
- (BOOL)isMediaBeingSent
{
if (self.isIncoming) {
return NO;
}
if (self.cellType == OWSMessageCellType_DownloadingAttachment) {
return NO;
}
if (self.cellType == OWSMessageCellType_ContactShare) {
// TODO: Handle this case.
return NO;
}
if (self.cellType == OWSMessageCellType_MediaGallery) {
// TODO:
return NO;
}
if (!self.attachmentStream) {
return NO;
}
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)self.viewItem.interaction;
return outgoingMessage.messageState == TSOutgoingMessageStateSending;
}
- (void)prepareForReuse - (void)prepareForReuse
{ {
[NSLayoutConstraint deactivateConstraints:self.viewConstraints]; [NSLayoutConstraint deactivateConstraints:self.viewConstraints];
@ -1381,8 +1358,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
{ {
OWSAssertDebug(self.delegate); OWSAssertDebug(self.delegate);
TSAttachmentStream *_Nullable attachmentStream = self.viewItem.attachmentStream;
switch (self.cellType) { switch (self.cellType) {
case OWSMessageCellType_Unknown: case OWSMessageCellType_Unknown:
case OWSMessageCellType_TextMessage: case OWSMessageCellType_TextMessage:
@ -1390,37 +1365,37 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
break; break;
case OWSMessageCellType_StillImage: case OWSMessageCellType_StillImage:
OWSAssertDebug(self.bodyMediaView); OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream); OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem [self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView]; imageView:self.bodyMediaView];
break; break;
case OWSMessageCellType_AnimatedImage: case OWSMessageCellType_AnimatedImage:
OWSAssertDebug(self.bodyMediaView); OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream); OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem [self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView]; imageView:self.bodyMediaView];
break; break;
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
OWSAssertDebug(attachmentStream); OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapAudioViewItem:self.viewItem attachmentStream:attachmentStream]; [self.delegate didTapAudioViewItem:self.viewItem attachmentStream:self.viewItem.attachmentStream];
return; return;
case OWSMessageCellType_Video: case OWSMessageCellType_Video:
OWSAssertDebug(self.bodyMediaView); OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream); OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapVideoViewItem:self.viewItem [self.delegate didTapVideoViewItem:self.viewItem
attachmentStream:attachmentStream attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView]; imageView:self.bodyMediaView];
return; return;
case OWSMessageCellType_GenericAttachment: case OWSMessageCellType_GenericAttachment:
OWSAssertDebug(attachmentStream); OWSAssertDebug(self.viewItem.attachmentStream);
[AttachmentSharing showShareUIForAttachment:attachmentStream]; [AttachmentSharing showShareUIForAttachment:self.viewItem.attachmentStream];
break; break;
case OWSMessageCellType_DownloadingAttachment: { case OWSMessageCellType_DownloadingAttachment: {
TSAttachmentPointer *_Nullable attachmentPointer = self.viewItem.attachmentPointer; TSAttachmentPointer *_Nullable attachmentPointer = self.viewItem.attachmentPointer;
@ -1435,7 +1410,25 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
[self.delegate didTapContactShareViewItem:self.viewItem]; [self.delegate didTapContactShareViewItem:self.viewItem];
break; break;
case OWSMessageCellType_MediaGallery: case OWSMessageCellType_MediaGallery:
// TODO: OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(self.viewItem.mediaGalleryItems.count > 0);
// For now, use first valid attachment.
TSAttachmentStream *_Nullable attachmentStream = nil;
for (ConversationMediaGalleryItem *mediaGalleryItem in self.viewItem.mediaGalleryItems) {
if (mediaGalleryItem.attachmentStream && mediaGalleryItem.attachmentStream.isValidVisualMedia) {
attachmentStream = mediaGalleryItem.attachmentStream;
break;
}
}
if (!attachmentStream) {
OWSLogInfo(@"Ignoring tap on gallery without any valid attachments.");
return;
}
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
imageView:self.bodyMediaView];
break; break;
} }
} }

@ -158,6 +158,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.displayableQuotedText = nil; self.displayableQuotedText = nil;
self.quotedReply = nil; self.quotedReply = nil;
self.systemMessageText = nil; self.systemMessageText = nil;
self.mediaGalleryItems = nil;
[self updateAuthorConversationColorNameWithTransaction:transaction]; [self updateAuthorConversationColorNameWithTransaction:transaction];
@ -545,6 +546,10 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
NSArray<ConversationMediaGalleryItem *> *mediaGalleryItems = [self mediaGalleryItemsForAttachments:attachments]; NSArray<ConversationMediaGalleryItem *> *mediaGalleryItems = [self mediaGalleryItemsForAttachments:attachments];
self.mediaGalleryItems = mediaGalleryItems; self.mediaGalleryItems = mediaGalleryItems;
self.messageCellType = OWSMessageCellType_MediaGallery; self.messageCellType = OWSMessageCellType_MediaGallery;
NSString *_Nullable galleryTitle = [message bodyTextWithTransaction:transaction];
if (galleryTitle) {
self.displayableBodyText = [self displayableBodyTextForText:galleryTitle interactionId:message.uniqueId];
}
return; return;
} }
// Only media galleries should have more than one attachment. // Only media galleries should have more than one attachment.

Loading…
Cancel
Save