瀏覽代碼

Include `chatbox` in 'message' event data

JC Brand 5 年之前
父節點
當前提交
9fe7bfcd64
共有 4 個文件被更改,包括 22 次插入9 次删除
  1. 1 1
      docs/source/theming.rst
  2. 4 4
      src/headless/converse-chat.js
  3. 16 3
      src/headless/converse-muc.js
  4. 1 1
      src/headless/utils/muc.js

+ 1 - 1
docs/source/theming.rst

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

+ 4 - 4
src/headless/converse-chat.js

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

+ 16 - 3
src/headless/converse-muc.js

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

+ 1 - 1
src/headless/utils/muc.js

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