Skip to content
Snippets Groups Projects
Commit 4b891ace authored by ubermanu's avatar ubermanu
Browse files

fix muc activity handler

parent 3fe6a3c8
No related branches found
No related tags found
2 merge requests!115161 new converse rai,!113History, Reply to messages and RAI
......@@ -88,7 +88,7 @@ converse.plugins.add('converse-rai', {
},
},
initialize() {
const { Strophe, _, $pres, u } = converse.env;
const { Strophe, _, $pres, u, sizzle } = converse.env;
const _converse = this._converse;
const { api } = _converse;
......@@ -129,45 +129,28 @@ converse.plugins.add('converse-rai', {
},
});
/**
* Triggers an event if a jid has activity.
*
* @param message
* @returns {boolean}
*/
function mucActivityHandler(message) {
console.log('mucActivityHandler', message);
const from_jid = message.attributes.from?.nodevalue;
const room_jid = from_jid?.split('/')[0];
let room = '';
let ignore = false;
const rai = sizzle(`rai[xmlns="${Strophe.NS.RAI}"]`, message).pop();
for (let i = 0; i < _converse.chatboxes.models.length; i++) {
if (_converse.chatboxes.models[i].id === room_jid) {
room = _converse.chatboxes.models[i].id;
break;
}
}
if (room && from_jid && room_jid) {
if (from_jid === room_jid + '/' + room.get('nick')) {
ignore = true;
}
}
if (message && !ignore) {
message.querySelectorAll('activity').forEach(activity => {
if (activity && activity.namespaceURI === Strophe.NS.RAI) {
const jid = activity.textContent;
// TODO: Give the chatroom object instead of the jid
api.trigger('chatRoomHasActivity', jid);
}
if (rai) {
rai.querySelectorAll('activity').forEach(activity => {
const jid = activity.textContent;
api.trigger('chatRoomHasActivity', jid);
});
}
return true;
}
// TODO: On loading subscribe to all the ChatViews in navigation (into another plugin)
// Register our RAI handler
api.listen.on('connected', () => {
_converse.connection.addHandler(mucActivityHandler, null, 'message');
});
// TODO: Remove
// api.listen.on('send', stanza => console.log('send', stanza));
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment