2024-06-27 17:56:12 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { XMLNS_POLL } from './constants.js'
|
2024-07-11 15:53:50 +00:00
|
|
|
import { _converse, api } from '../../../src/headless/index.js'
|
2024-06-27 17:56:12 +00:00
|
|
|
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) {
|
2024-06-27 17:56:12 +00:00
|
|
|
// 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()
|
2024-06-28 16:38:59 +00:00
|
|
|
api.modal.show('livechat-converse-poll-form-modal', { model: muc })
|
2024-06-27 17:56:12 +00:00
|
|
|
},
|
|
|
|
a_class: '',
|
|
|
|
icon_class: 'fa-list-check', // FIXME
|
|
|
|
name: 'muc-create-poll'
|
|
|
|
})
|
|
|
|
|
|
|
|
return buttons
|
|
|
|
}
|