Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with blogging reminders prompt not being shown after publishing a new post #23930

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()

Expand All @@ -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
}()
Expand All @@ -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,
Expand Down Expand Up @@ -98,7 +86,7 @@ class BloggingRemindersFlowIntroViewController: UIViewController {

configureStackView()
configureConstraints()
promptLabel.text = introDescription
promptLabel.text = Strings.introDescription
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -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.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no longer need for a separate path + I adopted l10n.

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega

var editorSession: PostEditorAnalyticsSession

var onClose: ((Bool) -> Void)?
var onClose: (() -> Void)?

var postIsReblogged: Bool = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 7 additions & 14 deletions WordPress/Classes/ViewRelated/Post/EditPostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer how it works starting from 23.9. After publishing editor?.post as? Post points to a revision that gets deleted during publishing. self.post is sufficient now.

}
strongSelf.closeEditor(changesSaved)
self.closeEditor()
}

let navController = AztecNavigationController(rootViewController: editor)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
18 changes: 8 additions & 10 deletions WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -204,19 +204,18 @@ extension PublishingEditor {
}

func discardUnsavedChangesAndUpdateGUI() {
let postDeleted = discardChanges()
dismissOrPopView(didSave: !postDeleted)
discardChanges()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that we no longer need didSave simplified this quite a bit.

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)
Expand All @@ -233,7 +232,6 @@ extension PublishingEditor {

AbstractPost.deleteLatestRevision(post, in: context)
ContextManager.shared.saveContextAndWait(context)
return true
}

private func showCloseDraftConfirmationAlert() {
Expand Down Expand Up @@ -276,15 +274,15 @@ 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)

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 {
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/ViewRelated/Post/PostEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ extension PostEditor where Self: UIViewController {

let deletedObjects = ((userInfo[NSDeletedObjectsKey] as? Set<NSManagedObject>) ?? [])
if deletedObjects.contains(where: { $0.objectID == originalPostID }) {
onClose?(false)
onClose?()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down