Selaa lähdekoodia

Use `_converse.api.send` instead of `_converse.connection.send`

so that we can emit an event when sending a stanza.
JC Brand 6 vuotta sitten
vanhempi
commit
7b2d64b066

+ 2 - 2
src/converse-muc-views.js

@@ -949,7 +949,7 @@ converse.plugins.add('converse-muc-views', {
                         if (!this.verifyRoles(['visitor', 'participant', 'moderator'])) {
                             break;
                         }
-                        _converse.connection.send($pres({
+                        _converse.api.send($pres({
                             from: _converse.connection.jid,
                             to: this.model.getRoomJIDAndNick(match[2]),
                             id: _converse.connection.getUniqueId()
@@ -999,7 +999,7 @@ converse.plugins.add('converse-muc-views', {
                     case 'topic':
                     case 'subject':
                         // TODO: should be done via API call to _converse.api.rooms
-                        _converse.connection.send(
+                        _converse.api.send(
                             $msg({
                                 to: this.model.get('jid'),
                                 from: _converse.connection.jid,

+ 3 - 3
src/headless/converse-chatboxes.js

@@ -346,10 +346,10 @@ converse.plugins.add('converse-chatboxes', {
             },
 
             sendMessageStanza (stanza) {
-                _converse.connection.send(stanza);
+                _converse.api.send(stanza);
                 if (_converse.forward_messages) {
                     // Forward the message, so that other connected resources are also aware of it.
-                    _converse.connection.send(
+                    _converse.api.send(
                         $msg({
                             'to': _converse.bare_jid,
                             'type': this.get('message_type'),
@@ -407,7 +407,7 @@ converse.plugins.add('converse-chatboxes', {
                  * See XEP-0085 Chat State Notifications.
                  */
                 if (_converse.send_chat_state_notifications) {
-                    _converse.connection.send(
+                    _converse.api.send(
                         $msg({'to':this.get('jid'), 'type': 'chat'})
                             .c(this.get('chat_state'), {'xmlns': Strophe.NS.CHATSTATES}).up()
                             .c('no-store', {'xmlns': Strophe.NS.HINTS}).up()

+ 3 - 3
src/headless/converse-core.js

@@ -420,7 +420,7 @@ _converse.initialize = function (settings, callback) {
          */
         /* Send out a Chat Status Notification (XEP-0352) */
         // XXX if (converse.features[Strophe.NS.CSI] || true) {
-        _converse.connection.send($build(stat, {xmlns: Strophe.NS.CSI}));
+        _converse.api.send($build(stat, {xmlns: Strophe.NS.CSI}));
         _converse.inactive = (stat === _converse.INACTIVE) ? true : false;
     };
 
@@ -510,7 +510,7 @@ _converse.initialize = function (settings, callback) {
          */
         const pres = $pres({to: jid, type: "unsubscribed"});
         if (message && message !== "") { pres.c("status").t(message); }
-        _converse.connection.send(pres);
+        _converse.api.send(pres);
     };
 
     this.reconnect = _.debounce(function () {
@@ -914,7 +914,7 @@ _converse.initialize = function (settings, callback) {
         },
 
         sendPresence (type, status_message) {
-            _converse.connection.send(this.constructPresence(type, status_message));
+            _converse.api.send(this.constructPresence(type, status_message));
         }
     });
 

+ 1 - 1
src/headless/converse-disco.js

@@ -333,7 +333,7 @@ converse.plugins.add('converse-disco', {
             _.each(plugin._features, (feature) => {
                 iqresult.c('feature', {'var': feature}).up();
             });
-            _converse.connection.send(iqresult.tree());
+            _converse.api.send(iqresult.tree());
             return true;
         }
 

+ 7 - 7
src/headless/converse-muc.js

@@ -278,7 +278,7 @@ converse.plugins.add('converse-muc', {
                     stanza.cnode(Strophe.xmlElement("password", [], password));
                 }
                 this.save('connection_status', converse.ROOMSTATUS.CONNECTING);
-                _converse.connection.send(stanza);
+                _converse.api.send(stanza);
                 return this;
             },
 
@@ -426,7 +426,7 @@ converse.plugins.add('converse-muc', {
                     // <gone/> is not applicable within MUC context
                     return;
                 }
-                _converse.connection.send(
+                _converse.api.send(
                     $msg({'to':this.get('jid'), 'type': 'groupchat'})
                         .c(chat_state, {'xmlns': Strophe.NS.CHATSTATES}).up()
                         .c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
@@ -462,12 +462,12 @@ converse.plugins.add('converse-muc', {
                 if (this.get('password')) { attrs.password = this.get('password'); }
 
                 const invitation = $msg({
-                    from: _converse.connection.jid,
-                    to: recipient,
-                    id: _converse.connection.getUniqueId()
+                    'from': _converse.connection.jid,
+                    'to': recipient,
+                    'id': _converse.connection.getUniqueId()
                 }).c('x', attrs);
-                _converse.connection.send(invitation);
-                _converse.emit('roomInviteSent', {
+                _converse.api.send(invitation);
+                _converse.api.emit('roomInviteSent', {
                     'room': this,
                     'recipient': recipient,
                     'reason': reason

+ 5 - 5
src/headless/converse-roster.js

@@ -268,7 +268,7 @@ converse.plugins.add('converse-roster', {
                 if (nick) {
                     pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
                 }
-                _converse.connection.send(pres);
+                _converse.api.send(pres);
                 this.save('ask', "subscribe"); // ask === 'subscribe' Means we have asked to subscribe to them.
                 return this;
             },
@@ -279,7 +279,7 @@ converse.plugins.add('converse-roster', {
                 * state notification by sending a presence stanza of type
                 * "subscribe" to the contact
                 */
-                _converse.connection.send($pres({
+                _converse.api.send($pres({
                     'type': 'subscribe',
                     'to': this.get('jid')
                 }));
@@ -294,7 +294,7 @@ converse.plugins.add('converse-roster', {
                 *  Parameters:
                 *    (String) jid - The Jabber ID of the user who is unsubscribing
                 */
-                _converse.connection.send($pres({'type': 'unsubscribe', 'to': this.get('jid')}));
+                _converse.api.send($pres({'type': 'unsubscribe', 'to': this.get('jid')}));
                 this.removeFromRoster();
                 this.destroy();
             },
@@ -317,7 +317,7 @@ converse.plugins.add('converse-roster', {
                 if (message && message !== "") {
                     pres.c("status").t(message);
                 }
-                _converse.connection.send(pres);
+                _converse.api.send(pres);
                 return this;
             },
 
@@ -546,7 +546,7 @@ converse.plugins.add('converse-roster', {
                     // user's bare JID <user@domainpart>.
                     return;
                 }
-                _converse.connection.send($iq({type: 'result', id, from: _converse.connection.jid}));
+                _converse.api.send($iq({type: 'result', id, from: _converse.connection.jid}));
 
                 const query = sizzle(`query[xmlns="${Strophe.NS.ROSTER}"]`, iq).pop();
                 this.data.save('version', query.getAttribute('ver'));