浏览代码

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.
JC Brand 9 年之前
父节点
当前提交
f60a0512d9
共有 3 个文件被更改,包括 25 次插入8 次删除
  1. 13 1
      docs/source/development.rst
  2. 2 0
      src/converse-core.js
  3. 10 7
      src/converse-rosterview.js

+ 13 - 1
docs/source/development.rst

@@ -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
 ~~~~~~~~~~
 

+ 2 - 0
src/converse-core.js

@@ -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);
             }
         };

+ 10 - 7
src/converse-rosterview.js

@@ -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();
+                                        }
                                     }
                                 }
                             });