Adds server side vote blocking for ended polls

This commit is contained in:
ericdecanini 2022-03-09 12:07:16 +01:00
parent 2048b859c5
commit e4ce4ab1ab
1 changed files with 13 additions and 6 deletions

View File

@ -54,7 +54,6 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
val relatedEventId = eventId ?: return
renderSendState(holder.view, holder.questionTextView) renderSendState(holder.view, holder.questionTextView)
@ -73,12 +72,20 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
optionViewStates.forEachIndexed { index, optionViewState -> optionViewStates.forEachIndexed { index, optionViewState ->
views.getOrNull(index)?.let { views.getOrNull(index)?.let {
it.render(optionViewState) it.render(optionViewState)
it.setOnClickListener { it.setOnClickListener { onPollItemClick(optionViewState) }
}
}
}
private fun onPollItemClick(optionViewState: PollOptionViewState) {
val relatedEventId = eventId
if (isPollActive(optionViewState) && relatedEventId != null) {
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId)) callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId))
} }
} }
}
} private fun isPollActive(optionViewState: PollOptionViewState) = optionViewState !is PollOptionViewState.PollEnded
class Holder : AbsMessageItem.Holder(STUB_ID) { class Holder : AbsMessageItem.Holder(STUB_ID) {
val questionTextView by bind<TextView>(R.id.questionTextView) val questionTextView by bind<TextView>(R.id.questionTextView)