restore Share/Delete functionality to gallery items in the post multi-attachment world
This commit is contained in:
parent
42bf267607
commit
7cf53293da
|
@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@class GalleryItemBox;
|
||||
@class MediaDetailViewController;
|
||||
@class TSAttachment;
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, MediaGalleryOption) {
|
||||
MediaGalleryOptionSliderEnabled = 1 << 0,
|
||||
|
@ -19,7 +20,7 @@ typedef NS_OPTIONS(NSInteger, MediaGalleryOption) {
|
|||
@protocol MediaDetailViewControllerDelegate <NSObject>
|
||||
|
||||
- (void)mediaDetailViewController:(MediaDetailViewController *)mediaDetailViewController
|
||||
requestDeleteConversationViewItem:(id<ConversationViewItem>)conversationViewItem;
|
||||
requestDeleteAttachment:(TSAttachment *)attachment;
|
||||
|
||||
- (void)mediaDetailViewController:(MediaDetailViewController *)mediaDetailViewController
|
||||
isPlayingVideo:(BOOL)isPlayingVideo;
|
||||
|
|
|
@ -348,32 +348,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
- (void)didPressShare:(id)sender
|
||||
{
|
||||
OWSFailDebug(@"TODO: support sharing individual attachment, not viewItem");
|
||||
|
||||
OWSLogInfo(@"didPressShare");
|
||||
if (!self.viewItem) {
|
||||
OWSFailDebug(@"share should only be available when a viewItem is present");
|
||||
return;
|
||||
}
|
||||
|
||||
[self.viewItem shareMediaAction];
|
||||
}
|
||||
|
||||
- (void)didPressDelete:(id)sender
|
||||
{
|
||||
OWSFailDebug(@"TODO: support sharing individual attachment, not viewItem");
|
||||
|
||||
OWSLogInfo(@"didPressDelete");
|
||||
if (!self.viewItem) {
|
||||
OWSFailDebug(@"delete should only be available when a viewItem is present");
|
||||
return;
|
||||
}
|
||||
|
||||
[self.delegate mediaDetailViewController:self requestDeleteConversationViewItem:self.viewItem];
|
||||
}
|
||||
|
||||
- (void)didPressPlayBarButton:(id)sender
|
||||
{
|
||||
OWSAssertDebug(self.isVideo);
|
||||
|
|
|
@ -284,7 +284,7 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
|
|||
public func presentDetailView(fromViewController: UIViewController, mediaAttachment: TSAttachment, replacingView: UIView) {
|
||||
var galleryItem: MediaGalleryItem?
|
||||
uiDatabaseConnection.read { transaction in
|
||||
galleryItem = self.buildGalleryItem(attachment: mediaAttachment, transaction: transaction)!
|
||||
galleryItem = self.buildGalleryItem(attachment: mediaAttachment, transaction: transaction)
|
||||
}
|
||||
|
||||
guard let initialDetailItem = galleryItem else {
|
||||
|
@ -807,12 +807,19 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
|
|||
deletedGalleryItems.formUnion(items)
|
||||
dataSourceDelegates.forEach { $0.value?.mediaGalleryDataSource(self, willDelete: items, initiatedBy: initiatedBy) }
|
||||
|
||||
for item in items {
|
||||
self.deletedAttachments.insert(item.attachmentStream)
|
||||
}
|
||||
|
||||
self.editingDatabaseConnection.asyncReadWrite { transaction in
|
||||
for item in items {
|
||||
let message = item.message
|
||||
let attachment = item.attachmentStream
|
||||
message.removeAttachment(attachment, transaction: transaction)
|
||||
self.deletedAttachments.insert(attachment)
|
||||
if message.attachmentIds.count == 0 {
|
||||
Logger.debug("removing message after removing last media attachment")
|
||||
message.remove(with: transaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -277,7 +277,10 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
|
|||
owsFailDebug("currentViewController was unexpectedly nil")
|
||||
return
|
||||
}
|
||||
currentViewController.didPressShare(sender)
|
||||
|
||||
let attachmentStream = currentViewController.galleryItem.attachmentStream
|
||||
|
||||
AttachmentSharing.showShareUI(forAttachment: attachmentStream)
|
||||
}
|
||||
|
||||
@objc
|
||||
|
@ -508,7 +511,7 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
|
|||
self.shouldHideToolbars = !self.shouldHideToolbars
|
||||
}
|
||||
|
||||
public func mediaDetailViewController(_ mediaDetailViewController: MediaDetailViewController, requestDelete conversationViewItem: ConversationViewItem) {
|
||||
public func mediaDetailViewController(_ mediaDetailViewController: MediaDetailViewController, requestDelete attachment: TSAttachment) {
|
||||
guard let mediaGalleryDataSource = self.mediaGalleryDataSource else {
|
||||
owsFailDebug("mediaGalleryDataSource was unexpectedly nil")
|
||||
self.presentingViewController?.dismiss(animated: true)
|
||||
|
@ -516,15 +519,8 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
|
|||
return
|
||||
}
|
||||
|
||||
guard let message = conversationViewItem.interaction as? TSMessage else {
|
||||
owsFailDebug("unexpected interaction: \(type(of: conversationViewItem))")
|
||||
self.presentingViewController?.dismiss(animated: true)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
guard let galleryItem = self.mediaGalleryDataSource?.galleryItems.first(where: { $0.message == message }) else {
|
||||
owsFailDebug("unexpected interaction: \(type(of: conversationViewItem))")
|
||||
guard let galleryItem = self.mediaGalleryDataSource?.galleryItems.first(where: { $0.attachmentStream == attachment }) else {
|
||||
owsFailDebug("galleryItem was unexpectedly nil")
|
||||
self.presentingViewController?.dismiss(animated: true)
|
||||
|
||||
return
|
||||
|
|
|
@ -207,8 +207,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|||
[TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
||||
if (attachment) {
|
||||
[attachments addObject:attachment];
|
||||
} else {
|
||||
OWSFailDebug(@"Missing attachment for: %@.", attachmentId);
|
||||
}
|
||||
}
|
||||
return [attachments copy];
|
||||
|
@ -221,9 +219,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|||
|
||||
[self.attachmentIds removeObject:attachment.uniqueId];
|
||||
|
||||
// TODO - Should we delete self if we delete the last attachment?
|
||||
// Or should that depend on whether message.body == nil
|
||||
|
||||
[self saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
|
@ -262,8 +257,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|||
}
|
||||
|
||||
TSAttachment *_Nullable attachment = [self attachmentsWithTransaction:transaction].firstObject;
|
||||
OWSAssertDebug(attachment);
|
||||
|
||||
if (![OWSMimeTypeOversizeTextMessage isEqualToString:attachment.contentType]
|
||||
|| ![attachment isKindOfClass:TSAttachmentStream.class]) {
|
||||
return nil;
|
||||
|
|
Loading…
Reference in New Issue