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

@ -241,8 +241,8 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
case OWSMessageCellType_ContactShare:
return NO;
case OWSMessageCellType_MediaGallery:
// TODO: How will media gallery captions work?
return NO;
// Is there a gallery title?
return self.hasBodyText;
}
}
@ -1250,29 +1250,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
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
{
[NSLayoutConstraint deactivateConstraints:self.viewConstraints];
@ -1381,8 +1358,6 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
{
OWSAssertDebug(self.delegate);
TSAttachmentStream *_Nullable attachmentStream = self.viewItem.attachmentStream;
switch (self.cellType) {
case OWSMessageCellType_Unknown:
case OWSMessageCellType_TextMessage:
@ -1390,37 +1365,37 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
break;
case OWSMessageCellType_StillImage:
OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream);
OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView];
break;
case OWSMessageCellType_AnimatedImage:
OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream);
OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapImageViewItem:self.viewItem
attachmentStream:attachmentStream
attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView];
break;
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;
case OWSMessageCellType_Video:
OWSAssertDebug(self.bodyMediaView);
OWSAssertDebug(attachmentStream);
OWSAssertDebug(self.viewItem.attachmentStream);
[self.delegate didTapVideoViewItem:self.viewItem
attachmentStream:attachmentStream
attachmentStream:self.viewItem.attachmentStream
imageView:self.bodyMediaView];
return;
case OWSMessageCellType_GenericAttachment:
OWSAssertDebug(attachmentStream);
OWSAssertDebug(self.viewItem.attachmentStream);
[AttachmentSharing showShareUIForAttachment:attachmentStream];
[AttachmentSharing showShareUIForAttachment:self.viewItem.attachmentStream];
break;
case OWSMessageCellType_DownloadingAttachment: {
TSAttachmentPointer *_Nullable attachmentPointer = self.viewItem.attachmentPointer;
@ -1435,7 +1410,25 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
[self.delegate didTapContactShareViewItem:self.viewItem];
break;
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;
}
}

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

Loading…
Cancel
Save