Updated the code to show the document interaction controller for text files as well

This commit is contained in:
Morgan Pretty 2022-02-14 09:54:17 +11:00
parent 185b2d2a97
commit 161a90ad28
5 changed files with 26 additions and 1 deletions

View File

@ -472,7 +472,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
confirmDownload()
}
else if viewItem.attachmentStream?.contentType == OWSMimeTypeApplicationPdf, let filePathString: String = viewItem.attachmentStream?.originalFilePath {
else if (viewItem.attachmentStream?.isText == true || 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

View File

@ -84,6 +84,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
@property (nonatomic, readonly) BOOL isAudio;
@property (nonatomic, readonly) BOOL isVoiceMessage;
@property (nonatomic, readonly) BOOL isVisualMedia;
@property (nonatomic, readonly) BOOL isText;
@property (nonatomic, readonly) BOOL isOversizeText;
+ (NSString *)emojiForMimeType:(NSString *)contentType;

View File

@ -3,6 +3,14 @@
#import "TSAttachmentPointer.h"
#import <SignalCoreKit/NSString+OWS.h>
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
#else
#import <CoreServices/CoreServices.h>
#endif
NS_ASSUME_NONNULL_BEGIN
NSUInteger const TSAttachmentSchemaVersion = 4;
@ -229,6 +237,10 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
return [MIMETypeUtil isVisualMedia:self.contentType];
}
- (BOOL)isText {
return [MIMETypeUtil isText:self.contentType];
}
- (BOOL)isOversizeText
{
return [self.contentType isEqualToString:OWSMimeTypeOversizeTextMessage];

View File

@ -41,6 +41,7 @@ extern NSString *const kSyncMessageFileExtension;
+ (BOOL)isImage:(NSString *)contentType;
+ (BOOL)isVideo:(NSString *)contentType;
+ (BOOL)isAudio:(NSString *)contentType;
+ (BOOL)isText:(NSString *)contentType;
+ (BOOL)isVisualMedia:(NSString *)contentType;
// filename is optional and should not be trusted.

View File

@ -279,6 +279,17 @@ NSString *const kSyncMessageFileExtension = @"bin";
return [MIMETypeUtil isSupportedAudioMIMEType:contentType];
}
+ (BOOL)isText:(NSString *)contentType {
return [
@[
@"text/plain",
@"text/csv",
@"text/tab-separated-values"
]
containsObject:contentType
];
}
+ (BOOL)isVisualMedia:(NSString *)contentType
{
if ([self isImage:contentType]) {