fix: safely cancel the listenser for status

This commit is contained in:
sunxiaojian 2021-05-08 10:38:55 +08:00
parent d3256f3171
commit 04eeb0100e
1 changed files with 15 additions and 0 deletions

View File

@ -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)