Post status deleted notifications when load fails with not found

This commit is contained in:
Shadowfacts 2023-01-17 20:04:48 -05:00
parent fb7a7db6e8
commit 10803408cd
1 changed files with 18 additions and 1 deletions

View File

@ -36,7 +36,24 @@ class FetchStatusService {
} }
private func handleStatusNotFound() { private func handleStatusNotFound() {
// todo: remove from persistent store, send notifications // todo: what about when browsing on another instance?
guard let accountID = mastodonController.accountInfo?.id else {
return
}
var reblogIDs = [String]()
if let cached = mastodonController.persistentContainer.status(for: statusID) {
let reblogsReq = StatusMO.fetchRequest()
reblogsReq.predicate = NSPredicate(format: "reblog = %@", cached)
if let reblogs = try? mastodonController.persistentContainer.viewContext.fetch(reblogsReq) {
reblogIDs = reblogs.map(\.id)
}
}
NotificationCenter.default.post(name: .statusDeleted, object: nil, userInfo: [
"accountID": accountID,
"statusIDs": [statusID] + reblogIDs
])
} }
enum Result { enum Result {