mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 11:46:58 +02:00
Handle poll updates
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user