diff --git a/Mastodon/Scene/Thread/ThreadViewController.swift b/Mastodon/Scene/Thread/ThreadViewController.swift index 0dcd473a1..ed8808b32 100644 --- a/Mastodon/Scene/Thread/ThreadViewController.swift +++ b/Mastodon/Scene/Thread/ThreadViewController.swift @@ -79,6 +79,13 @@ extension ThreadViewController { }) .store(in: &disposeBag) + viewModel.onEdit + .receive(on: DispatchQueue.main) + .sink(receiveValue: { [weak self] status in + self?.navigationController?.notifyChildrenAboutStatusUpdate(status) + }) + .store(in: &disposeBag) + tableView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(tableView) tableView.pinToParent() @@ -198,4 +205,10 @@ extension UINavigationController { provider?.delete(status: status ) } } + + func notifyChildrenAboutStatusUpdate(_ status: MastodonStatus) { + viewControllers.compactMap { $0 as? DataSourceProvider }.forEach { provider in + provider?.update(status: status ) + } + } } diff --git a/Mastodon/Scene/Thread/ThreadViewModel.swift b/Mastodon/Scene/Thread/ThreadViewModel.swift index 2a2e76a66..a6957049e 100644 --- a/Mastodon/Scene/Thread/ThreadViewModel.swift +++ b/Mastodon/Scene/Thread/ThreadViewModel.swift @@ -33,6 +33,7 @@ class ThreadViewModel { @Published var hasPendingStatusEditReload = false let onDismiss = PassthroughSubject() + let onEdit = PassthroughSubject() private(set) lazy var loadThreadStateMachine: GKStateMachine = { let stateMachine = GKStateMachine(states: [ @@ -84,14 +85,20 @@ class ThreadViewModel { context.publisherService .statusPublishResult .sink { [weak self] value in + guard let self else { return } if case let Result.success(result) = value { switch result { - case .edit: - self?.hasPendingStatusEditReload = true - case .post: - guard let self else { return } + case let .edit(content): + let status = content.value + let mastodonStatus = MastodonStatus.fromEntity(status) + self.hasPendingStatusEditReload = true + if status.id == root?.record.id { + self.root = .root(context: .init(status: mastodonStatus)) + } + self.loadThreadStateMachine.enter(LoadThreadState.Loading.self) + self.onEdit.send(mastodonStatus) + case .post: self.loadThreadStateMachine.enter(LoadThreadState.Loading.self) - } } }