Fix: TimelinePoll code refactoring

This commit is contained in:
Nicolas Mauri
2023-04-26 15:31:07 +02:00
parent 782ad8465c
commit b563043b19
11 changed files with 143 additions and 117 deletions
@@ -48,7 +48,7 @@ enum MockPollHistoryDetailScreenState: MockScreenState, CaseIterable {
}
var screenView: ([Any], AnyView) {
let timelineViewModel = TimelinePollViewModel(timelinePollDetails: poll)
let timelineViewModel = TimelinePollViewModel(timelinePollDetailsState: .loaded(poll))
let viewModel = PollHistoryDetailViewModel(poll: poll)
return ([viewModel], AnyView(PollHistoryDetail(viewModel: viewModel.context, contentPoll: TimelinePollView(viewModel: timelineViewModel.context))))
@@ -170,7 +170,6 @@ private extension PollHistoryService {
do {
newContext.pollAggregator = try PollAggregator(session: room.mxSession, room: room, pollEvent: pollStartEvent, delegate: self)
newContext.pollAggregator?.reloadPollData()
} catch {
pollAggregationContexts.removeValue(forKey: eventId)
}
@@ -210,13 +209,14 @@ extension PollHistoryService: PollAggregatorDelegate {
func pollAggregator(_ aggregator: PollAggregator, didFailWithError: Error) { }
func pollAggregatorDidEndLoading(_ aggregator: PollAggregator) {
guard let context = pollAggregationContexts[aggregator.poll.id], context.published == false else {
guard let poll = aggregator.poll, let context = pollAggregationContexts[poll.id], context.published == false else {
return
}
context.published = true
let newPoll: TimelinePollDetails = .init(poll: aggregator.poll, represent: .started)
let newPoll: TimelinePollDetails = .init(poll: poll, represent: .started)
if context.isLivePoll {
livePollsSubject.send(newPoll)
@@ -226,9 +226,9 @@ extension PollHistoryService: PollAggregatorDelegate {
}
func pollAggregatorDidUpdateData(_ aggregator: PollAggregator) {
guard let context = pollAggregationContexts[aggregator.poll.id], context.published else {
guard let poll = aggregator.poll, let context = pollAggregationContexts[poll.id], context.published else {
return
}
updatesSubject.send(.init(poll: aggregator.poll, represent: .started))
updatesSubject.send(.init(poll: poll, represent: .started))
}
}