Do not allow to vote the same option twice.

This commit is contained in:
Onuray Sahin 2021-12-09 16:08:59 +03:00
parent d5f8931e20
commit be9e592aa5
2 changed files with 8 additions and 2 deletions

View file

@ -158,7 +158,7 @@ internal class LocalEchoEventFactory @Inject constructor(
),
answers = options.mapIndexed { index, option ->
PollAnswer(
id = index.toString(),
id = "$index-$option",
answer = option
)
}

View file

@ -911,7 +911,13 @@ class RoomDetailViewModel @AssistedInject constructor(
private fun handleVoteToPoll(action: RoomDetailAction.VoteToPoll) {
// Do not allow to vote unsent local echo of the poll event
if (LocalEcho.isLocalEchoId(action.eventId)) return
room.voteToPoll(action.eventId, action.optionKey)
// Do not allow to vote the same option twice
room.getTimeLineEvent(action.eventId)?.let { pollTimelineEvent ->
val currentVote = pollTimelineEvent.annotations?.pollResponseSummary?.aggregatedContent?.myVote
if (currentVote != action.optionKey) {
room.voteToPoll(action.eventId, action.optionKey)
}
}
}
private fun handleEndPoll(eventId: String) {