diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 00430c187..823423680 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -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 diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h index 89f3b4aae..b9ab550f4 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.h @@ -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; diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m index e32418bdf..601eec0f9 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m +++ b/SessionMessagingKit/Sending & Receiving/Attachments/TSAttachment.m @@ -3,6 +3,14 @@ #import "TSAttachmentPointer.h" #import +#if TARGET_OS_IPHONE +#import + +#else +#import + +#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]; diff --git a/SessionUtilitiesKit/Media/MIMETypeUtil.h b/SessionUtilitiesKit/Media/MIMETypeUtil.h index cad42aef8..2093b5bf3 100644 --- a/SessionUtilitiesKit/Media/MIMETypeUtil.h +++ b/SessionUtilitiesKit/Media/MIMETypeUtil.h @@ -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. diff --git a/SessionUtilitiesKit/Media/MIMETypeUtil.m b/SessionUtilitiesKit/Media/MIMETypeUtil.m index c17e98c3a..fb4d15df4 100644 --- a/SessionUtilitiesKit/Media/MIMETypeUtil.m +++ b/SessionUtilitiesKit/Media/MIMETypeUtil.m @@ -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]) {