Converse v11, reporting customization in the livechat repo:
Reporting the vcard plugin customizations in the livechat repo, to avoid maintaining a Converse fork.
This commit is contained in:
parent
6218d65b72
commit
e97cd1d78e
57
conversejs/custom/livechat-patch-vcard.js
Normal file
57
conversejs/custom/livechat-patch-vcard.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Here we are patching the vCard plugin, to add some specific optimizations.
|
||||||
|
|
||||||
|
import { _converse, api } from '@converse/headless/index.js'
|
||||||
|
import {
|
||||||
|
onOccupantAvatarChanged,
|
||||||
|
setVCardOnModel,
|
||||||
|
setVCardOnOccupant
|
||||||
|
} from '@converse/headless/plugins/vcard/utils.js'
|
||||||
|
|
||||||
|
const pluginDefinition = _converse.pluggable.plugins['converse-vcard']
|
||||||
|
const originalInitialize = pluginDefinition.initialize
|
||||||
|
|
||||||
|
pluginDefinition.initialize = function initialize () {
|
||||||
|
const previousListeners = _converse._events.chatRoomInitialized ?? []
|
||||||
|
originalInitialize.apply(this)
|
||||||
|
|
||||||
|
_converse.api.settings.extend({
|
||||||
|
livechat_load_all_vcards: false
|
||||||
|
})
|
||||||
|
|
||||||
|
// Now we must detect the new chatRoomInitialized listener, and remove it:
|
||||||
|
const listenersToRemove = []
|
||||||
|
for (const def of _converse._events.chatRoomInitialized ?? []) {
|
||||||
|
if (def.callback && !previousListeners.includes(def.callback)) {
|
||||||
|
listenersToRemove.push(def.callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const callback of listenersToRemove) {
|
||||||
|
console.debug('Livechat patching vcard: we must remove this listener', callback)
|
||||||
|
api.listen.not('chatRoomInitialized', callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding the new listener:
|
||||||
|
api.listen.on('chatRoomInitialized', (m) => {
|
||||||
|
console.debug('Patched version of the vcard chatRoomInitialized event.')
|
||||||
|
setVCardOnModel(m)
|
||||||
|
|
||||||
|
// loadAll: when in readonly mode (ie: OBS integration), always load all avatars.
|
||||||
|
const loadAll = api.settings.get('livechat_load_all_vcards') === true
|
||||||
|
let hiddenOccupants = m.get('hidden_occupants')
|
||||||
|
if (hiddenOccupants !== true || loadAll) {
|
||||||
|
m.occupants.forEach(setVCardOnOccupant)
|
||||||
|
}
|
||||||
|
m.listenTo(m.occupants, 'add', (occupant) => {
|
||||||
|
if (hiddenOccupants !== true || loadAll) {
|
||||||
|
setVCardOnOccupant(occupant)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
m.on('change:hidden_occupants', () => {
|
||||||
|
hiddenOccupants = m.get('hidden_occupants')
|
||||||
|
if (hiddenOccupants !== true || loadAll) {
|
||||||
|
m.occupants.forEach(setVCardOnOccupant)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
m.listenTo(m.occupants, 'change:image_hash', o => onOccupantAvatarChanged(o))
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user