Commit f21abc60 authored by JC Brand's avatar JC Brand

roster: Only fetch from browser storage if already cached

parent 358187f8
......@@ -44,10 +44,6 @@
`<iq from="romeo@montague.lit/orchard" id="${iq.getAttribute('id')}" to="romeo@montague.lit" type="get" xmlns="jabber:client">`+
`<query xmlns="http://jabber.org/protocol/disco#info"/></iq>`);
iq = IQ_stanzas.pop();
expect(Strophe.serialize(iq)).toBe(
`<iq id="${iq.getAttribute('id')}" type="get" xmlns="jabber:client"><query xmlns="jabber:iq:roster"/></iq>`);
iq = IQ_stanzas.pop();
expect(Strophe.serialize(iq)).toBe(
`<iq from="romeo@montague.lit/orchard" id="${iq.getAttribute('id')}" to="montague.lit" type="get" xmlns="jabber:client">`+
......@@ -58,6 +54,10 @@
`<iq from="romeo@montague.lit" id="${disco_iq.getAttribute('id')}" to="romeo@montague.lit" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub"><items node="eu.siacs.conversations.axolotl.devicelist"/></pubsub></iq>`);
iq = IQ_stanzas.pop();
expect(Strophe.serialize(iq)).toBe(
`<iq id="${iq.getAttribute('id')}" type="get" xmlns="jabber:client"><query xmlns="jabber:iq:roster"/></iq>`);
expect(sent_stanzas.filter(s => (s.nodeName === 'r')).length).toBe(2);
expect(_converse.session.get('unacked_stanzas').length).toBe(4);
......@@ -118,9 +118,9 @@
`<iq from="romeo@montague.lit/orchard" id="${iq.getAttribute('id')}" to="romeo@montague.lit" type="get" xmlns="jabber:client">`+
`<query xmlns="http://jabber.org/protocol/disco#info"/></iq>`);
iq = IQ_stanzas.pop();
expect(Strophe.serialize(iq)).toBe(
`<iq id="${iq.getAttribute('id')}" type="get" xmlns="jabber:client"><query xmlns="jabber:iq:roster"/></iq>`);
// We don't fetch the roster again because it's cached.
expect(_converse.session.get('roster_fetched')).toBeFalsy();
expect(IQ_stanzas.filter(iq => sizzle('query[xmlns="jabber:iq:roster"]', iq).pop()).length).toBe(0);
await _converse.api.waitUntil('statusInitialized');
done();
......
......@@ -438,33 +438,33 @@ converse.plugins.add('converse-roster', {
* @returns {promise} Promise which resolves once the contacts have been fetched.
*/
async fetchRosterContacts () {
let collection;
try {
collection = await new Promise((resolve, reject) => {
if (_converse.session.get('roster_fetched')) {
const result = await new Promise((resolve, reject) => {
this.fetch({
'add': true,
'silent': true,
'success': resolve,
'error': (m, e) => reject(e)
'error': (c, e) => reject(e)
});
});
} catch (e) {
_converse.log(e, Strophe.LogLevel.ERROR);
_converse.session.set('roster_fetched', false)
}
if (_converse.session.get('roster_fetched')) {
/**
* The contacts roster has been retrieved from the local cache (`sessionStorage`).
* @event _converse#cachedRoster
* @type { _converse.RosterContacts }
* @example _converse.api.listen.on('cachedRoster', (items) => { ... });
* @example _converse.api.waitUntil('cachedRoster').then(items => { ... });
*/
_converse.api.trigger('cachedRoster', collection);
} else {
_converse.send_initial_presence = true;
return _converse.roster.fetchFromServer();
if (u.isErrorObject(result)) {
_converse.log(result, Strophe.LogLevel.ERROR);
_converse.session.set('roster_fetched', false)
} else {
/**
* The contacts roster has been retrieved from the local cache (`sessionStorage`).
* @event _converse#cachedRoster
* @type { _converse.RosterContacts }
* @example _converse.api.listen.on('cachedRoster', (items) => { ... });
* @example _converse.api.waitUntil('cachedRoster').then(items => { ... });
*/
_converse.api.trigger('cachedRoster', result);
return;
}
}
_converse.send_initial_presence = true;
return _converse.roster.fetchFromServer();
},
subscribeToSuggestedItems (msg) {
......
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