mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Adds server side vote blocking for ended polls
This commit is contained in:
parent
2048b859c5
commit
e4ce4ab1ab
1 changed files with 13 additions and 6 deletions
|
@ -44,8 +44,8 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
|||
@EpoxyAttribute
|
||||
var totalVotesText: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var edited: Boolean = false
|
||||
@EpoxyAttribute
|
||||
var edited: Boolean = false
|
||||
|
||||
@EpoxyAttribute
|
||||
lateinit var optionViewStates: List<PollOptionViewState>
|
||||
|
@ -54,7 +54,6 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
|||
|
||||
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<PollItem.Holder>() {
|
|||
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<TextView>(R.id.questionTextView)
|
||||
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
|
||||
|
|
Loading…
Reference in a new issue