diff --git a/RiotSwiftUI/Modules/Room/PollHistory/PollHistoryViewModel.swift b/RiotSwiftUI/Modules/Room/PollHistory/PollHistoryViewModel.swift index de987925a..358404514 100644 --- a/RiotSwiftUI/Modules/Room/PollHistory/PollHistoryViewModel.swift +++ b/RiotSwiftUI/Modules/Room/PollHistory/PollHistoryViewModel.swift @@ -39,7 +39,7 @@ final class PollHistoryViewModel: PollHistoryViewModelType, PollHistoryViewModel setupSubscriptions() pollService.next() case .segmentDidChange: - updatePolls() + updateState() } } } @@ -51,8 +51,8 @@ private extension PollHistoryViewModel { pollService .pollHistory .sink { [weak self] detail in - self?.polls.append(detail) - self?.updatePolls() + self?.updatePolls(with: detail) + self?.updateState() } .store(in: &subcriptions) @@ -80,7 +80,15 @@ private extension PollHistoryViewModel { .store(in: &subcriptions) } - func updatePolls() { + func updatePolls(with poll: TimelinePollDetails) { + if let matchIndex = polls.firstIndex(where: { $0.id == poll.id }) { + polls[matchIndex] = poll + } else { + polls.append(poll) + } + } + + func updateState() { let renderedPolls: [TimelinePollDetails] switch context.mode { diff --git a/RiotSwiftUI/Modules/Room/PollHistory/Service/MatrixSDK/PollHistoryService.swift b/RiotSwiftUI/Modules/Room/PollHistory/Service/MatrixSDK/PollHistoryService.swift index 8d96b3e36..1bdd34df0 100644 --- a/RiotSwiftUI/Modules/Room/PollHistory/Service/MatrixSDK/PollHistoryService.swift +++ b/RiotSwiftUI/Modules/Room/PollHistory/Service/MatrixSDK/PollHistoryService.swift @@ -148,17 +148,17 @@ private extension PollHistoryService { // MARK: - PollAggregatorDelegate extension PollHistoryService: PollAggregatorDelegate { - func pollAggregatorDidStartLoading(_ aggregator: PollAggregator) { - } + func pollAggregatorDidStartLoading(_ aggregator: PollAggregator) {} func pollAggregatorDidEndLoading(_ aggregator: PollAggregator) { pollsSubject.send(.init(poll: aggregator.poll, represent: .started)) } func pollAggregator(_ aggregator: PollAggregator, didFailWithError: Error) { + #warning("Handle error") } func pollAggregatorDidUpdateData(_ aggregator: PollAggregator) { - + pollsSubject.send(.init(poll: aggregator.poll, represent: .started)) } }