-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that we no longer need |
||
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,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 { | ||
|
There was a problem hiding this comment.
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.