Skip to content

Commit e115a2e

Browse files
committed
Prepare PostCoordinator side effects and cleanup for App Intent saves
A save that skips the UIKit flow used to skip the coordinator's non-UI side effects too: the dashboard notifications that refresh the posts cards, the app-rating significant event, and the post-save error analytics. The dormant didPublish helper now owns the success block so non-UI callers can emit them, leaving only the alert and notice UI in the UIKit path. The not-found cleanup from the in-app alert flow is shared so a post permanently deleted on the server no longer survives as a local ghost, and it now also removes the post's Spotlight entry, which was previously leaked. The scheduled-post publish date coercion moves to the shared RemotePostUpdateParameters helper.
1 parent 869579e commit e115a2e

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

WordPress/Classes/Services/PostCoordinator.swift

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ class PostCoordinator: NSObject {
9696
try await save(post, changes: parameters)
9797
}
9898

99+
/// Emits the side effects of a post reaching the scheduled or published
100+
/// state: dashboard notifications, Spotlight indexing, and the
101+
/// app-rating significant event.
99102
@MainActor
100-
private func didPublish(_ post: AbstractPost) {
103+
func didPublish(_ post: AbstractPost, previousStatus: BasePost.Status?) {
104+
guard previousStatus != post.status, post.isStatus(in: [.scheduled, .publish]) else {
105+
return
106+
}
101107
if post.status == .scheduled {
102108
notifyNewPostScheduled()
103109
} else if post.status == .publish {
@@ -118,29 +124,13 @@ class PostCoordinator: NSObject {
118124
let previousStatus = post.status
119125

120126
var changes = changes ?? .init()
121-
122-
// If the post was previously scheduled and the user wants to publish
123-
// it without specifying a new publish date, we have to send `.now`
124-
// to ensure it gets published immediatelly.
125-
if (changes.status == Post.Status.publish.rawValue || changes.status == Post.Status.publishPrivate.rawValue)
126-
&& previousStatus == .scheduled && changes.date == nil
127-
{
128-
changes.date = .now
129-
}
127+
changes.setDateForImmediatePublishIfNeeded(previousStatus: previousStatus)
130128

131129
do {
132130
let repository = PostRepository(coreDataStack: coreDataStack)
133131
try await repository.save(post, changes: changes)
134132

135-
if previousStatus != post.status && post.isStatus(in: [.scheduled, .publish]) {
136-
if post.status == .scheduled {
137-
notifyNewPostScheduled()
138-
} else if post.status == .publish {
139-
notifyNewPostPublished()
140-
}
141-
SearchManager.shared.indexItem(post)
142-
AppRatingUtility.shared.incrementSignificantEvent()
143-
}
133+
didPublish(post, previousStatus: previousStatus)
144134
show(PostCoordinator.makeUploadSuccessNotice(for: post, previousStatus: previousStatus))
145135
return post
146136
} catch {
@@ -193,7 +183,7 @@ class PostCoordinator: NSObject {
193183
topViewController.present(alert, animated: true)
194184
}
195185

196-
private func trackError(_ error: Error, operation: String, post: AbstractPost) {
186+
func trackError(_ error: Error, operation: String, post: AbstractPost) {
197187
DDLogError("post-coordinator-\(operation)-failed: \(error)")
198188

199189
if let error = error as? TrackableErrorProtocol, var userInfo = error.getTrackingUserInfo() {
@@ -230,7 +220,10 @@ class PostCoordinator: NSObject {
230220
startSync(for: post) // Clears the error associated with the post
231221
}
232222

233-
private func handlePermanentlyDeleted(_ post: AbstractPost) {
223+
/// Removes the local copy of a post that was permanently deleted on the
224+
/// server, along with its Spotlight entry.
225+
func handlePermanentlyDeleted(_ post: AbstractPost) {
226+
SearchManager.shared.deleteSearchableItem(post)
234227
let context = coreDataStack.mainContext
235228
context.deleteObject(post)
236229
ContextManager.shared.saveContextAndWait(context)

0 commit comments

Comments
 (0)