Commit 9fe7bfcd authored by JC Brand's avatar JC Brand

Include `chatbox` in 'message' event data

parent 522e7706
......@@ -53,7 +53,7 @@ To generate the CSS you can run::
make css
Testing your changes
=======
====================
The recommended way to test your changes is to run the tests that are part of the Converse source code.
By executing ``make test`` you'll run all tests (which live in the ``spec`` folder) which will open a browser window in which tests are processed.
......
......@@ -1215,19 +1215,19 @@ converse.plugins.add('converse-chat', {
const chatbox = await api.chats.get(attrs.contact_jid, {'nickname': attrs.nick }, has_body);
await chatbox?.queueMessage(attrs);
/**
* @typedef { Object } MessageData
* An object containing the original message stanza, as well as the
* parsed attributes.
* @typedef { Object } MessageData
* @property { XMLElement } stanza
* @property { MessageAttributes } stanza
* @property { ChatBox } chatbox
*/
const data = {stanza, attrs};
const data = {stanza, attrs, chatbox};
/**
* Triggered when a message stanza is been received and processed.
* @event _converse#message
* @type { object }
* @property { MessageData|MUCMessageData } data
* @example _converse.api.listen.on('message', obj => { ... });
* @property { module:converse-chat~MessageData } data
*/
api.trigger('message', data);
}
......
......@@ -662,6 +662,12 @@ converse.plugins.add('converse-muc', {
}
},
/**
* Parses an incoming message stanza and queues it for processing.
* @private
* @method _converse.ChatRoom#handleMessageStanza
* @param { XMLElement } stanza
*/
async handleMessageStanza (stanza) {
if (st.isArchived(stanza)) {
// MAM messages are handled in converse-mam.
......@@ -673,14 +679,21 @@ converse.plugins.add('converse-muc', {
this.fetchFeaturesIfConfigurationChanged(stanza);
/**
* @typedef { Object } MUCMessageData
* An object containing the original groupchat message stanza,
* as well as the parsed attributes.
* @typedef { Object } MUCMessageData
* @property { XMLElement } stanza
* @property { MUCMessageAttributes } stanza
* @property { MUCMessageAttributes } attrs
* @property { ChatRoom } chatbox
*/
const attrs = await st.parseMUCMessage(stanza, this, _converse);
const data = {stanza, attrs};
const data = {stanza, attrs, 'chatbox': this};
/**
* Triggered when a groupchat message stanza has been received and parsed.
* @event _converse#message
* @type { object }
* @property { module:converse-muc~MUCMessageData } data
*/
api.trigger('message', data);
return attrs && this.queueMessage(attrs);
},
......
/**
* @copyright 2020, the Converse.js contributors
* @copyright The Converse.js contributors
* @license Mozilla Public License (MPLv2)
* @description This is the MUC utilities module.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment