Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logout () {
const promise = u.getResolveablePromise();
const complete = () => {
// Recreate all the promises
Object.keys(_converse.promises).forEach(replacePromise);
/**
* Triggered once the user has logged out.
* @event _converse#logout
*/
_converse.api.trigger('logout');
promise.resolve();
}
_converse.setDisconnectionCause(_converse.LOGOUT, undefined, true);
if (_converse.connection !== undefined) {
_converse.api.listen.once('disconnected', () => complete());
_converse.connection.disconnect();
} else {
function replacePromise (name) {
const existing_promise = _converse.promises[name];
if (!existing_promise) {
throw new Error(`Tried to replace non-existing promise: ${name}`);
}
if (existing_promise.replace) {
const promise = u.getResolveablePromise();
promise.replace = existing_promise.replace;
_converse.promises[name] = promise;
} else {
log.debug(`Not replacing promise "${name}"`);
}
}
promises.forEach(name => {
const promise = u.getResolveablePromise();
promise.replace = replace;
_converse.promises[name] = promise;
});
}