diff --git a/conversejs/custom/plugins/poll/components/poll-view.js b/conversejs/custom/plugins/poll/components/poll-view.js index e96b5f3b..6f7410c4 100644 --- a/conversejs/custom/plugins/poll/components/poll-view.js +++ b/conversejs/custom/plugins/poll/components/poll-view.js @@ -4,7 +4,7 @@ import { tplPoll } from '../templates/poll.js' import { CustomElement } from 'shared/components/element.js' -import { converse, api } from '@converse/headless/core' +import { converse, _converse, api } from '@converse/headless/core' import '../styles/poll.scss' export default class MUCPollView extends CustomElement { @@ -26,6 +26,13 @@ export default class MUCPollView extends CustomElement { this.buttonDisabled = false this.requestUpdate() }) + this.listenTo(this.model.occupants, 'change:role', occupant => { + if (occupant.get('jid') !== _converse.bare_jid) { // only for myself + return + } + // visitors cant vote. So we must refresh the polls results when current occupant role changes. + this.requestUpdate() + }) } render () { diff --git a/conversejs/custom/plugins/poll/index.js b/conversejs/custom/plugins/poll/index.js index 2f32be8d..d7e94b0c 100644 --- a/conversejs/custom/plugins/poll/index.js +++ b/conversejs/custom/plugins/poll/index.js @@ -16,11 +16,6 @@ converse.plugins.add('livechat-converse-poll', { dependencies: ['converse-muc', 'converse-disco'], initialize () { - // _converse.api.listen.on('chatRoomInitialized', muc => { - // muc.features.on('change:' + XMLNS_POLL, () => { - // // TODO: refresh headingbuttons? - // }) - // }) // adding the poll actions in the MUC heading buttons: _converse.api.listen.on('getHeadingButtons', getHeadingButtons) diff --git a/conversejs/custom/plugins/poll/templates/poll.js b/conversejs/custom/plugins/poll/templates/poll.js index 03ad095f..f1b61144 100644 --- a/conversejs/custom/plugins/poll/templates/poll.js +++ b/conversejs/custom/plugins/poll/templates/poll.js @@ -6,8 +6,8 @@ import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' -function _tplPollInstructions (el, currentPoll) { - if (currentPoll.over) { +function _tplPollInstructions (el, currentPoll, canVote) { + if (currentPoll.over || !canVote) { return html`` } @@ -115,7 +115,7 @@ export function tplPoll (el, currentPoll, canVote) { ${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c, canVote))}
- ${_tplPollInstructions(el, currentPoll)} + ${_tplPollInstructions(el, currentPoll, canVote)} ${_tplPollEnd(el, currentPoll)} ` }