Commit 7b2d64b0 authored by JC Brand's avatar JC Brand

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

so that we can emit an event when sending a stanza.
parent 02f1b331
...@@ -949,7 +949,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -949,7 +949,7 @@ converse.plugins.add('converse-muc-views', {
if (!this.verifyRoles(['visitor', 'participant', 'moderator'])) { if (!this.verifyRoles(['visitor', 'participant', 'moderator'])) {
break; break;
} }
_converse.connection.send($pres({ _converse.api.send($pres({
from: _converse.connection.jid, from: _converse.connection.jid,
to: this.model.getRoomJIDAndNick(match[2]), to: this.model.getRoomJIDAndNick(match[2]),
id: _converse.connection.getUniqueId() id: _converse.connection.getUniqueId()
...@@ -999,7 +999,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -999,7 +999,7 @@ converse.plugins.add('converse-muc-views', {
case 'topic': case 'topic':
case 'subject': case 'subject':
// TODO: should be done via API call to _converse.api.rooms // TODO: should be done via API call to _converse.api.rooms
_converse.connection.send( _converse.api.send(
$msg({ $msg({
to: this.model.get('jid'), to: this.model.get('jid'),
from: _converse.connection.jid, from: _converse.connection.jid,
......
...@@ -346,10 +346,10 @@ converse.plugins.add('converse-chatboxes', { ...@@ -346,10 +346,10 @@ converse.plugins.add('converse-chatboxes', {
}, },
sendMessageStanza (stanza) { sendMessageStanza (stanza) {
_converse.connection.send(stanza); _converse.api.send(stanza);
if (_converse.forward_messages) { if (_converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it. // Forward the message, so that other connected resources are also aware of it.
_converse.connection.send( _converse.api.send(
$msg({ $msg({
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': this.get('message_type'), 'type': this.get('message_type'),
...@@ -407,7 +407,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -407,7 +407,7 @@ converse.plugins.add('converse-chatboxes', {
* See XEP-0085 Chat State Notifications. * See XEP-0085 Chat State Notifications.
*/ */
if (_converse.send_chat_state_notifications) { if (_converse.send_chat_state_notifications) {
_converse.connection.send( _converse.api.send(
$msg({'to':this.get('jid'), 'type': 'chat'}) $msg({'to':this.get('jid'), 'type': 'chat'})
.c(this.get('chat_state'), {'xmlns': Strophe.NS.CHATSTATES}).up() .c(this.get('chat_state'), {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('no-store', {'xmlns': Strophe.NS.HINTS}).up() .c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
......
...@@ -420,7 +420,7 @@ _converse.initialize = function (settings, callback) { ...@@ -420,7 +420,7 @@ _converse.initialize = function (settings, callback) {
*/ */
/* Send out a Chat Status Notification (XEP-0352) */ /* Send out a Chat Status Notification (XEP-0352) */
// XXX if (converse.features[Strophe.NS.CSI] || true) { // 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; _converse.inactive = (stat === _converse.INACTIVE) ? true : false;
}; };
...@@ -510,7 +510,7 @@ _converse.initialize = function (settings, callback) { ...@@ -510,7 +510,7 @@ _converse.initialize = function (settings, callback) {
*/ */
const pres = $pres({to: jid, type: "unsubscribed"}); const pres = $pres({to: jid, type: "unsubscribed"});
if (message && message !== "") { pres.c("status").t(message); } if (message && message !== "") { pres.c("status").t(message); }
_converse.connection.send(pres); _converse.api.send(pres);
}; };
this.reconnect = _.debounce(function () { this.reconnect = _.debounce(function () {
...@@ -914,7 +914,7 @@ _converse.initialize = function (settings, callback) { ...@@ -914,7 +914,7 @@ _converse.initialize = function (settings, callback) {
}, },
sendPresence (type, status_message) { sendPresence (type, status_message) {
_converse.connection.send(this.constructPresence(type, status_message)); _converse.api.send(this.constructPresence(type, status_message));
} }
}); });
......
...@@ -333,7 +333,7 @@ converse.plugins.add('converse-disco', { ...@@ -333,7 +333,7 @@ converse.plugins.add('converse-disco', {
_.each(plugin._features, (feature) => { _.each(plugin._features, (feature) => {
iqresult.c('feature', {'var': feature}).up(); iqresult.c('feature', {'var': feature}).up();
}); });
_converse.connection.send(iqresult.tree()); _converse.api.send(iqresult.tree());
return true; return true;
} }
......
...@@ -278,7 +278,7 @@ converse.plugins.add('converse-muc', { ...@@ -278,7 +278,7 @@ converse.plugins.add('converse-muc', {
stanza.cnode(Strophe.xmlElement("password", [], password)); stanza.cnode(Strophe.xmlElement("password", [], password));
} }
this.save('connection_status', converse.ROOMSTATUS.CONNECTING); this.save('connection_status', converse.ROOMSTATUS.CONNECTING);
_converse.connection.send(stanza); _converse.api.send(stanza);
return this; return this;
}, },
...@@ -426,7 +426,7 @@ converse.plugins.add('converse-muc', { ...@@ -426,7 +426,7 @@ converse.plugins.add('converse-muc', {
// <gone/> is not applicable within MUC context // <gone/> is not applicable within MUC context
return; return;
} }
_converse.connection.send( _converse.api.send(
$msg({'to':this.get('jid'), 'type': 'groupchat'}) $msg({'to':this.get('jid'), 'type': 'groupchat'})
.c(chat_state, {'xmlns': Strophe.NS.CHATSTATES}).up() .c(chat_state, {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('no-store', {'xmlns': Strophe.NS.HINTS}).up() .c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
...@@ -462,12 +462,12 @@ converse.plugins.add('converse-muc', { ...@@ -462,12 +462,12 @@ converse.plugins.add('converse-muc', {
if (this.get('password')) { attrs.password = this.get('password'); } if (this.get('password')) { attrs.password = this.get('password'); }
const invitation = $msg({ const invitation = $msg({
from: _converse.connection.jid, 'from': _converse.connection.jid,
to: recipient, 'to': recipient,
id: _converse.connection.getUniqueId() 'id': _converse.connection.getUniqueId()
}).c('x', attrs); }).c('x', attrs);
_converse.connection.send(invitation); _converse.api.send(invitation);
_converse.emit('roomInviteSent', { _converse.api.emit('roomInviteSent', {
'room': this, 'room': this,
'recipient': recipient, 'recipient': recipient,
'reason': reason 'reason': reason
......
...@@ -268,7 +268,7 @@ converse.plugins.add('converse-roster', { ...@@ -268,7 +268,7 @@ converse.plugins.add('converse-roster', {
if (nick) { if (nick) {
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); 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. this.save('ask', "subscribe"); // ask === 'subscribe' Means we have asked to subscribe to them.
return this; return this;
}, },
...@@ -279,7 +279,7 @@ converse.plugins.add('converse-roster', { ...@@ -279,7 +279,7 @@ converse.plugins.add('converse-roster', {
* state notification by sending a presence stanza of type * state notification by sending a presence stanza of type
* "subscribe" to the contact * "subscribe" to the contact
*/ */
_converse.connection.send($pres({ _converse.api.send($pres({
'type': 'subscribe', 'type': 'subscribe',
'to': this.get('jid') 'to': this.get('jid')
})); }));
...@@ -294,7 +294,7 @@ converse.plugins.add('converse-roster', { ...@@ -294,7 +294,7 @@ converse.plugins.add('converse-roster', {
* Parameters: * Parameters:
* (String) jid - The Jabber ID of the user who is unsubscribing * (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.removeFromRoster();
this.destroy(); this.destroy();
}, },
...@@ -317,7 +317,7 @@ converse.plugins.add('converse-roster', { ...@@ -317,7 +317,7 @@ converse.plugins.add('converse-roster', {
if (message && message !== "") { if (message && message !== "") {
pres.c("status").t(message); pres.c("status").t(message);
} }
_converse.connection.send(pres); _converse.api.send(pres);
return this; return this;
}, },
...@@ -546,7 +546,7 @@ converse.plugins.add('converse-roster', { ...@@ -546,7 +546,7 @@ converse.plugins.add('converse-roster', {
// user's bare JID <user@domainpart>. // user's bare JID <user@domainpart>.
return; 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(); const query = sizzle(`query[xmlns="${Strophe.NS.ROSTER}"]`, iq).pop();
this.data.save('version', query.getAttribute('ver')); this.data.save('version', query.getAttribute('ver'));
......
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