Skip to content

Commit

Permalink
Merge pull request #1760 from vector-im/riot_1759
Browse files Browse the repository at this point in the history
Share: The extension crashes if you try to share a GIF image (#1759)
  • Loading branch information
manuroe authored Feb 5, 2018
2 parents ebc1a08 + ba34f38 commit a07431d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
25 changes: 22 additions & 3 deletions RiotShareExtension/Model/ShareExtensionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ - (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)(NSError *error))f
UIAlertController *compressionPrompt = [self compressionPromptForImage:self.pendingImages.firstObject shareBlock:^{
[self sendImages:self.pendingImages withProviders:item.attachments toRoom:room extensionItem:item failureBlock:failureBlock];
}];

[self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt];

if (compressionPrompt)
{
[self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt];
}
}
}
}];
Expand Down Expand Up @@ -630,13 +633,29 @@ - (void)sendImages:(NSMutableArray *)imageDatas withProviders:(NSArray*)itemProv
}
else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG])
{
// Use jpeg format by default.
mimeType = @"image/jpeg";
if (convertedImage != image)
{
imageData = UIImageJPEGRepresentation(convertedImage, 0.9);
}
}
else
{
// Other image types like GIF
NSString *imageFileName = itemProvider.registeredTypeIdentifiers[0];
mimeType = (__bridge_transfer NSString *) UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)imageFileName, kUTTagClassMIMEType);
}

// Sanity check
if (!mimeType)
{
NSLog(@"[ShareExtensionManager] sendImage failed. Cannot determine MIME type of %@", itemProvider);
if (failureBlock)
{
failureBlock(nil);
}
return;
}

UIImage *thumbnail = nil;
// Thumbnail is useful only in case of encrypted room
Expand Down
26 changes: 16 additions & 10 deletions RiotShareExtension/ViewController/RoomsListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,30 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView

- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt
{
[compressionPrompt popoverPresentationController].sourceView = self.view;
[compressionPrompt popoverPresentationController].sourceRect = self.view.frame;
[self presentViewController:compressionPrompt animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[compressionPrompt popoverPresentationController].sourceView = self.view;
[compressionPrompt popoverPresentationController].sourceRect = self.view.frame;
[self presentViewController:compressionPrompt animated:YES completion:nil];
});
}

- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(MXRoom *)room
{
if (!self.hudView)
{
self.parentViewController.view.userInteractionEnabled = NO;
self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)];
[self.hudView setProgress:0.0];
}
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.hudView)
{
self.parentViewController.view.userInteractionEnabled = NO;
self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)];
[self.hudView setProgress:0.0];
}
});
}

- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress
{
[self.hudView setProgress:progress];
dispatch_async(dispatch_get_main_queue(), ^{
[self.hudView setProgress:progress];
});
}

@end

0 comments on commit a07431d

Please sign in to comment.