Commit 1c961ab4 authored by JC Brand's avatar JC Brand

Emit an event `presence` when a presence stanza is received.

parent ff41e085
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
## 0.11.0 (Unreleased) ## 0.11.0 (Unreleased)
- Emit an event `presence` when a presence stanza is received. [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] - Split converse.js up into different plugin modules. [jcbrand]
- Don't play sound notifications for OTR messages which are setting up an - Don't play sound notifications for OTR messages which are setting up an
encrypted session. [jcbrand] encrypted session. [jcbrand]
......
...@@ -770,21 +770,23 @@ Here are the different events that are emitted: ...@@ -770,21 +770,23 @@ Here are the different events that are emitted:
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **chatBoxToggled** | When a chat box has been minimized or maximized. Relevant to converse-chatview.js plugin. | ``converse.listen.on('chatBoxToggled', function (event, chatbox) { ... });`` | | **chatBoxToggled** | When a chat box has been minimized or maximized. Relevant to converse-chatview.js plugin. | ``converse.listen.on('chatBoxToggled', function (event, chatbox) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **connected** | After connection has been established and converse.js has got all its ducks in a row. | ``converse.listen.on('connected', function (event) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **contactRequest** | Someone has requested to subscribe to your presence (i.e. to be your contact). | ``converse.listen.on('contactRequest', function (event, user_data) { ... });`` | | **contactRequest** | Someone has requested to subscribe to your presence (i.e. to be your contact). | ``converse.listen.on('contactRequest', function (event, user_data) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **contactStatusChanged** | When a chat buddy's chat status has changed. | ``converse.listen.on('contactStatusChanged', function (event, buddy) { ... });`` | | **contactStatusChanged** | When a chat buddy's chat status has changed. | ``converse.listen.on('contactStatusChanged', function (event, buddy) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **contactStatusMessageChanged** | When a chat buddy's custom status message has changed. | ``converse.listen.on('contactStatusMessageChanged', function (event, data) { ... });`` | | **contactStatusMessageChanged** | When a chat buddy's custom status message has changed. | ``converse.listen.on('contactStatusMessageChanged', function (event, data) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **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) { ... });`` | | **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) { ... });`` | | **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) { ... });`` | | **noResumeableSession** | When keepalive=true but there aren't any stored prebind tokens. | ``converse.listen.on('noResumeableSession', function (event) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **initialized** | Once converse.js has been initialized. | ``converse.listen.on('initialized', function (event) { ... });`` | | **presence** | A presence stanza has been received. | ``converse.listen.on('presence', function (event, presenceStanza) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **connected** | After connection has been established and converse.js has got all its ducks in a row. | ``converse.listen.on('connected', function (event) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| **reconnect** | After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode. | ``converse.listen.on('reconnect', function (event) { ... });`` | | **reconnect** | After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode. | ``converse.listen.on('reconnect', function (event) { ... });`` |
+---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ +---------------------------------+---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
......
...@@ -1143,10 +1143,19 @@ ...@@ -1143,10 +1143,19 @@
status_message = $presence.find('status'), status_message = $presence.find('status'),
contact = this.get(bare_jid); contact = this.get(bare_jid);
if (this.isSelf(bare_jid)) { if (this.isSelf(bare_jid)) {
if ((converse.connection.jid !== jid)&&(presence_type !== 'unavailable')&&(converse.synchronize_availability === true || converse.synchronize_availability === resource)) { if ((converse.connection.jid !== jid) &&
// Another resource has changed its status and synchronize_availability option let to update, we'll update ours as well. (presence_type !== 'unavailable') &&
(converse.synchronize_availability === true ||
converse.synchronize_availability === resource)) {
// Another resource has changed its status and
// synchronize_availability option set to update,
// we'll update ours as well.
converse.xmppstatus.save({'status': chat_status}); converse.xmppstatus.save({'status': chat_status});
if (status_message.length) { converse.xmppstatus.save({'status_message': status_message.text()}); } if (status_message.length) {
converse.xmppstatus.save({
'status_message': status_message.text()
});
}
} }
return; return;
} else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) { } else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) {
...@@ -1173,6 +1182,7 @@ ...@@ -1173,6 +1182,7 @@
this.addResource(bare_jid, resource); this.addResource(bare_jid, resource);
contact.save({'chat_status': chat_status}); contact.save({'chat_status': chat_status});
} }
converse.emit('presence', presence);
} }
}); });
......
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