diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 0019973ad3..cecfe2c64b 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -34,7 +34,6 @@ 340CCB712305962B005243B3 /* YDBToGRDBMigrationKeyValueTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340CCB6F2305962A005243B3 /* YDBToGRDBMigrationKeyValueTest.swift */; }; 340CCB722305962B005243B3 /* YDBToGRDBMigrationModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340CCB702305962B005243B3 /* YDBToGRDBMigrationModelTest.swift */; }; 340E9AC0235F876800FA362C /* ForwardMessageNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340E9ABF235F876800FA362C /* ForwardMessageNavigationController.swift */; }; - 340E9AC2235F878900FA362C /* TextApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340E9AC1235F878800FA362C /* TextApprovalViewController.swift */; }; 340E9AC4236095CD00FA362C /* AttachmentMultisend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340E9AC3236095CC00FA362C /* AttachmentMultisend.swift */; }; 340FC8A9204DAC8D007AEB0F /* NotificationSettingsOptionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC87B204DAC8C007AEB0F /* NotificationSettingsOptionsViewController.m */; }; 340FC8AA204DAC8D007AEB0F /* NotificationSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC87C204DAC8C007AEB0F /* NotificationSettingsViewController.m */; }; @@ -160,6 +159,7 @@ 346B4A79236A138C00B56007 /* OWS116UpdatePrekeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B4A78236A138C00B56007 /* OWS116UpdatePrekeys.swift */; }; 346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; }; 346E9D5421B040B700562252 /* RegistrationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346E9D5321B040B600562252 /* RegistrationController.swift */; }; + 3470249C238367EA0078D72C /* TextApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3470249B238367E90078D72C /* TextApprovalViewController.swift */; }; 347137FC22A1BCE800F43A63 /* OWSMessageViewOnceView.m in Sources */ = {isa = PBXBuildFile; fileRef = 347137FB22A1BCE800F43A63 /* OWSMessageViewOnceView.m */; }; 347850311FD7494A007B8332 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; }; 347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.ttf */; }; @@ -212,7 +212,6 @@ 34AC09E3211B39B100997B47 /* OWSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09C5211B39AF00997B47 /* OWSViewController.m */; }; 34AC09E4211B39B100997B47 /* ScreenLockViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 34AC09C6211B39AF00997B47 /* ScreenLockViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34AC09E5211B39B100997B47 /* ScreenLockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09C7211B39AF00997B47 /* ScreenLockViewController.m */; }; - 34AC09E7211B39B100997B47 /* MessageApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09C9211B39AF00997B47 /* MessageApprovalViewController.swift */; }; 34AC09E9211B39B100997B47 /* OWSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09CB211B39AF00997B47 /* OWSTableViewController.m */; }; 34AC09EA211B39B100997B47 /* ModalActivityIndicatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09CC211B39B000997B47 /* ModalActivityIndicatorViewController.swift */; }; 34AC09EB211B39B100997B47 /* ContactShareApprovalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34AC09CD211B39B000997B47 /* ContactShareApprovalViewController.swift */; }; @@ -772,7 +771,6 @@ 340CCB6F2305962A005243B3 /* YDBToGRDBMigrationKeyValueTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YDBToGRDBMigrationKeyValueTest.swift; sourceTree = ""; }; 340CCB702305962B005243B3 /* YDBToGRDBMigrationModelTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YDBToGRDBMigrationModelTest.swift; sourceTree = ""; }; 340E9ABF235F876800FA362C /* ForwardMessageNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForwardMessageNavigationController.swift; sourceTree = ""; }; - 340E9AC1235F878800FA362C /* TextApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextApprovalViewController.swift; sourceTree = ""; }; 340E9AC3236095CC00FA362C /* AttachmentMultisend.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentMultisend.swift; sourceTree = ""; }; 340FC87B204DAC8C007AEB0F /* NotificationSettingsOptionsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotificationSettingsOptionsViewController.m; sourceTree = ""; }; 340FC87C204DAC8C007AEB0F /* NotificationSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotificationSettingsViewController.m; sourceTree = ""; }; @@ -943,6 +941,7 @@ 346B4A78236A138C00B56007 /* OWS116UpdatePrekeys.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWS116UpdatePrekeys.swift; sourceTree = ""; }; 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = ""; }; 346E9D5321B040B600562252 /* RegistrationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegistrationController.swift; sourceTree = ""; }; + 3470249B238367E90078D72C /* TextApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextApprovalViewController.swift; sourceTree = ""; }; 347137FA22A1BCE800F43A63 /* OWSMessageViewOnceView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageViewOnceView.h; sourceTree = ""; }; 347137FB22A1BCE800F43A63 /* OWSMessageViewOnceView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageViewOnceView.m; sourceTree = ""; }; 34784592237C4813000D1CAA /* hi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hi; path = translations/hi.lproj/Localizable.strings; sourceTree = ""; }; @@ -1006,7 +1005,6 @@ 34AC09C5211B39AF00997B47 /* OWSViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSViewController.m; sourceTree = ""; }; 34AC09C6211B39AF00997B47 /* ScreenLockViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenLockViewController.h; sourceTree = ""; }; 34AC09C7211B39AF00997B47 /* ScreenLockViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScreenLockViewController.m; sourceTree = ""; }; - 34AC09C9211B39AF00997B47 /* MessageApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageApprovalViewController.swift; sourceTree = ""; }; 34AC09CB211B39AF00997B47 /* OWSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSTableViewController.m; sourceTree = ""; }; 34AC09CC211B39B000997B47 /* ModalActivityIndicatorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModalActivityIndicatorViewController.swift; sourceTree = ""; }; 34AC09CD211B39B000997B47 /* ContactShareApprovalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactShareApprovalViewController.swift; sourceTree = ""; }; @@ -2171,7 +2169,6 @@ 8835DDFB230CEE7600DC6B66 /* RecipientPicker */, 340FC875204DAC8C007AEB0F /* Registration */, 4585C4671ED8F8D200896AEA /* SafetyNumberConfirmationAlert.swift */, - 340E9AC1235F878800FA362C /* TextApprovalViewController.swift */, 340FC897204DAC8D007AEB0F /* ThreadSettings */, 88F7EE92230253C5003ADF7D /* UsernameViewController.swift */, 34D1F0BE1F8EC1760066283D /* Utils */, @@ -2405,7 +2402,6 @@ 34AC09D0211B39B000997B47 /* EditContactShareNameViewController.swift */, 8835DE06230DFFC500DC6B66 /* FindByPhoneNumberViewController.swift */, 34AC09D9211B39B100997B47 /* MediaMessageView.swift */, - 34AC09C9211B39AF00997B47 /* MessageApprovalViewController.swift */, 34AC09CC211B39B000997B47 /* ModalActivityIndicatorViewController.swift */, 34AC09C0211B39AE00997B47 /* OWSNavigationController.h */, 34AC09C1211B39AF00997B47 /* OWSNavigationController.m */, @@ -2423,6 +2419,7 @@ 34AC09DC211B39B100997B47 /* SharingThreadPickerViewController.m */, 4C23A5F1215C4ADE00534937 /* SheetViewController.swift */, 344DC9AD226E483C004E7322 /* Stickers */, + 3470249B238367E90078D72C /* TextApprovalViewController.swift */, 4C38E4FE230374D700E464B9 /* UIViewController+Permissions.h */, 4C38E4FF230374D700E464B9 /* UIViewController+Permissions.m */, 34AC09BF211B39AE00997B47 /* ViewControllerUtils.h */, @@ -3952,6 +3949,7 @@ 346129AD1FD1F34E00532771 /* ImageCache.swift in Sources */, 34D5872F208E2C4200D2255A /* OWS109OutgoingMessageState.m in Sources */, 340872D02239787F00CB25B0 /* AttachmentTextToolbar.swift in Sources */, + 3470249C238367EA0078D72C /* TextApprovalViewController.swift in Sources */, 3416BCAE2277A24000E761B4 /* StickerPackDataSource.swift in Sources */, 34AC09F8211B39B100997B47 /* CountryCodeViewController.m in Sources */, 451F8A341FD710C3005CB9DA /* FullTextSearcher.swift in Sources */, @@ -4026,7 +4024,6 @@ 451F8A471FD715BA005CB9DA /* OWSAvatarBuilder.m in Sources */, 349ED992221EE80D008045B0 /* AppPreferences.swift in Sources */, 4C9C50FE22F36FA50054A33F /* OutboundMessage+OWS.swift in Sources */, - 34AC09E7211B39B100997B47 /* MessageApprovalViewController.swift in Sources */, 34480B591FD0A7A400BC14EF /* OWSScrubbingLogFormatter.m in Sources */, 342BF24D227A03F8005CEAA9 /* StickerHorizontalListView.swift in Sources */, 451F8A441FD7156B005CB9DA /* BlockListUIUtils.m in Sources */, @@ -4223,7 +4220,6 @@ 34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */, 45F32C222057297A00A300D5 /* MediaDetailViewController.m in Sources */, 34B3F8851E8DF1700035BE1A /* NewGroupViewController.m in Sources */, - 340E9AC2235F878900FA362C /* TextApprovalViewController.swift in Sources */, 34ABC0E421DD20C500ED9469 /* ConversationMessageMapping.swift in Sources */, 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */, 880BFFEA234590FA00F6FAB1 /* ConversationSplitViewController.swift in Sources */, diff --git a/SignalMessaging/ViewControllers/MessageApprovalViewController.swift b/SignalMessaging/ViewControllers/MessageApprovalViewController.swift deleted file mode 100644 index d5d2943666..0000000000 --- a/SignalMessaging/ViewControllers/MessageApprovalViewController.swift +++ /dev/null @@ -1,181 +0,0 @@ -// -// Copyright (c) 2019 Open Whisper Systems. All rights reserved. -// - -import Foundation - -@objc -public protocol MessageApprovalViewControllerDelegate: class { - func messageApproval(_ messageApproval: MessageApprovalViewController, didApproveMessage messageText: String) - func messageApprovalDidCancel(_ messageApproval: MessageApprovalViewController) -} - -@objc -public class MessageApprovalViewController: OWSViewController, UITextViewDelegate { - - weak var delegate: MessageApprovalViewControllerDelegate? - - // MARK: Properties - - let thread: TSThread - let initialMessageText: String - let contactsManager: OWSContactsManager - - private(set) var textView: UITextView! - private var sendButton: UIBarButtonItem! - - // MARK: Initializers - - @available(*, unavailable, message:"use attachment: constructor instead.") - required public init?(coder aDecoder: NSCoder) { - notImplemented() - } - - @objc - required public init(messageText: String, thread: TSThread, contactsManager: OWSContactsManager, delegate: MessageApprovalViewControllerDelegate) { - self.initialMessageText = messageText - self.thread = thread - self.contactsManager = contactsManager - self.delegate = delegate - - super.init(nibName: nil, bundle: nil) - } - - // MARK: View Lifecycle - - override public func viewDidLoad() { - super.viewDidLoad() - - self.navigationItem.title = NSLocalizedString("MESSAGE_APPROVAL_DIALOG_TITLE", - comment: "Title for the 'message approval' dialog.") - - self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(cancelPressed)) - sendButton = UIBarButtonItem(title: MessageStrings.sendButton, - style: .plain, - target: self, - action: #selector(sendPressed)) - self.navigationItem.rightBarButtonItem = sendButton - } - - private func updateSendButton() { - sendButton.isEnabled = textView.text.count > 0 - } - - override public func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - updateSendButton() - } - - // MARK: - Create Views - - public override func loadView() { - - self.view = UIView.container() - self.view.backgroundColor = Theme.backgroundColor - - // Recipient Row - let recipientRow = createRecipientRow() - view.addSubview(recipientRow) - recipientRow.autoPinEdge(toSuperviewSafeArea: .leading) - recipientRow.autoPinEdge(toSuperviewSafeArea: .trailing) - recipientRow.autoPin(toTopLayoutGuideOf: self, withInset: 0) - - // Text View - textView = OWSTextView() - textView.delegate = self - textView.backgroundColor = Theme.backgroundColor - textView.textColor = Theme.primaryTextColor - textView.font = UIFont.ows_dynamicTypeBody - textView.text = self.initialMessageText - textView.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) - textView.textContainerInset = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0) - view.addSubview(textView) - textView.autoPinEdge(toSuperviewSafeArea: .leading) - textView.autoPinEdge(toSuperviewSafeArea: .trailing) - textView.autoPinEdge(.top, to: .bottom, of: recipientRow) - textView.autoPin(toBottomLayoutGuideOf: self, withInset: 0) - } - - private func createRecipientRow() -> UIView { - let recipientRow = UIView.container() - recipientRow.backgroundColor = Theme.toolbarBackgroundColor - - // Hairline borders should be 1 pixel, not 1 point. - let borderThickness = 1.0 / UIScreen.main.scale - let borderColor = Theme.middleGrayColor - - let topBorder = UIView.container() - topBorder.backgroundColor = borderColor - recipientRow.addSubview(topBorder) - topBorder.autoPinWidthToSuperview() - topBorder.autoPinTopToSuperviewMargin() - topBorder.autoSetDimension(.height, toSize: borderThickness) - - let bottomBorder = UIView.container() - bottomBorder.backgroundColor = borderColor - recipientRow.addSubview(bottomBorder) - bottomBorder.autoPinWidthToSuperview() - bottomBorder.autoPinBottomToSuperviewMargin() - bottomBorder.autoSetDimension(.height, toSize: borderThickness) - - let font = UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(14.0, 18.0)) - let hSpacing = CGFloat(10) - let hMargin = CGFloat(15) - let vMargin = CGFloat(10) - - let toLabel = UILabel() - toLabel.text = NSLocalizedString("MESSAGE_APPROVAL_RECIPIENT_LABEL", - comment: "Label for the recipient name in the 'message approval' dialog.") - toLabel.textColor = Theme.secondaryTextAndIconColor - toLabel.font = font - recipientRow.addSubview(toLabel) - - let nameLabel = UILabel() - nameLabel.textColor = Theme.primaryTextColor - nameLabel.font = font - nameLabel.lineBreakMode = .byTruncatingTail - recipientRow.addSubview(nameLabel) - - toLabel.autoPinLeadingToSuperviewMargin(withInset: hMargin) - toLabel.setContentHuggingHorizontalHigh() - toLabel.setCompressionResistanceHorizontalHigh() - toLabel.autoAlignAxis(.horizontal, toSameAxisOf: nameLabel) - - nameLabel.autoPinLeading(toTrailingEdgeOf: toLabel, offset: hSpacing) - nameLabel.autoPinTrailingToSuperviewMargin(withInset: hMargin) - nameLabel.setContentHuggingHorizontalLow() - nameLabel.setCompressionResistanceHorizontalLow() - nameLabel.autoPinTopToSuperviewMargin(withInset: vMargin) - nameLabel.autoPinBottomToSuperviewMargin(withInset: vMargin) - - if let groupThread = self.thread as? TSGroupThread { - nameLabel.text = groupThread.groupNameOrDefault - return recipientRow - } - guard let contactThread = self.thread as? TSContactThread else { - owsFailDebug("Unexpected thread type") - return recipientRow - } - - nameLabel.text = contactsManager.displayName(for: contactThread.contactAddress) - - return recipientRow - } - - // MARK: - Event Handlers - - @objc func cancelPressed(sender: UIButton) { - delegate?.messageApprovalDidCancel(self) - } - - @objc func sendPressed(sender: UIButton) { - delegate?.messageApproval(self, didApproveMessage: self.textView.text) - } - - // MARK: - UITextViewDelegate - - public func textViewDidChange(_ textView: UITextView) { - updateSendButton() - } -} diff --git a/SignalMessaging/ViewControllers/SharingThreadPickerViewController.m b/SignalMessaging/ViewControllers/SharingThreadPickerViewController.m index 1bc4127886..2f52b0fb2f 100644 --- a/SignalMessaging/ViewControllers/SharingThreadPickerViewController.m +++ b/SignalMessaging/ViewControllers/SharingThreadPickerViewController.m @@ -21,7 +21,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); @interface SharingThreadPickerViewController () @property (nonatomic, readonly) OWSContactsManager *contactsManager; @@ -164,11 +164,8 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); return NO; } - MessageApprovalViewController *approvalVC = - [[MessageApprovalViewController alloc] initWithMessageText:messageText - thread:self.thread - contactsManager:self.contactsManager - delegate:self]; + TextApprovalViewController *approvalVC = [[TextApprovalViewController alloc] initWithMessageText:messageText]; + approvalVC.delegate = self; [self.navigationController pushViewController:approvalVC animated:YES]; return YES; @@ -297,10 +294,9 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); return nil; } -#pragma mark - MessageApprovalViewControllerDelegate +#pragma mark - TextApprovalViewControllerDelegate -- (void)messageApproval:(MessageApprovalViewController *)approvalViewController - didApproveMessage:(NSString *)messageText +- (void)textApproval:(TextApprovalViewController *)approvalViewController didApproveMessage:(NSString *)messageText { OWSAssertDebug(messageText.length > 0); @@ -332,11 +328,30 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion); fromViewController:approvalViewController]; } -- (void)messageApprovalDidCancel:(MessageApprovalViewController *)approvalViewController +- (void)textApprovalDidCancel:(TextApprovalViewController *)approvalViewController { [self cancelShareExperience]; } +- (nullable NSString *)textApprovalCustomTitle:(TextApprovalViewController *)approvalViewController +{ + return NSLocalizedString(@"MESSAGE_APPROVAL_DIALOG_TITLE", @"Title for the 'message approval' dialog."); +} + +- (nullable NSString *)textApprovalRecipientsDescription:(TextApprovalViewController *)approvalViewController +{ + __block NSString *result; + [self.databaseStorage uiReadWithBlock:^(SDSAnyReadTransaction *transaction) { + result = [self.contactsManager displayNameForThread:self.thread transaction:transaction]; + }]; + return result; +} + +- (ApprovalMode)textApprovalMode:(TextApprovalViewController *)approvalViewController +{ + return ApprovalModeSend; +} + #pragma mark - ContactShareApprovalViewControllerDelegate - (void)approveContactShare:(ContactShareApprovalViewController *)approvalViewController diff --git a/Signal/src/ViewControllers/TextApprovalViewController.swift b/SignalMessaging/ViewControllers/TextApprovalViewController.swift similarity index 97% rename from Signal/src/ViewControllers/TextApprovalViewController.swift rename to SignalMessaging/ViewControllers/TextApprovalViewController.swift index 635624f4a9..ec74568400 100644 --- a/Signal/src/ViewControllers/TextApprovalViewController.swift +++ b/SignalMessaging/ViewControllers/TextApprovalViewController.swift @@ -22,11 +22,12 @@ public protocol TextApprovalViewControllerDelegate: class { @objc public class TextApprovalViewController: OWSViewController, UITextViewDelegate { - weak var delegate: TextApprovalViewControllerDelegate? + @objc + public weak var delegate: TextApprovalViewControllerDelegate? // MARK: - Properties - let initialMessageText: String + private let initialMessageText: String private(set) var textView: UITextView! private let footerView = ApprovalFooterView()