Commit 1bc9a7f8 authored by JC Brand's avatar JC Brand

Ensure JID is set when `userSessionInitialized` triggers.

Otherwise `converse.features` cache id contains `null` instead of the
user JID and it doesn't clear correctly.
parent f0f7cfab
......@@ -567,6 +567,9 @@ converse.plugins.add('converse-controlbox', {
}
});
/******************** Event Handlers ********************/
_converse.api.listen.on('chatBoxViewsInitialized', () => {
_converse.chatboxes.on('add', item => {
if (item.get('type') === _converse.CONTROLBOX_TYPE) {
......@@ -627,7 +630,8 @@ converse.plugins.add('converse-controlbox', {
});
/************************ BEGIN API ************************/
/************************ API ************************/
Object.assign(_converse.api, {
/**
* The "controlbox" namespace groups methods pertaining to the
......
......@@ -572,7 +572,7 @@ _converse.initConnection = async function () {
};
async function initUserSession (jid) {
async function setUserJID (jid) {
const bare_jid = Strophe.getBareJidFromJid(jid).toLowerCase();
const id = `converse.session-${bare_jid}`;
if (!_converse.session || _converse.session.get('id') !== id) {
......@@ -583,6 +583,7 @@ async function initUserSession (jid) {
_converse.session.clear();
_converse.session.save({'id': id});
}
saveJIDtoSession(jid);
/**
* Triggered once the user's session has been initialized. The session is a
* cache which stores information about the user's current session.
......@@ -590,11 +591,18 @@ async function initUserSession (jid) {
* @memberOf _converse
*/
_converse.api.trigger('userSessionInitialized');
} else {
saveJIDtoSession(jid);
}
/**
* Triggered whenever the user's JID has been updated
* @event _converse#setUserJID
*/
_converse.api.trigger('setUserJID');
return jid;
}
async function setUserJID (jid) {
await initUserSession(jid);
function saveJIDtoSession (jid) {
jid = _converse.session.get('jid') || jid;
if (_converse.authentication !== _converse.ANONYMOUS && !Strophe.getResourceFromJid(jid)) {
jid = jid.toLowerCase() + _converse.generateResource();
......@@ -603,7 +611,6 @@ async function setUserJID (jid) {
// `connection.bind` the new resource is found by Strophe.js
// and sent to the XMPP server.
_converse.connection.jid = jid;
_converse.jid = jid;
_converse.bare_jid = Strophe.getBareJidFromJid(jid);
_converse.resource = Strophe.getResourceFromJid(jid);
......@@ -615,12 +622,6 @@ async function setUserJID (jid) {
'domain': _converse.domain,
'active': true
});
/**
* Triggered whenever the user's JID has been updated
* @event _converse#setUserJID
*/
_converse.api.trigger('setUserJID');
return jid;
}
......
......@@ -293,6 +293,42 @@ converse.plugins.add('converse-disco', {
}
}
const plugin = this;
plugin._identities = [];
plugin._features = [];
function onDiscoInfoRequest (stanza) {
const node = stanza.getElementsByTagName('query')[0].getAttribute('node');
const attrs = {xmlns: Strophe.NS.DISCO_INFO};
if (node) { attrs.node = node; }
const iqresult = $iq({'type': 'result', 'id': stanza.getAttribute('id')});
const from = stanza.getAttribute('from');
if (from !== null) {
iqresult.attrs({'to': from});
}
iqresult.c('query', attrs);
_.each(plugin._identities, (identity) => {
const attrs = {
'category': identity.category,
'type': identity.type
};
if (identity.name) {
attrs.name = identity.name;
}
if (identity.lang) {
attrs['xml:lang'] = identity.lang;
}
iqresult.c('identity', attrs).up();
});
_.each(plugin._features, (feature) => {
iqresult.c('feature', {'var': feature}).up();
});
_converse.api.send(iqresult.tree());
return true;
}
async function initializeDisco () {
addClientFeatures();
_converse.connection.addHandler(onDiscoInfoRequest, Strophe.NS.DISCO_INFO, 'iq', 'get', null, null);
......@@ -318,6 +354,8 @@ converse.plugins.add('converse-disco', {
_converse.api.trigger('discoInitialized');
}
/******************** Event Handlers ********************/
_converse.api.listen.on('userSessionInitialized', initStreamFeatures);
_converse.api.listen.on('beforeResourceBinding', initStreamFeatures);
......@@ -334,46 +372,13 @@ converse.plugins.add('converse-disco', {
_converse.disco_entities.browserStorage._clear();
}
if (_converse.stream_features) {
_converse.stream_features.reset();
Array.from(_converse.stream_features.models).forEach(f => f.destroy());
_converse.stream_features.browserStorage._clear();
}
});
const plugin = this;
plugin._identities = [];
plugin._features = [];
function onDiscoInfoRequest (stanza) {
const node = stanza.getElementsByTagName('query')[0].getAttribute('node');
const attrs = {xmlns: Strophe.NS.DISCO_INFO};
if (node) { attrs.node = node; }
const iqresult = $iq({'type': 'result', 'id': stanza.getAttribute('id')});
const from = stanza.getAttribute('from');
if (from !== null) {
iqresult.attrs({'to': from});
}
iqresult.c('query', attrs);
_.each(plugin._identities, (identity) => {
const attrs = {
'category': identity.category,
'type': identity.type
};
if (identity.name) {
attrs.name = identity.name;
}
if (identity.lang) {
attrs['xml:lang'] = identity.lang;
}
iqresult.c('identity', attrs).up();
});
_.each(plugin._features, (feature) => {
iqresult.c('feature', {'var': feature}).up();
});
_converse.api.send(iqresult.tree());
return true;
}
/************************ API ************************/
Object.assign(_converse.api, {
/**
......
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