Emit an event when the roster is fetched from the cache

We already emit an event when the roster is fetched from the XMPP server,
similarly, it would be useful to know when the roster was instead fetched from
the cache.
This commit is contained in:
JC Brand 2016-06-01 16:01:09 +00:00
parent f9528e7144
commit f60a0512d9
3 changed files with 25 additions and 8 deletions

View File

@ -798,6 +798,15 @@ Event Types
Here are the different events that are emitted:
cachedRoster
~~~~~~~~~~~~
The contacts roster has been retrieved from the local cache (`sessionStorage`).
``converse.listen.on('cachedRoster', function (event, items) { ... });``
See also the `roster` event further down.
callButtonClicked
~~~~~~~~~~~~~~~~~
@ -937,10 +946,13 @@ After the user has sent out a direct invitation, to a roster contact, asking the
roster
~~~~~~
When the roster is updated.
When the roster has been received from the XMPP server.
``converse.listen.on('roster', function (event, items) { ... });``
See also the `cachedRoster` event further up, which gets called instead of
`roster` if its already in `sessionStorage`.
rosterPush
~~~~~~~~~~

View File

@ -358,6 +358,8 @@
}
if (converse.auto_changed_status === true) {
converse.auto_changed_status = false;
// XXX: we should really remember the original state here, and
// then set it back to that...
converse.xmppstatus.setStatus(converse.default_state);
}
};

View File

@ -294,13 +294,16 @@
*/
converse.roster.fetchFromServer(
converse.xmppstatus.sendPresence.bind(converse.xmppstatus));
} else if (converse.send_initial_presence) {
/* We're not going to fetch the roster again because we have
* it already cached in sessionStorage, but we still need to
* send out a presence stanza because this is a new session.
* See: https://github.com/jcbrand/converse.js/issues/536
*/
converse.xmppstatus.sendPresence();
} else {
converse.emit('cachedRoster', collection);
if (converse.send_initial_presence) {
/* We're not going to fetch the roster again because we have
* it already cached in sessionStorage, but we still need to
* send out a presence stanza because this is a new session.
* See: https://github.com/jcbrand/converse.js/issues/536
*/
converse.xmppstatus.sendPresence();
}
}
}
});