Adding actions on the occupant list.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { api, converse } from '../../../src/headless/index.js'
|
||||
import { getMessageActionButtons } from './utils.js'
|
||||
import { getMessageActionButtons, getOccupantActionButtons } from './utils.js'
|
||||
import mamSearchApi from './api.js'
|
||||
|
||||
import './components/muc-mam-search-app-view.js'
|
||||
@ -23,8 +23,10 @@ converse.plugins.add('livechat-converse-mam-search', {
|
||||
livechat_mam_search_app_enabled: false
|
||||
})
|
||||
|
||||
// Adding buttons on message:
|
||||
// Adding buttons on messages:
|
||||
_converse.api.listen.on('getMessageActionButtons', getMessageActionButtons)
|
||||
// Adding buttons on occupants:
|
||||
_converse.api.listen.on('getOccupantActionButtons', getOccupantActionButtons)
|
||||
|
||||
// FIXME: should we listen to any event (feature/affiliation change?, mam_enabled?) to refresh messageActionButtons?
|
||||
}
|
||||
|
@ -52,6 +52,43 @@ function getMessageActionButtons (messageActionsEl, buttons) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
export {
|
||||
getMessageActionButtons
|
||||
function getOccupantActionButtons (occupant, buttons) {
|
||||
if (!api.settings.get('livechat_mam_search_app_enabled')) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
const muc = occupant.collection?.chatroom
|
||||
if (!muc) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
if (!muc.features?.get?.(XMLNS_MAM_SEARCH)) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
const myself = muc.getOwnOccupant()
|
||||
if (!myself || !['admin', 'owner'].includes(myself.get('affiliation'))) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const i18nSearch = __(LOC_search_occupant_message)
|
||||
|
||||
buttons.push({
|
||||
i18n_text: i18nSearch,
|
||||
handler: async (ev) => {
|
||||
ev.preventDefault()
|
||||
api.livechat_mam_search.showMessagesFrom(occupant)
|
||||
},
|
||||
button_class: '',
|
||||
icon_class: 'fa fa-magnifying-glass',
|
||||
name: 'muc-mam-search'
|
||||
})
|
||||
|
||||
return buttons
|
||||
}
|
||||
|
||||
export {
|
||||
getMessageActionButtons,
|
||||
getOccupantActionButtons
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ import { _converse, converse } from '../../../src/headless/index.js'
|
||||
import { XMLNS_NOTE } from './constants.js'
|
||||
import { ChatRoomNote } from './note.js'
|
||||
import { ChatRoomNotes } from './notes.js'
|
||||
import { initOrDestroyChatRoomNotes, getHeadingButtons, getMessageActionButtons } from './utils.js'
|
||||
import {
|
||||
initOrDestroyChatRoomNotes, getHeadingButtons, getMessageActionButtons, getOccupantActionButtons
|
||||
} from './utils.js'
|
||||
import notesApi from './api.js'
|
||||
|
||||
import './components/muc-note-app-view.js'
|
||||
@ -59,7 +61,9 @@ converse.plugins.add('livechat-converse-notes', {
|
||||
// adding the "Notes" button in the MUC heading buttons:
|
||||
_converse.api.listen.on('getHeadingButtons', getHeadingButtons)
|
||||
|
||||
// Adding buttons on message:
|
||||
// Adding buttons on messages:
|
||||
_converse.api.listen.on('getMessageActionButtons', getMessageActionButtons)
|
||||
// Adding buttons on occupants:
|
||||
_converse.api.listen.on('getOccupantActionButtons', getOccupantActionButtons)
|
||||
}
|
||||
})
|
||||
|
@ -82,6 +82,43 @@ export function getMessageActionButtons (messageActionsEl, buttons) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
export function getOccupantActionButtons (occupant, buttons) {
|
||||
const muc = occupant.collection?.chatroom
|
||||
if (!muc?.notes) {
|
||||
// We dont have access.
|
||||
return buttons
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const i18nCreate = __(LOC_moderator_note_create_for_participant)
|
||||
// eslint-disable-next-line no-undef
|
||||
const i18nSearch = __(LOC_moderator_note_search_for_participant)
|
||||
|
||||
buttons.push({
|
||||
i18n_text: i18nCreate,
|
||||
handler: async (ev) => {
|
||||
ev.preventDefault()
|
||||
await api.livechat_notes.openCreateNoteForm(occupant)
|
||||
},
|
||||
button_class: '',
|
||||
icon_class: 'fa fa-note-sticky',
|
||||
name: 'muc-note-create-for-occupant'
|
||||
})
|
||||
|
||||
buttons.push({
|
||||
i18n_text: i18nSearch,
|
||||
handler: async (ev) => {
|
||||
ev.preventDefault()
|
||||
await api.livechat_notes.searchNotesAbout(occupant)
|
||||
},
|
||||
button_class: '',
|
||||
icon_class: 'fa fa-magnifying-glass',
|
||||
name: 'muc-note-search-for-occupant'
|
||||
})
|
||||
|
||||
return buttons
|
||||
}
|
||||
|
||||
function _initChatRoomNotes (mucModel) {
|
||||
if (mucModel.noteManager) {
|
||||
// already initiliazed
|
||||
|
Reference in New Issue
Block a user