Skip to content

Commit

Permalink
Fix crash when deleting posts
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 22, 2023
1 parent 7063206 commit a8f4da3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions WordPress/Classes/Services/PostCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ class PostCoordinator: NSObject {
ActionDispatcher.dispatch(NoticeAction.dismiss)
ActionDispatcher.dispatch(NoticeAction.post(notice))

setPendingDeletion(false, post: post)
// No need to notify as the object gets deleted
setPendingDeletion(false, post: post, notify: false)
} catch {
if let error = error as NSError?, error.code == Constants.httpCodeForbidden {
delegate?.postCoordinator(self, promptForPasswordForBlog: post.blog)
Expand All @@ -532,15 +533,17 @@ class PostCoordinator: NSObject {
}
}

private func setPendingDeletion(_ isDeleting: Bool, post: AbstractPost) {
private func setPendingDeletion(_ isDeleting: Bool, post: AbstractPost, notify: Bool = true) {
if isDeleting {
pendingDeletionPostIDs.insert(post.objectID)
} else {
pendingDeletionPostIDs.remove(post.objectID)
}
NotificationCenter.default.post(name: .postCoordinatorDidUpdate, object: self, userInfo: [
NSUpdatedObjectsKey: Set([post])
])
if notify {
NotificationCenter.default.post(name: .postCoordinatorDidUpdate, object: self, userInfo: [
NSUpdatedObjectsKey: Set([post])
])
}
}

private func propertiesForAnalytics(for post: AbstractPost) -> [String: AnyObject] {
Expand Down

0 comments on commit a8f4da3

Please sign in to comment.