From 6a7f06f940a1ebc85fe1bb3f7e9b552b24bad527 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 25 Jan 2018 13:53:39 -0500 Subject: [PATCH] Respond to CR. --- SignalMessaging/Views/OWSFlatButton.swift | 12 ++++++------ .../MessageApprovalViewController.swift | 5 +---- .../SharingThreadPickerViewController.m | 11 ++++++++++- SignalMessaging/categories/UIFont+OWS.h | 6 +++++- SignalMessaging/categories/UIFont+OWS.m | 6 +++++- SignalShareExtension/ShareViewController.swift | 14 +++++++------- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/SignalMessaging/Views/OWSFlatButton.swift b/SignalMessaging/Views/OWSFlatButton.swift index 76b6143cf..a79452856 100644 --- a/SignalMessaging/Views/OWSFlatButton.swift +++ b/SignalMessaging/Views/OWSFlatButton.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // import Foundation @@ -51,7 +51,7 @@ public class OWSFlatButton: UIView { backgroundColor: UIColor, width: CGFloat, height: CGFloat, - target:Any, + target: Any, selector: Selector) -> OWSFlatButton { let button = OWSFlatButton() button.setTitle(title:title, @@ -70,7 +70,7 @@ public class OWSFlatButton: UIView { backgroundColor: UIColor, width: CGFloat, height: CGFloat, - target:Any, + target: Any, selector: Selector) -> OWSFlatButton { return OWSFlatButton.button(title:title, font:fontForHeight(height), @@ -87,7 +87,7 @@ public class OWSFlatButton: UIView { font: UIFont, titleColor: UIColor, backgroundColor: UIColor, - target:Any, + target: Any, selector: Selector) -> OWSFlatButton { let button = OWSFlatButton() button.setTitle(title:title, @@ -104,7 +104,7 @@ public class OWSFlatButton: UIView { // Cap the "button height" at 40pt or button text can look // excessively large. let fontPointSize = round(min(40, height) * 0.45) - return UIFont.ows_mediumFont(withSize:fontPointSize)! + return UIFont.ows_mediumFont(withSize:fontPointSize) } // MARK: Methods @@ -150,7 +150,7 @@ public class OWSFlatButton: UIView { } @objc - public func addTarget(target:Any, + public func addTarget(target: Any, selector: Selector) { button.addTarget(target, action:selector, for:.touchUpInside) } diff --git a/SignalMessaging/attachments/MessageApprovalViewController.swift b/SignalMessaging/attachments/MessageApprovalViewController.swift index f2c7dd71f..cf63f9934 100644 --- a/SignalMessaging/attachments/MessageApprovalViewController.swift +++ b/SignalMessaging/attachments/MessageApprovalViewController.swift @@ -131,10 +131,7 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat bottomBorder.autoPinBottomToSuperview() bottomBorder.autoSetDimension(.height, toSize: borderThickness) - guard let font = UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(14.0, 18.0)) else { - owsFail("Can't load font") - return recipientRow - } + let font = UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(14.0, 18.0)) let hSpacing = CGFloat(10) let hMargin = CGFloat(15) let vSpacing = CGFloat(5) diff --git a/SignalMessaging/attachments/SharingThreadPickerViewController.m b/SignalMessaging/attachments/SharingThreadPickerViewController.m index 7f3a71bd8..2ea07b5fc 100644 --- a/SignalMessaging/attachments/SharingThreadPickerViewController.m +++ b/SignalMessaging/attachments/SharingThreadPickerViewController.m @@ -183,6 +183,8 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); { [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread]; [self tryToSendMessageWithBlock:^(SendCompletionBlock sendCompletion) { + OWSAssertIsOnMainThread(); + __block TSOutgoingMessage *outgoingMessage = nil; outgoingMessage = [ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread @@ -190,6 +192,9 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); completion:^(NSError *_Nullable error) { sendCompletion(error, outgoingMessage); }]; + + // This is necessary to show progress. + self.outgoingMessage = outgoingMessage; } fromViewController:approvalViewController]; } @@ -209,6 +214,8 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread]; [self tryToSendMessageWithBlock:^(SendCompletionBlock sendCompletion) { + OWSAssertIsOnMainThread(); + __block TSOutgoingMessage *outgoingMessage = nil; outgoingMessage = [ThreadUtil sendMessageWithText:messageText inThread:self.thread @@ -219,6 +226,9 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); failure:^(NSError *_Nonnull error) { sendCompletion(error, outgoingMessage); }]; + + // This is necessary to show progress. + self.outgoingMessage = outgoingMessage; } fromViewController:approvalViewController]; } @@ -229,7 +239,6 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); } #pragma mark - Helpers -typedef void (^SendMessageBlock)(SendCompletionBlock completion); - (void)tryToSendMessageWithBlock:(SendMessageBlock)sendMessageBlock fromViewController:(UIViewController *)fromViewController diff --git a/SignalMessaging/categories/UIFont+OWS.h b/SignalMessaging/categories/UIFont+OWS.h index 5eb182256..b98c8004b 100644 --- a/SignalMessaging/categories/UIFont+OWS.h +++ b/SignalMessaging/categories/UIFont+OWS.h @@ -1,9 +1,11 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import +NS_ASSUME_NONNULL_BEGIN + @interface UIFont (OWS) + (UIFont *)ows_thinFontWithSize:(CGFloat)size; @@ -31,3 +33,5 @@ + (UIFont *)ows_footnoteFont; @end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/categories/UIFont+OWS.m b/SignalMessaging/categories/UIFont+OWS.m index 861552b96..5ee3a934d 100644 --- a/SignalMessaging/categories/UIFont+OWS.m +++ b/SignalMessaging/categories/UIFont+OWS.m @@ -1,9 +1,11 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "UIFont+OWS.h" +NS_ASSUME_NONNULL_BEGIN + @implementation UIFont (OWS) + (UIFont *)ows_thinFontWithSize:(CGFloat)size @@ -105,3 +107,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 48eaea8ba..6df732fba 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -540,7 +540,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE } Logger.debug("\(logTag) matched utiType: \(srcUtiType)") - let (promise, fulfill, reject) = Promise<(URL, String)>.pending() + let (promise, fulfill, reject) = Promise<(itemUrl: URL, utiType: String)>.pending() var customFileName: String? var isConvertibleToTextMessage = false @@ -576,7 +576,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE return } let fileUrl = URL(fileURLWithPath:tempFilePath) - fulfill((fileUrl, srcUtiType)) + fulfill((itemUrl: fileUrl, utiType: srcUtiType)) } else if let string = value as? String { Logger.debug("\(self.logTag) string provider: \(string)") guard let data = string.data(using: String.Encoding.utf8) else { @@ -595,18 +595,18 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE isConvertibleToTextMessage = !itemProvider.registeredTypeIdentifiers.contains(kUTTypeFileURL as String) if UTTypeConformsTo(srcUtiType as CFString, kUTTypeText) { - fulfill((fileUrl, srcUtiType)) + fulfill((itemUrl: fileUrl, utiType: srcUtiType)) } else { - fulfill((fileUrl, kUTTypeText as String)) + fulfill((itemUrl: fileUrl, utiType: kUTTypeText as String)) } } else if let url = value as? URL { // If the share itself is a URL (e.g. a link from Safari), try to send this as a text message. isConvertibleToTextMessage = (itemProvider.registeredTypeIdentifiers.contains(kUTTypeURL as String) && !itemProvider.registeredTypeIdentifiers.contains(kUTTypeFileURL as String)) if isConvertibleToTextMessage { - fulfill((url, kUTTypeURL as String)) + fulfill((itemUrl: url, utiType: kUTTypeURL as String)) } else { - fulfill((url, srcUtiType)) + fulfill((itemUrl: url, utiType: srcUtiType)) } } else { // It's unavoidable that we may sometimes receives data types that we @@ -633,7 +633,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE Logger.debug("\(self.logTag) building DataSource with url: \(url), utiType: \(utiType)") - guard let dataSource = ShareViewController.createDataSource(utiType : utiType, url : url, customFileName : customFileName) else { + guard let dataSource = ShareViewController.createDataSource(utiType: utiType, url: url, customFileName: customFileName) else { throw ShareViewControllerError.assertionError(description: "Unable to read attachment data") }