diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 3cc140b66..83b37ef40 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -487,7 +487,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc func save(_ viewItem: ConversationViewItem) { guard viewItem.canSaveMedia() else { return } viewItem.saveMediaAction() - sendMediaSavedNotificationIfNeeded(with: viewItem.interaction.timestamp) + sendMediaSavedNotificationIfNeeded(for: viewItem) } func ban(_ viewItem: ConversationViewItem) { @@ -668,12 +668,12 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc */ } - func sendMediaSavedNotificationIfNeeded(with timestamp: UInt64) { + func sendMediaSavedNotificationIfNeeded(for viewItem: ConversationViewItem) { // Disabled until other platforms implement it as well /* - guard thread is TSContactThread else { return } + guard thread is TSContactThread, viewItem.interaction.interactionType() == .incomingMessage else { return } let message = DataExtractionNotification() - message.kind = .mediaSaved(timestamp: timestamp) + message.kind = .mediaSaved(timestamp: viewItem.interaction.timestamp) Storage.write { transaction in MessageSender.send(message, in: self.thread, using: transaction) } diff --git a/Session/Media Viewing & Editing/MediaPageViewController.swift b/Session/Media Viewing & Editing/MediaPageViewController.swift index 404145152..6036e8044 100644 --- a/Session/Media Viewing & Editing/MediaPageViewController.swift +++ b/Session/Media Viewing & Editing/MediaPageViewController.swift @@ -381,7 +381,16 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou let attachmentStream = currentViewController.galleryItem.attachmentStream - AttachmentSharing.showShareUI(forAttachment: attachmentStream) + AttachmentSharing.showShareUI(forAttachment: attachmentStream) { activityType in + guard let activityType = activityType, activityType == .saveToCameraRoll, + let tsMessage = currentViewController.galleryItem.message as? TSIncomingMessage, let thread = tsMessage.thread as? TSContactThread else { return } + let message = DataExtractionNotification() + message.kind = .mediaSaved(timestamp: tsMessage.timestamp) + Storage.write { transaction in + MessageSender.send(message, in: thread, using: transaction) + } + + } } @objc diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 4ce89d936..ee30b81b5 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -110,7 +110,7 @@ extension MessageReceiver { private static func handleDataExtractionNotification(_ message: DataExtractionNotification, using transaction: Any) { let transaction = transaction as! YapDatabaseReadWriteTransaction guard message.groupPublicKey == nil, - let thread = TSContactThread.getWithContactId(message.sender!, transaction: transaction), case .screenshot = message.kind else { return } + let thread = TSContactThread.getWithContactId(message.sender!, transaction: transaction) else { return } let type: TSInfoMessageType switch message.kind! { case .screenshot: type = .screenshotNotification diff --git a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.h b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.h index 0be5d3194..e3454b5e1 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.h +++ b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN @class TSAttachmentStream; -typedef void (^AttachmentSharingCompletion)(void); +typedef void (^AttachmentSharingCompletion)(UIActivityType __nullable activityType); @interface AttachmentSharing : NSObject @@ -14,15 +14,14 @@ typedef void (^AttachmentSharingCompletion)(void); completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForAttachment:(TSAttachmentStream *)stream; ++ (void)showShareUIForAttachment:(TSAttachmentStream *)stream completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForURL:(NSURL *)url; - + (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForURLs:(NSArray *)urls completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForText:(NSString *)text; - + (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion; #ifdef DEBUG diff --git a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m index cb4f18bd1..770342426 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m +++ b/SignalUtilitiesKit/Media Viewing & Editing/AttachmentSharing.m @@ -28,7 +28,14 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssertDebug(stream); - [self showShareUIForURL:stream.originalMediaURL]; + [self showShareUIForAttachment:stream completion:nil]; +} + ++ (void)showShareUIForAttachment:(TSAttachmentStream *)stream completion:(nullable AttachmentSharingCompletion)completion +{ + OWSAssertDebug(stream); + + [self showShareUIForURL:stream.originalMediaURL completion:completion]; } + (void)showShareUIForURL:(NSURL *)url @@ -95,7 +102,7 @@ NS_ASSUME_NONNULL_BEGIN } if (completion) { - DispatchMainThreadSafe(completion); + DispatchMainThreadSafe(^{ completion(activityType); }); } }];