Refetch the roster from the server after reconnection.
From the perspective of the XMPP server, this is an entirely new login, and therefore as per RFC-6121 the roster SHOULD be queried, making the client an "interested resource". https://tools.ietf.org/html/rfc6121#section-2
This commit is contained in:
parent
0a7c20a1e2
commit
9862d747a9
@ -736,17 +736,31 @@
|
|||||||
_converse.emit('rosterInitialized');
|
_converse.emit('rosterInitialized');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.populateRoster = function () {
|
this.populateRoster = function (ignore_cache=false) {
|
||||||
/* Fetch all the roster groups, and then the roster contacts.
|
/* Fetch all the roster groups, and then the roster contacts.
|
||||||
* Emit an event after fetching is done in each case.
|
* Emit an event after fetching is done in each case.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (Bool) ignore_cache - If set to to true, the local cache
|
||||||
|
* will be ignored it's guaranteed that the XMPP server
|
||||||
|
* will be queried for the roster.
|
||||||
*/
|
*/
|
||||||
_converse.rostergroups.fetchRosterGroups().then(function () {
|
if (ignore_cache) {
|
||||||
_converse.emit('rosterGroupsFetched');
|
_converse.send_initial_presence = true;
|
||||||
_converse.roster.fetchRosterContacts().then(function () {
|
_converse.roster.fetchFromServer()
|
||||||
|
.then(_converse.sendInitialPresence)
|
||||||
|
.catch(_converse.sendInitialPresence);
|
||||||
|
} else {
|
||||||
|
_converse.rostergroups.fetchRosterGroups().then(() => {
|
||||||
|
_converse.emit('rosterGroupsFetched');
|
||||||
|
return _converse.roster.fetchRosterContacts();
|
||||||
|
}).then(() => {
|
||||||
_converse.emit('rosterContactsFetched');
|
_converse.emit('rosterContactsFetched');
|
||||||
_converse.sendInitialPresence();
|
_converse.sendInitialPresence();
|
||||||
|
}).catch(() => {
|
||||||
|
_converse.sendInitialPresence();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.unregisterPresenceHandler = function () {
|
this.unregisterPresenceHandler = function () {
|
||||||
@ -788,11 +802,9 @@
|
|||||||
_converse.initRoster();
|
_converse.initRoster();
|
||||||
}
|
}
|
||||||
_converse.roster.onConnected();
|
_converse.roster.onConnected();
|
||||||
_converse.populateRoster();
|
_converse.populateRoster(reconnecting);
|
||||||
_converse.registerPresenceHandler();
|
_converse.registerPresenceHandler();
|
||||||
if (reconnecting) {
|
if (!reconnecting) {
|
||||||
_converse.xmppstatus.sendPresence();
|
|
||||||
} else {
|
|
||||||
init_promise.resolve();
|
init_promise.resolve();
|
||||||
_converse.emit('initialized');
|
_converse.emit('initialized');
|
||||||
}
|
}
|
||||||
@ -1086,14 +1098,8 @@
|
|||||||
add: true,
|
add: true,
|
||||||
success (collection) {
|
success (collection) {
|
||||||
if (collection.length === 0) {
|
if (collection.length === 0) {
|
||||||
/* We don't have any roster contacts stored in sessionStorage,
|
|
||||||
* so lets fetch the roster from the XMPP server. We pass in
|
|
||||||
* 'sendPresence' as callback method, because after initially
|
|
||||||
* fetching the roster we are ready to receive presence
|
|
||||||
* updates from our contacts.
|
|
||||||
*/
|
|
||||||
_converse.send_initial_presence = true;
|
_converse.send_initial_presence = true;
|
||||||
_converse.roster.fetchFromServer(resolve);
|
_converse.roster.fetchFromServer().then(resolve).catch(reject);
|
||||||
} else {
|
} else {
|
||||||
_converse.emit('cachedRoster', collection);
|
_converse.emit('cachedRoster', collection);
|
||||||
resolve();
|
resolve();
|
||||||
@ -1244,13 +1250,21 @@
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchFromServer (callback) {
|
fetchFromServer () {
|
||||||
/* Get the roster from the XMPP server */
|
/* Fetch the roster from the XMPP server */
|
||||||
const iq = $iq({type: 'get', 'id': _converse.connection.getUniqueId('roster')})
|
return new Promise((resolve, reject) => {
|
||||||
.c('query', {xmlns: Strophe.NS.ROSTER});
|
const iq = $iq({
|
||||||
return _converse.connection.sendIQ(iq, (iq) => {
|
'type': 'get',
|
||||||
this.onReceivedFromServer(iq);
|
'id': _converse.connection.getUniqueId('roster')
|
||||||
callback.apply(this, arguments);
|
}).c('query', {xmlns: Strophe.NS.ROSTER});
|
||||||
|
|
||||||
|
const callback = _.flow(this.onReceivedFromServer.bind(this), resolve);
|
||||||
|
const errback = function (iq) {
|
||||||
|
const errmsg = "Error while trying to fetch roster from the server";
|
||||||
|
_converse.log(errmsg, Strophe.LogLevel.ERROR);
|
||||||
|
reject(new Error(errmsg));
|
||||||
|
}
|
||||||
|
return _converse.connection.sendIQ(iq, callback, errback);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user