2024-06-25 07:59:46 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-07-11 15:53:50 +00:00
|
|
|
import { converse, api } from '../../../src/headless/index.js'
|
2024-06-25 07:59:46 +00:00
|
|
|
import './components/muc-terms.js'
|
|
|
|
|
|
|
|
const { sizzle } = converse.env
|
|
|
|
|
|
|
|
converse.plugins.add('livechat-converse-terms', {
|
|
|
|
dependencies: ['converse-muc'],
|
|
|
|
initialize () {
|
|
|
|
api.listen.on('parseMUCMessage', (stanza, attrs) => {
|
|
|
|
const livechatTerms = sizzle('x-livechat-terms', stanza)
|
|
|
|
if (!livechatTerms.length) {
|
|
|
|
return attrs
|
|
|
|
}
|
|
|
|
return Object.assign(
|
|
|
|
attrs,
|
|
|
|
{
|
|
|
|
x_livechat_terms: livechatTerms[0].getAttribute('type')
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
overrides: {
|
|
|
|
ChatRoom: {
|
|
|
|
onMessage: function onMessage (attrs) {
|
|
|
|
if (!attrs.x_livechat_terms) {
|
|
|
|
return this.__super__.onMessage(attrs)
|
|
|
|
}
|
|
|
|
// We received a x-livechat-terms message, we don't forward it to standard onMessage,
|
|
|
|
// but we just update the room attribute.
|
|
|
|
const type = attrs.x_livechat_terms
|
|
|
|
if (type !== 'global' && type !== 'muc') {
|
|
|
|
console.error('Invalid x-livechat-terms type: ', type)
|
|
|
|
return
|
|
|
|
}
|
2024-07-05 12:57:59 +00:00
|
|
|
if (attrs.is_archived) {
|
|
|
|
// This should not happen, as we add some no-store hints. But, just in case.
|
|
|
|
console.info('Dropping an archived x-livechat-terms message')
|
|
|
|
return
|
|
|
|
}
|
2024-06-25 07:59:46 +00:00
|
|
|
// console.info('Received a x-livechat-terms message', attrs)
|
|
|
|
const options = {}
|
|
|
|
options['x_livechat_terms_' + type] = attrs
|
|
|
|
this.set(options)
|
|
|
|
// this will be displayed by the livechat-converse-muc-terms custom element,
|
|
|
|
// which is inserted in the DOM by the muc.js template overload.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|