Browse Source

Add stanza-specific event listener.

Therefore removing the `presence` event again.
JC Brand 9 năm trước cách đây
mục cha
commit
36a875a402
4 tập tin đã thay đổi với 14 bổ sung6 xóa
  1. 2 1
      docs/CHANGES.md
  2. 0 4
      docs/source/development.rst
  3. 12 0
      src/converse-api.js
  4. 0 1
      src/converse-core.js

+ 2 - 1
docs/CHANGES.md

@@ -2,7 +2,8 @@
 
 ## 0.11.0 (Unreleased)
 
-- Emit an event `presence` when a presence stanza is received. [jcbrand]
+- Add stanza-specific event listener `converse.listen.stanza`.
+  As a result `converse.listen.on('message');` has been deprecated, use `converse.stanza.on('message');` instead. [jcbrand]
 - Emit an event `chatBoxInitialized` once a chat box's initialize method has been called. [jcbrand]
 - Emit an event `statusInitialized` once the user's own status has been initialized upon startup. [jcbrand]
 - Split converse.js up into different plugin modules. [jcbrand]

+ 0 - 4
docs/source/development.rst

@@ -780,14 +780,10 @@ Here are the different events that are emitted:
 +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
 | **initialized**                 | Once converse.js has been initialized.                                                            | ``converse.listen.on('initialized', function (event) { ... });``                                     |
 +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
-| **message**                     | When a message is received.                                                                       | ``converse.listen.on('message', function (event, messageXML) { ... });``                             |
-+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
 | **messageSend**                 | When a message will be sent out.                                                                  | ``storage_memoryconverse.listen.on('messageSend', function (event, messageText) { ... });``          |
 +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
 | **noResumeableSession**         | When keepalive=true but there aren't any stored prebind tokens.                                   | ``converse.listen.on('noResumeableSession', function (event) { ... });``                             |
 +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
-| **presence**                    | A presence stanza has been received.                                                              | ``converse.listen.on('presence', function (event, presenceStanza) { ... });``                        |
-+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
 | **reconnect**                   | After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode. | ``converse.listen.on('reconnect', function (event) { ... });``                                       |
 +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
 | **roomInviteSent**              | After the user has sent out a direct invitation, to a roster contact, asking them to join a room. | ``converse.listen.on('roomInvite', function (event, data) { ... });``                                |

+ 12 - 0
src/converse-api.js

@@ -144,6 +144,18 @@
             'not': function (evt, handler) {
                 converse.off(evt, handler);
             },
+            'stanza': function (name, options, handler) {
+                options = options || {};
+                converse.connection.addHandler(
+                    handler,
+                    options.ns,
+                    options.name,
+                    options.type,
+                    options.id,
+                    options.from,
+                    options
+                );
+            },
         },
         'send': function (stanza) {
             converse.connection.send(stanza);

+ 0 - 1
src/converse-core.js

@@ -1182,7 +1182,6 @@
                     this.addResource(bare_jid, resource);
                     contact.save({'chat_status': chat_status});
                 }
-                converse.emit('presence', presence);
             }
         });