Save and share all items in album

pull/1/head
Matthew Chen 6 years ago
parent baa42dc910
commit 4fda1be3f5

@ -98,6 +98,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream; @property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer; @property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
@property (nonatomic, nullable) ContactShareViewModel *contactShare; @property (nonatomic, nullable) ContactShareViewModel *contactShare;
@property (nonatomic, nullable) NSArray<TSAttachment *> *allMediaAlbumAttachments;
@property (nonatomic, nullable) NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems; @property (nonatomic, nullable) NSArray<ConversationMediaAlbumItem *> *mediaAlbumItems;
@property (nonatomic, nullable) NSString *systemMessageText; @property (nonatomic, nullable) NSString *systemMessageText;
@property (nonatomic, nullable) TSThread *incomingMessageAuthorThread; @property (nonatomic, nullable) TSThread *incomingMessageAuthorThread;
@ -162,6 +163,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.displayableQuotedText = nil; self.displayableQuotedText = nil;
self.quotedReply = nil; self.quotedReply = nil;
self.systemMessageText = nil; self.systemMessageText = nil;
self.allMediaAlbumAttachments = nil;
self.mediaAlbumItems = nil; self.mediaAlbumItems = nil;
[self updateAuthorConversationColorNameWithTransaction:transaction]; [self updateAuthorConversationColorNameWithTransaction:transaction];
@ -601,6 +603,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
} }
} }
self.allMediaAlbumAttachments = attachments;
self.mediaAlbumItems = mediaAlbumItems; self.mediaAlbumItems = mediaAlbumItems;
self.messageCellType = OWSMessageCellType_MediaAlbum; self.messageCellType = OWSMessageCellType_MediaAlbum;
NSString *_Nullable albumTitle = [message bodyTextWithTransaction:transaction]; NSString *_Nullable albumTitle = [message bodyTextWithTransaction:transaction];
@ -925,9 +928,13 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
// TODO: We need a "canShareMediaAction" method. // TODO: We need a "canShareMediaAction" method.
OWSAssertDebug(self.mediaAlbumItems); OWSAssertDebug(self.mediaAlbumItems);
NSMutableArray<TSAttachmentStream *> *attachmentStreams = [NSMutableArray new]; NSMutableArray<TSAttachmentStream *> *attachmentStreams = [NSMutableArray new];
for (ConversationMediaAlbumItem *mediaAlbumItem in self.mediaAlbumItems) { for (TSAttachment *attachment in self.allMediaAlbumAttachments) {
if (mediaAlbumItem.attachmentStream && mediaAlbumItem.attachmentStream.isValidVisualMedia) { if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
[attachmentStreams addObject:mediaAlbumItem.attachmentStream]; continue;
}
TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
if (attachmentStream.isValidVisualMedia) {
[attachmentStreams addObject:attachmentStream];
} }
} }
if (attachmentStreams.count < 1) { if (attachmentStreams.count < 1) {
@ -1022,15 +1029,16 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
case OWSMessageCellType_MediaAlbum: { case OWSMessageCellType_MediaAlbum: {
// TODO: Use PHPhotoLibrary. // TODO: Use PHPhotoLibrary.
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
for (ConversationMediaAlbumItem *mediaAlbumItem in self.mediaAlbumItems) { for (TSAttachment *attachment in self.allMediaAlbumAttachments) {
if (!mediaAlbumItem.attachmentStream) { if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
continue; continue;
} }
if (!mediaAlbumItem.attachmentStream.isValidVisualMedia) { TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
if (!attachmentStream.isValidVisualMedia) {
continue; continue;
} }
if (mediaAlbumItem.attachmentStream.isImage || mediaAlbumItem.attachmentStream.isAnimated) { if (attachmentStream.isImage || attachmentStream.isAnimated) {
NSData *data = [NSData dataWithContentsOfURL:[mediaAlbumItem.attachmentStream originalMediaURL]]; NSData *data = [NSData dataWithContentsOfURL:[attachmentStream originalMediaURL]];
if (!data) { if (!data) {
OWSFailDebug(@"Could not load image data"); OWSFailDebug(@"Could not load image data");
continue; continue;
@ -1043,11 +1051,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
} }
}]; }];
} }
if (mediaAlbumItem.attachmentStream.isVideo) { if (attachmentStream.isVideo) {
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum( if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(attachmentStream.originalFilePath)) {
mediaAlbumItem.attachmentStream.originalFilePath)) { UISaveVideoAtPathToSavedPhotosAlbum(attachmentStream.originalFilePath, self, nil, nil);
UISaveVideoAtPathToSavedPhotosAlbum(
mediaAlbumItem.attachmentStream.originalFilePath, self, nil, nil);
} }
} }
} }

Loading…
Cancel
Save