From 10803408cdb3e2c711699bbd3e78c0f47bdc097c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 17 Jan 2023 20:04:48 -0500 Subject: [PATCH] Post status deleted notifications when load fails with not found --- Tusker/API/FetchStatusService.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Tusker/API/FetchStatusService.swift b/Tusker/API/FetchStatusService.swift index 4d540df9..bf944b6d 100644 --- a/Tusker/API/FetchStatusService.swift +++ b/Tusker/API/FetchStatusService.swift @@ -36,7 +36,24 @@ class FetchStatusService { } 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 {