From e4ce4ab1ab0633ea4b33668ca20d6dc2aa8210ab Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 9 Mar 2022 12:07:16 +0100 Subject: [PATCH] Adds server side vote blocking for ended polls --- .../room/detail/timeline/item/PollItem.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt index 2327a0f2e2..0ce225b21c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt @@ -44,8 +44,8 @@ abstract class PollItem : AbsMessageItem() { @EpoxyAttribute var totalVotesText: String? = null - @EpoxyAttribute - var edited: Boolean = false + @EpoxyAttribute + var edited: Boolean = false @EpoxyAttribute lateinit var optionViewStates: List @@ -54,7 +54,6 @@ abstract class PollItem : AbsMessageItem() { override fun bind(holder: Holder) { super.bind(holder) - val relatedEventId = eventId ?: return renderSendState(holder.view, holder.questionTextView) @@ -73,13 +72,21 @@ abstract class PollItem : AbsMessageItem() { optionViewStates.forEachIndexed { index, optionViewState -> views.getOrNull(index)?.let { it.render(optionViewState) - it.setOnClickListener { - callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId)) - } + it.setOnClickListener { onPollItemClick(optionViewState) } } } } + private fun onPollItemClick(optionViewState: PollOptionViewState) { + val relatedEventId = eventId + + if (isPollActive(optionViewState) && relatedEventId != null) { + callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId)) + } + } + + private fun isPollActive(optionViewState: PollOptionViewState) = optionViewState !is PollOptionViewState.PollEnded + class Holder : AbsMessageItem.Holder(STUB_ID) { val questionTextView by bind(R.id.questionTextView) val optionsContainer by bind(R.id.optionsContainer)