Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Don't query pasteboard contents until paste:
Browse files Browse the repository at this point in the history
  • Loading branch information
Adlai-Holler committed Jan 24, 2021
1 parent acd82b4 commit b9c086f
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions MatrixKit/Views/RoomInputToolbar/MXKRoomInputToolbarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1336,29 +1336,26 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
// Check whether some data listed in general pasteboard can be paste
UIPasteboard *pasteboard = MXKPasteboardManager.shared.pasteboard;
if (pasteboard.numberOfItems)
NSIndexSet* all = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, pasteboard.numberOfItems)];
for (NSArray<NSString*>* typesForItem in [pasteboard pasteboardTypesForItemSet:all])
{
for (NSDictionary* dict in pasteboard.items)
for (NSString* type in typesForItem)
{
NSArray* allKeys = dict.allKeys;
for (NSString* key in allKeys)
NSString* MIMEType = (__bridge_transfer NSString *) UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)type, kUTTagClassMIMEType);

if ([MIMEType hasPrefix:@"image/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendImage:)])
{
NSString* MIMEType = (__bridge_transfer NSString *) UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)key, kUTTagClassMIMEType);

if ([MIMEType hasPrefix:@"image/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendImage:)])
{
return YES;
}

if ([MIMEType hasPrefix:@"video/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendVideo:withThumbnail:)])
{
return YES;
}

if ([MIMEType hasPrefix:@"application/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendFile:withMimeType:)])
{
return YES;
}
return YES;
}

if ([MIMEType hasPrefix:@"video/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendVideo:withThumbnail:)])
{
return YES;
}

if ([MIMEType hasPrefix:@"application/"] && [self.delegate respondsToSelector:@selector(roomInputToolbarView:sendFile:withMimeType:)])
{
return YES;
}
}
}
Expand Down

0 comments on commit b9c086f

Please sign in to comment.