Polls: notifier on votes

This commit is contained in:
John Livingston 2024-07-05 16:34:51 +02:00
parent 9b1f24eafe
commit e97c33cec5
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
5 changed files with 26 additions and 2 deletions

View File

@ -128,3 +128,5 @@ declare const LOC_TOKEN_ACTION_CREATE: string
declare const LOC_TOKEN_ACTION_REVOKE: string
declare const LOC_TOKEN_DEFAULT_LABEL: string
declare const LOC_TOKEN_ACTION_REVOKE_CONFIRM: string
declare const LOC_POLL_VOTE_OK: string

View File

@ -17,6 +17,8 @@ declare global {
}
}
let pollListenerInitiliazed: boolean = false
/**
* load the ConverseJS CSS.
* @param url CSS url
@ -164,6 +166,15 @@ async function displayConverseJS (
}
const converseJSParams: InitConverseJSParams = await (response).json()
if (!pollListenerInitiliazed) {
// First time we got here, initiliaze this event:
const i18nVoteOk = await clientOptions.peertubeHelpers.translate(LOC_POLL_VOTE_OK)
pollListenerInitiliazed = true
document.addEventListener('livechat-poll-vote', () => {
clientOptions.peertubeHelpers.notifier.success(i18nVoteOk)
})
}
await loadConverseJS(converseJSParams)
await window.initConverse(converseJSParams, chatIncludeMode, authHeader ?? null)
}

View File

@ -47,7 +47,7 @@ export default class MUCPollView extends CustomElement {
this.collapsed = !this.collapsed
}
voteFor (choice) {
async voteFor (choice) {
if (this.buttonDisabled) { return }
const currentPoll = this.model?.get('current_poll')
@ -59,9 +59,18 @@ export default class MUCPollView extends CustomElement {
this.buttonDisabled = true
this.requestUpdate()
this.model.sendMessage({
await this.model.sendMessage({
body: '!' + choice.choice
})
// Dispatching an event.
// When in Peertube interface, this will open a Peertube notifier with a message.
// FIXME: we should only trigger this on the message echo or bounce,
// but seems ConverseJs does not provide any promise for that.
const event = new Event('livechat-poll-vote', {
bubbles: true
})
this.dispatchEvent(event)
}
closePoll (ev) {

View File

@ -578,3 +578,4 @@ poll_vote_instructions_xmpp: "Send a message with an exclamation mark followed b
poll_is_over: This poll is now over.
poll_choice_invalid: This choice is not valid.
poll_anonymous_vote_ok: Your vote is taken into account. Votes are anonymous, they will not be shown to other participants.
poll_vote_ok: Your vote has been taking into account, the counters will be updated in a moment.

View File

@ -559,3 +559,4 @@ poll_vote_instructions: "Pour voter, cliquez sur votre choix, ou envoyez un mess
poll_is_over: Ce sondage est à présent terminé.
poll_choice_invalid: Ce choix n'est pas valide.
poll_anonymous_vote_ok: Votre vote a été pris en compte. Les votes sont anonymes, ils ne seront pas montrés aux autres participant⋅es.
poll_vote_ok: Votre vote a été pris en compte, les compteurs seront mis à jour dans un instant.