Update datasource on delete statuses in timelines and thread (IOS-212)

This commit is contained in:
Marcus Kida 2023-12-14 09:56:50 +01:00
parent 31796f1680
commit 9167260e30
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
3 changed files with 23 additions and 0 deletions

View File

@ -60,6 +60,10 @@ extension ThreadViewController: DataSourceProvider {
}
func delete(status: MastodonStatus) {
if viewModel.root?.record.id == status.id {
viewModel.root = nil
viewModel.onDismiss.send(status)
}
viewModel.mastodonStatusThreadViewModel.ancestors.handleDelete(status: status, for: viewModel)
viewModel.mastodonStatusThreadViewModel.descendants.handleDelete(status: status, for: viewModel)
}

View File

@ -14,6 +14,7 @@ import MastodonAsset
import MastodonCore
import MastodonUI
import MastodonLocalization
import MastodonSDK
final class ThreadViewController: UIViewController, NeedsDependency, MediaPreviewableViewController {
@ -70,6 +71,14 @@ extension ThreadViewController {
}
.store(in: &disposeBag)
viewModel.onDismiss
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] status in
self?.navigationController?.popViewController(animated: true)
self?.navigationController?.notifyChildrenAboutStatusDeletion(status)
})
.store(in: &disposeBag)
tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView)
tableView.pinToParent()
@ -182,3 +191,11 @@ extension ThreadViewController: StatusTableViewControllerNavigateable {
statusKeyCommandHandler(sender)
}
}
extension UINavigationController {
func notifyChildrenAboutStatusDeletion(_ status: MastodonStatus) {
viewControllers.compactMap { $0 as? DataSourceProvider }.forEach { provider in
provider?.delete(status: status )
}
}
}

View File

@ -32,6 +32,8 @@ class ThreadViewModel {
@Published var threadContext: ThreadContext?
@Published var hasPendingStatusEditReload = false
let onDismiss = PassthroughSubject<MastodonStatus, Never>()
private(set) lazy var loadThreadStateMachine: GKStateMachine = {
let stateMachine = GKStateMachine(states: [
LoadThreadState.Initial(viewModel: self),