Browse Source

Don't unnecessarily fetch the roster

If we've fetched the roster before within this session, then we don't
have to do so again, regardless of whether versioning is supported or
not, otherwise, even if we have a cached roster, we still need to get
the latest one again.
JC Brand 6 years ago
parent
commit
3b29e5754d
4 changed files with 12 additions and 3 deletions
  1. 3 0
      spec/converse.js
  2. 3 0
      spec/http-file-upload.js
  3. 3 1
      spec/notification.js
  4. 3 2
      src/headless/converse-roster.js

+ 3 - 0
spec/converse.js

@@ -217,6 +217,9 @@
             it("has a method 'get' which returns wrapped contacts", mock.initConverse(async (done, _converse) => {
                 // Check that it returns nothing if a non-existing JID is given
                 test_utils.createContacts(_converse, 'current');
+                // Hack to avoid having to fetch the roster again.
+                _converse.session.set('roster_fetched', true);
+
                 let contact = await _converse.api.contacts.get('non-existing@jabber.org');
                 expect(contact).toBeFalsy();
                 // Check when a single jid is given

+ 3 - 0
spec/http-file-upload.js

@@ -173,6 +173,9 @@
                 it("does not appear in private chats", mock.initConverse(async (done, _converse) => {
                     var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
                     test_utils.createContacts(_converse, 'current');
+                    // Hack to avoid having to fetch the roster again.
+                    _converse.session.set('roster_fetched', true);
+
                     test_utils.openChatBoxFor(_converse, contact_jid);
 
                     await test_utils.waitUntilDiscoConfirmed(

+ 3 - 1
spec/notification.js

@@ -20,8 +20,10 @@
                             async (done, _converse) => {
 
                         // TODO: not yet testing show_desktop_notifications setting
-                        test_utils.createContacts(_converse, 'current');
                         await test_utils.createContacts(_converse, 'current');
+                        // Hack to avoid having to fetch the roster again.
+                        _converse.session.set('roster_fetched', true);
+
                         spyOn(_converse, 'showMessageNotification').and.callThrough();
                         spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
                         spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);

+ 3 - 2
src/headless/converse-roster.js

@@ -464,9 +464,10 @@ converse.plugins.add('converse-roster', {
                         });
                     });
                 } catch (e) {
-                    return _converse.log(e, Strophe.LogLevel.ERROR);
+                    _converse.log(e, Strophe.LogLevel.ERROR);
+                    _converse.session.set('roster_fetched', false)
                 }
-                if (collection.length || (this.rosterVersioningSupported() && _converse.session.get('roster_fetched'))) {
+                if (_converse.session.get('roster_fetched')) {
                     /**
                      * The contacts roster has been retrieved from the local cache (`sessionStorage`).
                      * @event _converse#cachedRoster