Search user messages WIP (#145)
This commit is contained in:
57
conversejs/custom/plugins/mam-search/utils.js
Normal file
57
conversejs/custom/plugins/mam-search/utils.js
Normal file
@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { api } from '../../../src/headless/index.js'
|
||||
import { XMLNS_MAM_SEARCH } from './constants.js'
|
||||
import { __ } from 'i18n'
|
||||
|
||||
function getMessageActionButtons (messageActionsEl, buttons) {
|
||||
const messageModel = messageActionsEl.model
|
||||
if (!api.settings.get('livechat_mam_search_app_enabled')) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
if (messageModel.get('type') !== 'groupchat') {
|
||||
// only on groupchat message.
|
||||
return buttons
|
||||
}
|
||||
|
||||
if (!messageModel.occupant) {
|
||||
return buttons
|
||||
}
|
||||
|
||||
const muc = messageModel.collection?.chatbox
|
||||
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(messageModel.occupant)
|
||||
},
|
||||
button_class: '',
|
||||
icon_class: 'fa fa-magnifying-glass',
|
||||
name: 'muc-mam-search'
|
||||
})
|
||||
|
||||
return buttons
|
||||
}
|
||||
|
||||
export {
|
||||
getMessageActionButtons
|
||||
}
|
Reference in New Issue
Block a user