Update datasource on delete statuses in timelines and thread (IOS-212)
This commit is contained in:
parent
31796f1680
commit
9167260e30
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue