From e48bf653470f5c8d4ccd5cdff17e8e5b9ff0b12a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 1 Jun 2017 12:46:00 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20=E2=80=9Ccan=E2=80=99t=20paste=20GIF=20fr?= =?UTF-8?q?om=20iMessage=E2=80=9D=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../ViewControllers/SignalAttachment.swift | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Signal/src/ViewControllers/SignalAttachment.swift b/Signal/src/ViewControllers/SignalAttachment.swift index 5adf7bb39..952c1ff9b 100644 --- a/Signal/src/ViewControllers/SignalAttachment.swift +++ b/Signal/src/ViewControllers/SignalAttachment.swift @@ -279,16 +279,6 @@ class SignalAttachment: NSObject { return MIMETypeUtil.supportedAudioUTITypes() } - public class var textUTISet: Set { - return [ - kUTTypeText as String, - kUTTypePlainText as String, - kUTTypeUTF8PlainText as String, - kUTTypeUTF16PlainText as String, - kUTTypeURL as String - ] - } - public var isImage: Bool { return SignalAttachment.outputImageUTISet.contains(dataUTI) } @@ -305,10 +295,6 @@ class SignalAttachment: NSObject { return SignalAttachment.audioUTISet.contains(dataUTI) } - public var isText: Bool { - return SignalAttachment.textUTISet.contains(dataUTI) - } - public class func pasteboardHasPossibleAttachment() -> Bool { return UIPasteboard.general.numberOfItems > 0 } @@ -323,12 +309,34 @@ class SignalAttachment: NSObject { } let pasteboardUTISet = Set(pasteboardUTITypes[0]) - let mediaUTISet = inputImageUTISet.union(animatedImageUTISet.union(videoUTISet.union(audioUTISet))) - if pasteboardUTISet.intersection(mediaUTISet).count > 0 { + // The pasteboard can be populated with multiple UTI types + // with different payloads. iMessage for example will copy + // an animated GIF to the pasteboard with the following UTI + // types: + // + // * "public.url-name" + // * "public.utf8-plain-text" + // * "com.compuserve.gif" + // + // We want to paste the animated GIF itself, not it's name. + // + // In general, our rule is to prefer non-text pasteboard + // contents, so we return true IFF there is a text UTI type + // and there is no non-text UTI type. + var hasTextUTIType = false + var hasNonTextUTIType = false + for utiType in pasteboardUTISet { + Logger.error("\(utiType) is text? \(UTTypeConformsTo(utiType as CFString, kUTTypeText))") + if UTTypeConformsTo(utiType as CFString, kUTTypeText) { + hasTextUTIType = true + } else { + hasNonTextUTIType = true + } + } + if hasNonTextUTIType { return false } - - return pasteboardUTISet.intersection(textUTISet).count > 0 + return hasTextUTIType } // Returns an attachment from the pasteboard, or nil if no attachment