From b85c113da62b4f57ec8a28faa498abb579a94248 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 28 Jan 2022 16:24:18 +1100 Subject: [PATCH] Added code to preview PDF attachments --- Podfile.lock | 8 ++++---- .../ConversationVC+Interaction.swift | 18 +++++++++++++++++- SessionUtilitiesKit/Media/MIMETypeUtil.h | 1 + SessionUtilitiesKit/Media/MIMETypeUtil.m | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 24d6abeed..d8af51feb 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -132,7 +132,7 @@ DEPENDENCIES: - SignalCoreKit (from `https://github.com/oxen-io/session-ios-core-kit`, branch `session-version`) - Sodium (~> 0.9.1) - SwiftProtobuf (~> 1.5.0) - - YapDatabase/SQLCipher (from `https://github.com/loki-project/session-ios-yap-database.git`, branch `signal-release`) + - YapDatabase/SQLCipher (from `https://github.com/oxen-io/session-ios-yap-database.git`, branch `signal-release`) - YYImage (from `https://github.com/signalapp/YYImage`) - ZXingObjC @@ -163,7 +163,7 @@ EXTERNAL SOURCES: :git: https://github.com/oxen-io/session-ios-core-kit YapDatabase: :branch: signal-release - :git: https://github.com/loki-project/session-ios-yap-database.git + :git: https://github.com/oxen-io/session-ios-yap-database.git YYImage: :git: https://github.com/signalapp/YYImage @@ -179,7 +179,7 @@ CHECKOUT OPTIONS: :git: https://github.com/oxen-io/session-ios-core-kit YapDatabase: :commit: d84069e25e12a16ab4422e5258127a04b70489ad - :git: https://github.com/loki-project/session-ios-yap-database.git + :git: https://github.com/oxen-io/session-ios-yap-database.git YYImage: :commit: 62a4cede20bcf31da73d18163408e46a92f171c6 :git: https://github.com/signalapp/YYImage @@ -204,6 +204,6 @@ SPEC CHECKSUMS: YYImage: f1ddd15ac032a58b78bbed1e012b50302d318331 ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb -PODFILE CHECKSUM: 7722d8a03a0ebc6ecd0070d02b199bd748992f12 +PODFILE CHECKSUM: 7f961dc4934dd213f5a3277af57d54caef7a4442 COCOAPODS: 1.11.2 diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 61ff20d9f..d397dc668 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1,6 +1,7 @@ import CoreServices import Photos import PhotosUI +import SessionUtilitiesKit extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuActionDelegate, ScrollToBottomButtonDelegate, SendMediaNavDelegate, UIDocumentPickerDelegate, AttachmentApprovalViewControllerDelegate, GifPickerViewControllerDelegate, @@ -463,7 +464,14 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc let thread = self.thread as? TSContactThread, Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true { confirmDownload() - } else { + } + else if viewItem.attachmentStream?.contentType == OWSMimeTypeApplicationPdf, let filePathString: String = viewItem.attachmentStream?.originalFilePath { + let fileUrl: URL = URL(fileURLWithPath: filePathString) + let interactionController: UIDocumentInteractionController = UIDocumentInteractionController(url: fileUrl) + interactionController.delegate = self + interactionController.presentPreview(animated: true) + } + else { // Open the document if possible guard let url = viewItem.attachmentStream?.originalMediaURL else { return } let shareVC = UIActivityViewController(activityItems: [ url ], applicationActivities: nil) @@ -981,3 +989,11 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc OWSAlerts.showAlert(title: title, message: message) } } + +// MARK: - UIDocumentInteractionControllerDelegate + +extension ConversationVC: UIDocumentInteractionControllerDelegate { + func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { + return self + } +} diff --git a/SessionUtilitiesKit/Media/MIMETypeUtil.h b/SessionUtilitiesKit/Media/MIMETypeUtil.h index 1c12bc7fa..cad42aef8 100644 --- a/SessionUtilitiesKit/Media/MIMETypeUtil.h +++ b/SessionUtilitiesKit/Media/MIMETypeUtil.h @@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const OWSMimeTypeApplicationOctetStream; extern NSString *const OWSMimeTypeApplicationZip; +extern NSString *const OWSMimeTypeApplicationPdf; extern NSString *const OWSMimeTypeImagePng; extern NSString *const OWSMimeTypeImageJpeg; extern NSString *const OWSMimeTypeImageGif; diff --git a/SessionUtilitiesKit/Media/MIMETypeUtil.m b/SessionUtilitiesKit/Media/MIMETypeUtil.m index d2024d6ad..c17e98c3a 100644 --- a/SessionUtilitiesKit/Media/MIMETypeUtil.m +++ b/SessionUtilitiesKit/Media/MIMETypeUtil.m @@ -22,6 +22,7 @@ NSString *const OWSMimeTypeImageBmp2 = @"image/x-windows-bmp"; NSString *const OWSMimeTypeOversizeTextMessage = @"text/x-signal-plain"; NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype"; NSString *const OWSMimeTypeApplicationZip = @"application/zip"; +NSString *const OWSMimeTypeApplicationPdf = @"application/pdf"; NSString *const kOversizeTextAttachmentUTI = @"org.whispersystems.oversize-text-attachment"; NSString *const kOversizeTextAttachmentFileExtension = @"txt";