Skip to content

Commit

Permalink
Send files to IRCCloud even if the image service is set to imgur
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Feb 26, 2015
1 parent 01e9090 commit 5e1558c
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions ShareExtension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (void)presentationAnimationDidFinish {
#else
NSUserDefaults *d = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.irccloud.share"];
#endif
if([d boolForKey:@"uploadsAvailable"] && [[d objectForKey:@"imageService"] isEqualToString:@"IRCCloud"]) {
if([d boolForKey:@"uploadsAvailable"]) {
NSExtensionItem *input = self.extensionContext.inputItems.firstObject;
NSExtensionItem *output = [input copy];
output.attributedContentText = [[NSAttributedString alloc] initWithString:self.contentText attributes:nil];
Expand All @@ -46,30 +46,34 @@ - (void)presentationAnimationDidFinish {
i = output.attachments.firstObject;

NSItemProviderCompletionHandler imageHandler = ^(UIImage *item, NSError *error) {
NSLog(@"Uploading image to IRCCloud");
_item = item;
[_fileUploader uploadImage:item];
if(!_filename)
_filename = _fileUploader.originalFilename;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self reloadConfigurationItems];
[self validateContent];
}];
if([[d objectForKey:@"imageService"] isEqualToString:@"IRCCloud"]) {
NSLog(@"Uploading image to IRCCloud");
_item = item;
[_fileUploader uploadImage:item];
if(!_filename)
_filename = _fileUploader.originalFilename;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self reloadConfigurationItems];
[self validateContent];
}];
}
};

NSItemProviderCompletionHandler urlHandler = ^(NSURL *item, NSError *error) {
if([i hasItemConformingToTypeIdentifier:@"public.image"] && ![item.pathExtension.lowercaseString isEqualToString:@"gif"] && ![item.pathExtension.lowercaseString isEqualToString:@"png"]) {
_fileUploader.originalFilename = [[item pathComponents] lastObject];
[i loadItemForTypeIdentifier:@"public.image" options:nil completionHandler:imageHandler];
} else {
NSLog(@"Uploading file to IRCCloud");
[_fileUploader uploadFile:item];
if(!_filename)
_filename = _fileUploader.originalFilename;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self reloadConfigurationItems];
[self validateContent];
}];
if([[d objectForKey:@"imageService"] isEqualToString:@"IRCCloud"] || ![i hasItemConformingToTypeIdentifier:@"public.image"]) {
NSLog(@"Uploading file to IRCCloud");
[_fileUploader uploadFile:item];
if(!_filename)
_filename = _fileUploader.originalFilename;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self reloadConfigurationItems];
[self validateContent];
}];
}
}
};

Expand Down

0 comments on commit 5e1558c

Please sign in to comment.