Feature/4383 poll participants details

This commit is contained in:
Frank Rotermund
2023-05-31 14:31:07 +00:00
committed by Arnfried Griesert
parent 00286183f6
commit 9bd569dac0
22 changed files with 462 additions and 19 deletions
@@ -29,6 +29,7 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel
// MARK: Private
private let navigationRouter: NavigationRouterType?
private let parameters: TimelinePollCoordinatorParameters
private let selectedAnswerIdentifiersSubject = PassthroughSubject<[String], Never>()
@@ -43,9 +44,12 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel
// MARK: - Setup
init(parameters: TimelinePollCoordinatorParameters) throws {
// FRROT show participants needs a navigation router as it is a button click that creates a new View
init(parameters: TimelinePollCoordinatorParameters, navigationRouter: NavigationRouterType? = nil) throws {
self.parameters = parameters
self.navigationRouter = navigationRouter
try pollAggregator = PollAggregator(session: parameters.session, room: parameters.room, pollEvent: parameters.pollEvent)
pollAggregator.delegate = self
@@ -56,6 +60,9 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel
switch result {
case .selectedAnswerOptionsWithIdentifiers(let identifiers):
self.selectedAnswerIdentifiersSubject.send(identifiers)
case .showParticipants:
self.showParticipantsView()
}
}
@@ -105,6 +112,23 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel
}
}
func showParticipantsView() {
if let navigationRouter = navigationRouter {
let parameters = PollParticipantDetailsCoordinatorParameters(room: parameters.room, poll: pollAggregator.poll)
let coordinator = PollParticipantDetailsCoordinator(parameters: parameters)
add(childCoordinator: coordinator)
if navigationRouter.modules.isEmpty == false {
navigationRouter.push(coordinator, animated: true, popCompletion: nil)
} else {
navigationRouter.setRootModule(coordinator, popCompletion: nil)
}
coordinator.start()
}
}
// MARK: - PollAggregatorDelegate
func pollAggregatorDidUpdateData(_ aggregator: PollAggregator) {
@@ -134,7 +158,8 @@ extension TimelinePollDetails {
text: pollAnswerOption.text,
count: pollAnswerOption.count,
winner: pollAnswerOption.isWinner,
selected: pollAnswerOption.isCurrentUserSelection)
selected: pollAnswerOption.isCurrentUserSelection,
voters:pollAnswerOption.voters)
}
self.init(id: poll.id,
@@ -31,11 +31,15 @@ class TimelinePollProvider: NSObject {
}
}
}
var navigationRouter: NavigationRouterType? = nil
var coordinatorsForEventIdentifiers = [String: TimelinePollCoordinator]()
/// Create or retrieve the poll timeline coordinator for this event and return
/// a view to be displayed in the timeline
func buildTimelinePollVCForEvent(_ event: MXEvent) -> UIViewController? {
guard let session = session, let room = session.room(withRoomId: event.roomId) else {
return nil
}
@@ -45,7 +49,7 @@ class TimelinePollProvider: NSObject {
}
let parameters = TimelinePollCoordinatorParameters(session: session, room: room, pollEvent: event)
guard let coordinator = try? TimelinePollCoordinator(parameters: parameters) else {
guard let coordinator = try? TimelinePollCoordinator(parameters: parameters, navigationRouter: navigationRouter ) else {
return messageViewController(for: event)
}