Added code to preview PDF attachments

This commit is contained in:
Morgan Pretty 2022-01-28 16:24:18 +11:00
parent 6aac2a9966
commit b85c113da6
4 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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;

View File

@ -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";