From 04eeb0100e6ec4f61b07b2a7e95969cfefc09729 Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Sat, 8 May 2021 10:38:55 +0800 Subject: [PATCH] fix: safely cancel the listenser for status --- Mastodon/Diffiable/Section/StatusSection.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Mastodon/Diffiable/Section/StatusSection.swift b/Mastodon/Diffiable/Section/StatusSection.swift index af4b70490..76bc91592 100644 --- a/Mastodon/Diffiable/Section/StatusSection.swift +++ b/Mastodon/Diffiable/Section/StatusSection.swift @@ -143,6 +143,21 @@ extension StatusSection { requestUserID: String, statusItemAttribute: Item.StatusAttribute ) { + // safely cancel the listenser when deleted + ManagedObjectObserver.observe(object: status.reblog ?? status) + .receive(on: DispatchQueue.main) + .sink { _ in + // do nothing + } receiveValue: { [weak cell] change in + guard let cell = cell else { return } + guard let changeType = change.changeType else { return } + if case .delete = changeType { + cell.disposeBag.removeAll() + } + } + .store(in: &cell.disposeBag) + + // set header StatusSection.configureHeader(cell: cell, status: status) ManagedObjectObserver.observe(object: status)