Include chatbox in 'message' event data

This commit is contained in:
JC Brand 2020-09-16 18:58:12 +02:00
parent 522e7706c1
commit 9fe7bfcd64
4 changed files with 22 additions and 9 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -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);
},

View File

@ -1,5 +1,5 @@
/**
* @copyright 2020, the Converse.js contributors
* @copyright The Converse.js contributors
* @license Mozilla Public License (MPLv2)
* @description This is the MUC utilities module.
*/