Commit 4e9e532a authored by JC Brand's avatar JC Brand

Use async/await in populateRoster

parent 37426024
......@@ -67805,7 +67805,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.emit('rosterInitialized');
};
_converse.populateRoster = function (ignore_cache = false) {
_converse.populateRoster = async function (ignore_cache = false) {
/* Fetch all the roster groups, and then the roster contacts.
* Emit an event after fetching is done in each case.
*
......@@ -67817,29 +67817,29 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
if (ignore_cache) {
_converse.send_initial_presence = true;
_converse.roster.fetchFromServer().then(() => {
_converse.emit('rosterContactsFetched');
try {
await _converse.roster.fetchFromServer();
_converse.sendInitialPresence();
}).catch(reason => {
_converse.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
_converse.sendInitialPresence();
});
}
} else {
_converse.rostergroups.fetchRosterGroups().then(() => {
_converse.emit('rosterGroupsFetched');
try {
await _converse.rostergroups.fetchRosterGroups().then(() => {
_converse.emit('rosterGroupsFetched');
return _converse.roster.fetchRosterContacts();
}).then(() => {
_converse.emit('rosterContactsFetched');
return _converse.roster.fetchRosterContacts();
});
_converse.sendInitialPresence();
}).catch(reason => {
_converse.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
_converse.sendInitialPresence();
});
}
}
};
......@@ -68,7 +68,7 @@ converse.plugins.add('converse-roster', {
};
_converse.populateRoster = function (ignore_cache=false) {
_converse.populateRoster = async function (ignore_cache=false) {
/* Fetch all the roster groups, and then the roster contacts.
* Emit an event after fetching is done in each case.
*
......@@ -79,25 +79,26 @@ converse.plugins.add('converse-roster', {
*/
if (ignore_cache) {
_converse.send_initial_presence = true;
_converse.roster.fetchFromServer()
.then(() => {
_converse.emit('rosterContactsFetched');
_converse.sendInitialPresence();
}).catch((reason) => {
_converse.log(reason, Strophe.LogLevel.ERROR);
_converse.sendInitialPresence();
});
} else {
_converse.rostergroups.fetchRosterGroups().then(() => {
_converse.emit('rosterGroupsFetched');
return _converse.roster.fetchRosterContacts();
}).then(() => {
try {
await _converse.roster.fetchFromServer();
_converse.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
_converse.sendInitialPresence();
}).catch((reason) => {
}
} else {
try {
await _converse.rostergroups.fetchRosterGroups().then(() => {
_converse.emit('rosterGroupsFetched');
return _converse.roster.fetchRosterContacts();
});
_converse.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
_converse.sendInitialPresence();
});
}
}
};
......
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