From 4834a85fb5d90eab39587cab7fa674e98d488883 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 2 Mar 2018 14:29:53 -0500 Subject: [PATCH] Add share option for debug logs. --- Signal/src/util/Pastelog.m | 11 ++++++- .../translations/en.lproj/Localizable.strings | 3 ++ .../attachments/AttachmentSharing.h | 10 +++++++ .../attachments/AttachmentSharing.m | 29 ++++++++++++++++--- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Signal/src/util/Pastelog.m b/Signal/src/util/Pastelog.m index f5322086a..17dda81a0 100644 --- a/Signal/src/util/Pastelog.m +++ b/Signal/src/util/Pastelog.m @@ -8,6 +8,7 @@ #import "zlib.h" #import #import +#import #import #import #import @@ -326,10 +327,18 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_BUG_REPORT", @"Label for the 'Open a Bug Report' option of the the debug log alert.") - style:UIAlertActionStyleCancel + style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [Pastelog.sharedManager prepareRedirection:url completion:completion]; }]]; + [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"DEBUG_LOG_ALERT_OPTION_SHARE", + @"Label for the 'Share' option of the the debug log alert.") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + [AttachmentSharing showShareUIForText:url.absoluteString + completion:completion]; + }]]; + [alert addAction:[OWSAlerts cancelAction]]; UIViewController *presentingViewController = UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts; [presentingViewController presentViewController:alert animated:NO completion:nil]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 9a973d039..7bc110c58 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -529,6 +529,9 @@ /* Label for the 'send to self' option of the the debug log alert. */ "DEBUG_LOG_ALERT_OPTION_SEND_TO_SELF" = "Send to Self"; +/* Label for the 'Share' option of the the debug log alert. */ +"DEBUG_LOG_ALERT_OPTION_SHARE" = "Share"; + /* Title of the alert shown for failures while uploading debug logs. Title of the debug log alert. */ "DEBUG_LOG_ALERT_TITLE" = "One More Step"; diff --git a/SignalMessaging/attachments/AttachmentSharing.h b/SignalMessaging/attachments/AttachmentSharing.h index 66bf2b833..712c77157 100644 --- a/SignalMessaging/attachments/AttachmentSharing.h +++ b/SignalMessaging/attachments/AttachmentSharing.h @@ -2,18 +2,28 @@ // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // +NS_ASSUME_NONNULL_BEGIN + @class TSAttachmentStream; +typedef void (^AttachmentSharingCompletion)(void); + @interface AttachmentSharing : NSObject + (void)showShareUIForAttachment:(TSAttachmentStream *)stream; + (void)showShareUIForURL:(NSURL *)url; ++ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion; + + (void)showShareUIForText:(NSString *)text; ++ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion; + #ifdef DEBUG + (void)showShareUIForUIImage:(UIImage *)image; #endif @end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/attachments/AttachmentSharing.m b/SignalMessaging/attachments/AttachmentSharing.m index 7508a3645..c648ccd18 100644 --- a/SignalMessaging/attachments/AttachmentSharing.m +++ b/SignalMessaging/attachments/AttachmentSharing.m @@ -8,6 +8,8 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @implementation AttachmentSharing + (void)showShareUIForAttachment:(TSAttachmentStream *)stream @@ -18,21 +20,33 @@ } + (void)showShareUIForURL:(NSURL *)url +{ + [self showShareUIForURL:url completion:nil]; +} + ++ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion { OWSAssert(url); [AttachmentSharing showShareUIForActivityItems:@[ url, - ]]; + ] + completion:completion]; } + (void)showShareUIForText:(NSString *)text +{ + [self showShareUIForText:text completion:nil]; +} + ++ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion { OWSAssert(text); [AttachmentSharing showShareUIForActivityItems:@[ text, - ]]; + ] + completion:completion]; } #ifdef DEBUG @@ -42,11 +56,12 @@ [AttachmentSharing showShareUIForActivityItems:@[ image, - ]]; + ] + completion:nil]; } #endif -+ (void)showShareUIForActivityItems:(NSArray *)activityItems ++ (void)showShareUIForActivityItems:(NSArray *)activityItems completion:(nullable AttachmentSharingCompletion)completion { OWSAssert(activityItems); @@ -67,6 +82,10 @@ } else if (completed) { DDLogInfo(@"%@ Did share with activityType: %@", self.logTag, activityType); } + + if (completion) { + DispatchMainThreadSafe(completion); + } }]; UIViewController *fromViewController = CurrentAppContext().frontmostViewController; @@ -84,3 +103,5 @@ } @end + +NS_ASSUME_NONNULL_END