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
		
	
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#import "AttachmentSharing.h"
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								#import "UIUtil.h"
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								#import <SessionUtilitiesKit/AppContext.h>
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								#import <SessionMessagingKit/TSAttachmentStream.h>
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								NS_ASSUME_NONNULL_BEGIN
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											9 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];
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    OWSAssertDebug(stream);
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    [self showShareUIForURL:stream.originalMediaURL];
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								+ (void)showShareUIForURL:(NSURL *)url
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 | 
							
								    [self showShareUIForURL:url completion:nil];
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								+ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion
							 | 
						||
| 
								 
											8 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
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								                                        completion:completion];
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								+ (void)showShareUIForText:(NSString *)text
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 | 
							
								    [self showShareUIForText:text completion:nil];
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								+ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    OWSAssertDebug(text);
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    [AttachmentSharing showShareUIForActivityItems:@[ text, ]
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								                                        completion:completion];
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								#ifdef DEBUG
							 | 
						||
| 
								 | 
							
								+ (void)showShareUIForUIImage:(UIImage *)image
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    OWSAssertDebug(image);
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    [AttachmentSharing showShareUIForActivityItems:@[ image, ]
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								                                        completion:nil];
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											8 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) {
							 | 
						||
| 
								 
											9 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
										 
									 | 
							
								            }
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								            if (completion) {
							 | 
						||
| 
								 | 
							
								                DispatchMainThreadSafe(completion);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        }];
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        UIViewController *fromViewController = CurrentAppContext().frontmostViewController;
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								        while (fromViewController.presentedViewController) {
							 | 
						||
| 
								 | 
							
								            fromViewController = fromViewController.presentedViewController;
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								        }
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        OWSAssertDebug(fromViewController);
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        [fromViewController presentViewController:activityViewController animated:YES completion:nil];
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								    });
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											9 years ago
										 
									 | 
							
								@end
							 | 
						||
| 
								 
											8 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								NS_ASSUME_NONNULL_END
							 |