diff --git a/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController.swift b/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController.swift index 36ecd42046..7d4d84b6c1 100644 --- a/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController.swift +++ b/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController.swift @@ -995,9 +995,9 @@ extension ConversationSettingsViewController: OWSNavigationView { public func shouldCancelNavigationBack() -> Bool { let result = hasUnsavedChangesToDisappearingMessagesConfiguration if result { - GroupAttributesViewController.showUnsavedGroupChangesActionSheet(from: self, - saveBlock: { - self.updateDisappearingMessagesConfigurationAndDismiss() + Self.showUnsavedChangesActionSheet(from: self, + saveBlock: { + self.updateDisappearingMessagesConfigurationAndDismiss() }, discardBlock: { self.navigationController?.popViewController(animated: true) }) @@ -1005,6 +1005,29 @@ extension ConversationSettingsViewController: OWSNavigationView { return result } + @objc + public static func showUnsavedChangesActionSheet(from fromViewController: UIViewController, + saveBlock: @escaping () -> Void, + discardBlock: @escaping () -> Void) { + let actionSheet = ActionSheetController(title: NSLocalizedString("CONVERSATION_SETTINGS_UNSAVED_CHANGES_TITLE", + comment: "The alert title if user tries to exit conversation settings view without saving changes."), + message: NSLocalizedString("CONVERSATION_SETTINGS_UNSAVED_CHANGES_MESSAGE", + comment: "The alert message if user tries to exit conversation settings view without saving changes.")) + actionSheet.addAction(ActionSheetAction(title: NSLocalizedString("ALERT_SAVE", + comment: "The label for the 'save' button in action sheets."), + accessibilityIdentifier: UIView.accessibilityIdentifier(in: fromViewController, name: "save"), + style: .default) { _ in + saveBlock() + }) + actionSheet.addAction(ActionSheetAction(title: NSLocalizedString("ALERT_DONT_SAVE", + comment: "The label for the 'don't save' button in action sheets."), + accessibilityIdentifier: UIView.accessibilityIdentifier(in: fromViewController, name: "dont_save"), + style: .destructive) { _ in + discardBlock() + }) + fromViewController.presentActionSheet(actionSheet) + } + private func updateDisappearingMessagesConfigurationAndDismiss() { let dmConfiguration: OWSDisappearingMessagesConfiguration = disappearingMessagesConfiguration let thread = self.thread diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 8b4430a654..ba818da9ba 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -860,6 +860,12 @@ /* Label for button to unmute a thread. */ "CONVERSATION_SETTINGS_UNMUTE_ACTION" = "Unmute"; +/* The alert message if user tries to exit conversation settings view without saving changes. */ +"CONVERSATION_SETTINGS_UNSAVED_CHANGES_MESSAGE" = "Would you like to save the changes that you made to this conversation?"; + +/* The alert title if user tries to exit conversation settings view without saving changes. */ +"CONVERSATION_SETTINGS_UNSAVED_CHANGES_TITLE" = "Unsaved Changes"; + /* Label for 'view all members' button in conversation settings view. */ "CONVERSATION_SETTINGS_VIEW_ALL_MEMBERS" = "View all members";