From 57d2e024a0a52ca290045458dc4c462eb1e69981 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 30 Dec 2024 17:53:21 -0500 Subject: [PATCH] Fix an issue with blogging reminders flow not being shown after publishing a new post --- RELEASE-NOTES.txt | 1 + .../AztecPostViewController.swift | 2 +- ...gingRemindersFlowIntroViewController.swift | 34 ++++--------------- .../Gutenberg/GutenbergViewController.swift | 2 +- .../NewGutenbergViewController.swift | 4 +-- .../Controllers/EditPageViewController.swift | 2 +- .../Post/EditPostViewController.swift | 21 ++++-------- .../ViewRelated/Post/PostEditor+Publish.swift | 18 +++++----- .../Classes/ViewRelated/Post/PostEditor.swift | 2 +- .../Post/PostListEditorPresenter.swift | 2 +- 10 files changed, 30 insertions(+), 58 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ffda07ddec97..14842c841edb 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -2,6 +2,7 @@ ----- * [**] Add new lightbox screen for images with modern transitions and enhanced performance [#23922] * [*] Add prefetching to Reader streams [#23928] +* [*] Fix an issue with blogging reminders prompt not being shown after publishing a new post [#23930] 25.6 ----- diff --git a/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift b/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift index 08b1d51bb244..8b88ea4f9ef2 100644 --- a/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift +++ b/WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift @@ -23,7 +23,7 @@ class AztecPostViewController: UIViewController, PostEditor { /// Closure to be executed when the editor gets closed. /// - var onClose: ((_ changesSaved: Bool) -> ())? + var onClose: (() -> ())? /// Verification Prompt Helper /// diff --git a/WordPress/Classes/ViewRelated/Blog/Blogging Reminders/BloggingRemindersFlowIntroViewController.swift b/WordPress/Classes/ViewRelated/Blog/Blogging Reminders/BloggingRemindersFlowIntroViewController.swift index 76430c083a7f..36666edd5eb8 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blogging Reminders/BloggingRemindersFlowIntroViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blogging Reminders/BloggingRemindersFlowIntroViewController.swift @@ -29,7 +29,7 @@ class BloggingRemindersFlowIntroViewController: UIViewController { label.font = WPStyleGuide.serifFontForTextStyle(.title1, fontWeight: .semibold) label.numberOfLines = 2 label.textAlignment = .center - label.text = TextContent.introTitle + label.text = Strings.introTitle return label }() @@ -46,7 +46,7 @@ class BloggingRemindersFlowIntroViewController: UIViewController { private lazy var getStartedButton: UIButton = { let button = FancyButton() button.isPrimary = true - button.setTitle(TextContent.introButtonTitle, for: .normal) + button.setTitle(Strings.introButtonTitle, for: .normal) button.addTarget(self, action: #selector(getStartedTapped), for: .touchUpInside) return button }() @@ -58,18 +58,6 @@ class BloggingRemindersFlowIntroViewController: UIViewController { private let source: BloggingRemindersTracker.FlowStartSource private weak var delegate: BloggingRemindersFlowDelegate? - private var introDescription: String { - switch source { - case .publishFlow: - return TextContent.postPublishingintroDescription - case .blogSettings, - .notificationSettings, - .statsInsights, - .bloggingPromptsFeatureIntroduction: - return TextContent.siteSettingsIntroDescription - } - } - init(for blog: Blog, tracker: BloggingRemindersTracker, source: BloggingRemindersTracker.FlowStartSource, @@ -98,7 +86,7 @@ class BloggingRemindersFlowIntroViewController: UIViewController { configureStackView() configureConstraints() - promptLabel.text = introDescription + promptLabel.text = Strings.introDescription } override func viewDidAppear(_ animated: Bool) { @@ -197,18 +185,10 @@ extension BloggingRemindersFlowIntroViewController: ChildDrawerPositionable { // MARK: - Constants -private enum TextContent { - static let introTitle = NSLocalizedString("Set your blogging reminders", - comment: "Title of the Blogging Reminders Settings screen.") - - static let postPublishingintroDescription = NSLocalizedString("Your post is publishing... in the meantime, set up your blogging reminders on days you want to post.", - comment: "Description on the first screen of the Blogging Reminders Settings flow called aftet post publishing.") - - static let siteSettingsIntroDescription = NSLocalizedString("Set up your blogging reminders on days you want to post.", - comment: "Description on the first screen of the Blogging Reminders Settings flow called from site settings.") - - static let introButtonTitle = NSLocalizedString("Set reminders", - comment: "Title of the set goals button in the Blogging Reminders Settings flow.") +private enum Strings { + static let introTitle = NSLocalizedString("bloggingRemindersPrompt.intro.title", value: "Blogging Reminders", comment: "Title of the Blogging Reminders Settings screen.") + static let introDescription = NSLocalizedString("bloggingRemindersPrompt.intro.details", value: "Set up your blogging reminders on days you want to post.", comment: "Description on the first screen of the Blogging Reminders Settings flow called aftet post publishing.") + static let introButtonTitle = NSLocalizedString("bloggingRemindersPrompt.intro.continueButton", value: "Set reminders", comment: "Title of the set goals button in the Blogging Reminders Settings flow.") } private enum Images { diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift index 758bf6f4abff..1589fc3e3ade 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift @@ -91,7 +91,7 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega var editorSession: PostEditorAnalyticsSession - var onClose: ((Bool) -> Void)? + var onClose: (() -> Void)? var postIsReblogged: Bool = false diff --git a/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift b/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift index 8b8516e62d7c..f3fd5637ea5a 100644 --- a/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift @@ -34,7 +34,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor var analyticsEditorSource: String { Analytics.editorSource } var editorSession: PostEditorAnalyticsSession - var onClose: ((Bool) -> Void)? + var onClose: (() -> Void)? // MARK: - Set content @@ -321,7 +321,7 @@ extension NewGutenbergViewController: GutenbergKit.EditorViewControllerDelegate } func editor(_ viewContoller: GutenbergKit.EditorViewController, didEncounterCriticalError error: any Error) { - onClose?(false) + onClose?() } func editor(_ viewController: GutenbergKit.EditorViewController, didUpdateContentWithState state: GutenbergKit.EditorState) { diff --git a/WordPress/Classes/ViewRelated/Pages/Controllers/EditPageViewController.swift b/WordPress/Classes/ViewRelated/Pages/Controllers/EditPageViewController.swift index ee4b37ab70da..e74acbe58500 100644 --- a/WordPress/Classes/ViewRelated/Pages/Controllers/EditPageViewController.swift +++ b/WordPress/Classes/ViewRelated/Pages/Controllers/EditPageViewController.swift @@ -67,7 +67,7 @@ class EditPageViewController: UIViewController { private func show(_ editor: EditorViewController) { editor.entryPoint = entryPoint - editor.onClose = { [weak self] _ in + editor.onClose = { [weak self] in // Dismiss navigation controller self?.dismiss(animated: true) { // Dismiss self diff --git a/WordPress/Classes/ViewRelated/Post/EditPostViewController.swift b/WordPress/Classes/ViewRelated/Post/EditPostViewController.swift index 1998e29e5702..524fda7ec2de 100644 --- a/WordPress/Classes/ViewRelated/Post/EditPostViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/EditPostViewController.swift @@ -22,7 +22,7 @@ class EditPostViewController: UIViewController { fileprivate var editingExistingPost = false fileprivate let blog: Blog - @objc var onClose: ((_ changesSaved: Bool) -> ())? + @objc var onClose: (() -> ())? @objc var afterDismiss: (() -> Void)? override var modalPresentationStyle: UIModalPresentationStyle { @@ -126,19 +126,12 @@ class EditPostViewController: UIViewController { } private func showEditor(_ editor: EditorViewController) { - editor.onClose = { [weak self, weak editor] changesSaved in - guard let strongSelf = self else { + editor.onClose = { [weak self, weak editor] in + guard let self else { editor?.dismiss(animated: true) {} return } - - // NOTE: - // We need to grab the latest Post Reference, since it may have changed (ie. revision / user picked a - // new blog). - if changesSaved { - strongSelf.post = editor?.post as? Post - } - strongSelf.closeEditor(changesSaved) + self.closeEditor() } let navController = AztecNavigationController(rootViewController: editor) @@ -166,8 +159,8 @@ class EditPostViewController: UIViewController { } } - @objc func closeEditor(_ changesSaved: Bool = true, from presentingViewController: UIViewController? = nil) { - onClose?(changesSaved) + @objc func closeEditor(from presentingViewController: UIViewController? = nil) { + onClose?() dismiss(animated: true) { self.closeEditor(animated: false) } @@ -182,7 +175,7 @@ class EditPostViewController: UIViewController { return } self.afterDismiss?() - guard let post = self.post, + guard let post = self.post?.original(), post.isPublished(), !self.editingExistingPost, let controller = presentingController else { diff --git a/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift b/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift index 9f6d7777905d..410d3df38e61 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift @@ -26,7 +26,7 @@ protocol PublishingEditor where Self: UIViewController { var alertBarButtonItem: UIBarButtonItem? { get } /// Closure to be executed when the editor gets closed. - var onClose: ((_ changesSaved: Bool) -> Void)? { get set } + var onClose: (() -> Void)? { get set } /// Return the current html in the editor func getHTML() -> String @@ -204,19 +204,18 @@ extension PublishingEditor { } func discardUnsavedChangesAndUpdateGUI() { - let postDeleted = discardChanges() - dismissOrPopView(didSave: !postDeleted) + discardChanges() + dismissOrPopView() } - @discardableResult - func discardChanges() -> Bool { + func discardChanges() { guard post.status != .trash else { - return true // No revision is created for trashed posts + return // No revision is created for trashed posts } guard let context = post.managedObjectContext else { wpAssertionFailure("Missing managedObjectContext") - return true + return } WPAppAnalytics.track(.editorDiscardedChanges, withProperties: [WPAppAnalyticsKeyEditorSource: analyticsEditorSource], with: post) @@ -233,7 +232,6 @@ extension PublishingEditor { AbstractPost.deleteLatestRevision(post, in: context) ContextManager.shared.saveContextAndWait(context) - return true } private func showCloseDraftConfirmationAlert() { @@ -276,7 +274,7 @@ extension PublishingEditor { // MARK: - Publishing extension PublishingEditor { - func dismissOrPopView(didSave: Bool = true, presentBloggingReminders: Bool = false) { + func dismissOrPopView(presentBloggingReminders: Bool = false) { stopEditing() WPAppAnalytics.track(.editorClosed, withProperties: [WPAppAnalyticsKeyEditorSource: analyticsEditorSource], with: post) @@ -284,7 +282,7 @@ extension PublishingEditor { if let onClose { // if this closure exists, the presentation of the Blogging Reminders flow (if needed) // needs to happen in the closure. - onClose(didSave) + onClose() } else if isModal(), let controller = presentingViewController { controller.dismiss(animated: true) { if presentBloggingReminders { diff --git a/WordPress/Classes/ViewRelated/Post/PostEditor.swift b/WordPress/Classes/ViewRelated/Post/PostEditor.swift index bbe24267d949..a9bc7231d967 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditor.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditor.swift @@ -267,7 +267,7 @@ extension PostEditor where Self: UIViewController { let deletedObjects = ((userInfo[NSDeletedObjectsKey] as? Set) ?? []) if deletedObjects.contains(where: { $0.objectID == originalPostID }) { - onClose?(false) + onClose?() } } } diff --git a/WordPress/Classes/ViewRelated/Post/PostListEditorPresenter.swift b/WordPress/Classes/ViewRelated/Post/PostListEditorPresenter.swift index f66d2aa4fccd..d2736f1c8f0d 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListEditorPresenter.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListEditorPresenter.swift @@ -53,7 +53,7 @@ struct PostListEditorPresenter { let editor = EditPostViewController(post: post) editor.modalPresentationStyle = .fullScreen editor.entryPoint = entryPoint - editor.onClose = { _ in + editor.onClose = { NotificationCenter.default.post(name: .postListEditorPresenterDidHideEditor, object: nil) } postListViewController.present(editor, animated: false)