Commit b176161e authored by JC Brand's avatar JC Brand

converse-roster: Reconnection bugfixes.

Don't remove cached presences in `afterTearDown` event.
We might reconnect again and resume the session, in which case we need
that data still.

Instead, we remove cached presences when `clearSession` fires, because
then we know we're not reconnecting.

When reconnecting, we don't fetch presences from cache, we still have
them (since we no longer remove them in `afterTearDown`).

When reconnecting and not resuming, we clear the presences from cache,
since we're starting a new session.
parent 3dc2b2b6
......@@ -941,19 +941,17 @@ converse.plugins.add('converse-roster', {
});
});
_converse.api.listen.on('afterTearDown', () => {
function clearPresences () {
if (_converse.presences) {
_converse.presences.each(p => {
_converse.presences.forEach(p => {
p.resources.reject(r => r === undefined).forEach(r => r.destroy({'silent': true}));
p.save({'show': 'offline'}, {'silent': true})
});
_converse.presences.clearSession();
}
});
}
_converse.api.listen.on('clearSession', () => {
if (_converse.presences) {
_converse.presences.browserStorage._clear();
}
clearPresences();
if (_converse.shouldClearCache()) {
if (_converse.roster) {
_.invoke(_converse, 'roster.data.destroy');
......@@ -969,16 +967,18 @@ converse.plugins.add('converse-roster', {
});
_converse.api.listen.on('statusInitialized', (reconnecting) => {
if (!reconnecting) {
if (reconnecting) {
// When reconnecting and not resuming a previous session,
// we clear all cached presence data, since it might be stale
// and we'll receive new presence updates
!_converse.haveResumed() && clearPresences();
} else {
_converse.presences = new _converse.Presences();
}
_converse.presences.browserStorage =
new BrowserStorage.session(`converse.presences-${_converse.bare_jid}`);
if (_converse.haveResumed()) {
const id = `converse.presences-${_converse.bare_jid}`;
_converse.presences.browserStorage = new BrowserStorage.session(id);
// We might be continuing an existing session, so we fetch
// cached presence data.
_converse.presences.fetch();
} else {
_converse.presences.clearSession();
}
/**
* Triggered once the _converse.Presences collection has been
......
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