Poll WIP (#231):

* muted participants can't vote
* removed "Choice N" from button labels.
This commit is contained in:
John Livingston 2024-07-05 11:00:37 +02:00
parent 6dda0cc44f
commit 14ffa90208
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
5 changed files with 11 additions and 10 deletions

View File

@ -4,7 +4,7 @@
import { tplPoll } from '../templates/poll.js'
import { CustomElement } from 'shared/components/element.js'
import { api } from '@converse/headless/core'
import { converse, api } from '@converse/headless/core'
import '../styles/poll.scss'
export default class MUCPollView extends CustomElement {
@ -30,7 +30,9 @@ export default class MUCPollView extends CustomElement {
render () {
const currentPoll = this.model?.get('current_poll')
return tplPoll(this, currentPoll)
const entered = this.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED
const canVote = entered && this.model.getOwnRole() !== 'visitor'
return tplPoll(this, currentPoll, canVote)
}
toggle (ev) {

View File

@ -31,9 +31,9 @@ function _tplPollEnd (el, currentPoll) {
</p>`
}
function _tplChoice (el, currentPoll, choice) {
function _tplChoice (el, currentPoll, choice, canVote) {
// eslint-disable-next-line no-undef
const i18nChoiceN = __(LOC_poll_choice_n).replace('{{N}}', choice.choice)
const i18nChoiceN = '' + choice.choice + ':'
const votes = choice.votes
const totalVotes = currentPoll.votes
@ -42,7 +42,7 @@ function _tplChoice (el, currentPoll, choice) {
<tr>
<td>
${
currentPoll.over
currentPoll.over || !canVote
? html`${i18nChoiceN}`
: html`
<button type="button" class="btn btn-primary btn-sm"
@ -75,7 +75,7 @@ function _tplChoice (el, currentPoll, choice) {
</tr>`
}
export function tplPoll (el, currentPoll) {
export function tplPoll (el, currentPoll, canVote) {
if (!currentPoll) {
return html``
}
@ -113,7 +113,7 @@ export function tplPoll (el, currentPoll) {
? ''
: html`
<table><tbody>
${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c))}
${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c, canVote))}
</tbody></table>
${_tplPollInstructions(el, currentPoll)}
${_tplPollEnd(el, currentPoll)}

View File

@ -20,7 +20,7 @@ All above configurations are optional.
The priority for the hook that will take into account votes.
You can change this, if you have some specific hook that should be done after/before counting votes (slow mode, firewall, ...).
Default: 500
Default: 40 (Prosody checks visitor role with priority of 50, we want this to be after).
## Strings

View File

@ -23,7 +23,7 @@ local remove_specific_tags_from_groupchat = module:require("message").remove_spe
local handle_new_occupant_session = module:require("message").handle_new_occupant_session;
local room_restored = module:require("poll").room_restored;
local poll_groupchat_votes_priority = module:get_option_number("poll_groupchat_votes_priority") or 500;
local poll_groupchat_votes_priority = module:get_option_number("poll_groupchat_votes_priority") or 40;
-- new poll creation, get form

View File

@ -536,7 +536,6 @@ class ProsodyConfigContent {
*/
usePoll (): void {
this.muc.add('modules_enabled', 'muc_poll')
this.muc.set('poll_groupchat_votes_priority', 1000)
this.muc.set('poll_string_over', loc('poll_is_over'))
this.muc.set('poll_string_invalid_choice', loc('poll_choice_invalid'))
this.muc.set('poll_string_anonymous_vote_ok', loc('poll_anonymous_vote_ok'))