diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index a9c36920c..97a849f8d 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -478,6 +478,12 @@ /* Title for the 'edit contact share name' view. */ "CONTACT_SHARE_EDIT_NAME_VIEW_TITLE" = "Edit Name"; +/* Error indicating that an invalid contact cannot be shared. */ +"CONTACT_SHARE_INVALID_CONTACT" = "Invalid contact."; + +/* Error indicating that at least one contact field must be selected before sharing a contact. */ +"CONTACT_SHARE_NO_FIELDS_SELECTED" = "No contact fields selected."; + /* Indicates that a contact has no name. */ "CONTACT_WITHOUT_NAME" = "Unnamed Contact"; diff --git a/SignalMessaging/attachments/ApproveContactShareViewController.swift b/SignalMessaging/attachments/ApproveContactShareViewController.swift index 793efd220..c3ef9d746 100644 --- a/SignalMessaging/attachments/ApproveContactShareViewController.swift +++ b/SignalMessaging/attachments/ApproveContactShareViewController.swift @@ -278,11 +278,6 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh updateNavigationBar() } - // TODO: Surface error with resolution to user if not. - func canShareContact() -> Bool { - return contactShare.ows_isValid && isAtLeastOneFieldSelected() - } - func isAtLeastOneFieldSelected() -> Bool { for fieldView in fieldViews { if fieldView.field.isIncluded() { @@ -297,14 +292,9 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh target: self, action: #selector(didPressCancel)) - if canShareContact() { - self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON", - comment: "Label for 'send' button in the 'attachment approval' dialog."), - style: .plain, target: self, action: #selector(didPressSendButton)) - } else { - self.navigationItem.rightBarButtonItem = nil - } - + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON", + comment: "Label for 'send' button in the 'attachment approval' dialog."), + style: .plain, target: self, action: #selector(didPressSendButton)) } private func updateContent() { @@ -410,7 +400,17 @@ public class ApproveContactShareViewController: OWSViewController, EditContactSh func didPressSendButton() { SwiftAssertIsOnMainThread(#function) - assert(canShareContact()) + + guard isAtLeastOneFieldSelected() else { + OWSAlerts.showErrorAlert(message: NSLocalizedString("CONTACT_SHARE_NO_FIELDS_SELECTED", + comment: "Error indicating that at least one contact field must be selected before sharing a contact.")) + return + } + guard contactShare.ows_isValid else { + OWSAlerts.showErrorAlert(message: NSLocalizedString("CONTACT_SHARE_INVALID_CONTACT", + comment: "Error indicating that an invalid contact cannot be shared.")) + return + } Logger.info("\(logTag) \(#function)")