mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.4 KiB
Matlab
114 lines
3.4 KiB
Matlab
8 years ago
|
//
|
||
7 years ago
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
8 years ago
|
//
|
||
|
|
||
|
#import "AttachmentSharing.h"
|
||
8 years ago
|
#import "UIUtil.h"
|
||
4 years ago
|
#import <SessionUtilitiesKit/AppContext.h>
|
||
4 years ago
|
#import <SessionMessagingKit/TSAttachmentStream.h>
|
||
8 years ago
|
|
||
7 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
8 years ago
|
@implementation AttachmentSharing
|
||
|
|
||
7 years ago
|
+ (void)showShareUIForAttachments:(NSArray<TSAttachmentStream *> *)attachmentStreams
|
||
|
completion:(nullable AttachmentSharingCompletion)completion
|
||
|
{
|
||
|
OWSAssertDebug(attachmentStreams.count > 0);
|
||
|
|
||
|
NSMutableArray<NSURL *> *urls = [NSMutableArray new];
|
||
|
for (TSAttachmentStream *attachmentStream in attachmentStreams) {
|
||
|
[urls addObject:attachmentStream.originalMediaURL];
|
||
|
}
|
||
|
|
||
|
[AttachmentSharing showShareUIForActivityItems:urls completion:completion];
|
||
|
}
|
||
|
|
||
7 years ago
|
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream
|
||
|
{
|
||
7 years ago
|
OWSAssertDebug(stream);
|
||
8 years ago
|
|
||
7 years ago
|
[self showShareUIForURL:stream.originalMediaURL];
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
+ (void)showShareUIForURL:(NSURL *)url
|
||
7 years ago
|
{
|
||
|
[self showShareUIForURL:url completion:nil];
|
||
|
}
|
||
|
|
||
|
+ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion
|
||
7 years ago
|
{
|
||
7 years ago
|
OWSAssertDebug(url);
|
||
7 years ago
|
|
||
5 years ago
|
[AttachmentSharing showShareUIForActivityItems:@[ url ]
|
||
7 years ago
|
completion:completion];
|
||
|
}
|
||
|
|
||
|
+ (void)showShareUIForURLs:(NSArray<NSURL *> *)urls completion:(nullable AttachmentSharingCompletion)completion
|
||
|
{
|
||
|
OWSAssertDebug(urls.count > 0);
|
||
|
|
||
|
[AttachmentSharing showShareUIForActivityItems:urls
|
||
7 years ago
|
completion:completion];
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
+ (void)showShareUIForText:(NSString *)text
|
||
7 years ago
|
{
|
||
|
[self showShareUIForText:text completion:nil];
|
||
|
}
|
||
|
|
||
|
+ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion
|
||
8 years ago
|
{
|
||
7 years ago
|
OWSAssertDebug(text);
|
||
7 years ago
|
|
||
5 years ago
|
[AttachmentSharing showShareUIForActivityItems:@[ text, ]
|
||
7 years ago
|
completion:completion];
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
#ifdef DEBUG
|
||
|
+ (void)showShareUIForUIImage:(UIImage *)image
|
||
|
{
|
||
7 years ago
|
OWSAssertDebug(image);
|
||
7 years ago
|
|
||
5 years ago
|
[AttachmentSharing showShareUIForActivityItems:@[ image, ]
|
||
7 years ago
|
completion:nil];
|
||
7 years ago
|
}
|
||
|
#endif
|
||
|
|
||
7 years ago
|
+ (void)showShareUIForActivityItems:(NSArray *)activityItems completion:(nullable AttachmentSharingCompletion)completion
|
||
8 years ago
|
{
|
||
7 years ago
|
OWSAssertDebug(activityItems);
|
||
8 years ago
|
|
||
|
DispatchMainThreadSafe(^{
|
||
|
UIActivityViewController *activityViewController =
|
||
|
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];
|
||
|
|
||
|
[activityViewController setCompletionWithItemsHandler:^(UIActivityType __nullable activityType,
|
||
|
BOOL completed,
|
||
|
NSArray *__nullable returnedItems,
|
||
|
NSError *__nullable activityError) {
|
||
8 years ago
|
|
||
8 years ago
|
if (activityError) {
|
||
7 years ago
|
OWSLogInfo(@"Failed to share with activityError: %@", activityError);
|
||
8 years ago
|
} else if (completed) {
|
||
7 years ago
|
OWSLogInfo(@"Did share with activityType: %@", activityType);
|
||
8 years ago
|
}
|
||
7 years ago
|
|
||
|
if (completion) {
|
||
|
DispatchMainThreadSafe(completion);
|
||
|
}
|
||
8 years ago
|
}];
|
||
8 years ago
|
|
||
7 years ago
|
UIViewController *fromViewController = CurrentAppContext().frontmostViewController;
|
||
8 years ago
|
while (fromViewController.presentedViewController) {
|
||
|
fromViewController = fromViewController.presentedViewController;
|
||
8 years ago
|
}
|
||
7 years ago
|
OWSAssertDebug(fromViewController);
|
||
7 years ago
|
[fromViewController presentViewController:activityViewController animated:YES completion:nil];
|
||
8 years ago
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
@end
|
||
7 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|