peertube-plugin-livechat/conversejs/custom/plugins/poll/utils.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
//
// SPDX-License-Identifier: AGPL-3.0-only
import { XMLNS_POLL } from './constants.js'
import { _converse, api } from '../../../src/headless/index.js'
import { __ } from 'i18n'
export function getHeadingButtons (view, buttons) {
const muc = view.model
2024-07-15 10:09:25 +00:00
if (muc.get('type') !== _converse.constants.CHATROOMS_TYPE) {
// only on MUC.
return buttons
}
if (!muc.features?.get?.(XMLNS_POLL)) {
// Poll feature not available (can happen if the chat is remote, and the plugin not up to date)
return buttons
}
const myself = muc.getOwnOccupant()
if (!myself || !['admin', 'owner'].includes(myself.get('affiliation'))) {
return buttons
}
// Adding a "New poll" button.
buttons.unshift({
// eslint-disable-next-line no-undef
i18n_text: __(LOC_new_poll),
handler: async (ev) => {
ev.preventDefault()
api.modal.show('livechat-converse-poll-form-modal', { model: muc })
},
a_class: '',
2024-07-16 10:01:51 +00:00
icon_class: 'fa-square-poll-horizontal',
name: 'muc-create-poll'
})
return buttons
}