Commit 68d4a71c authored by JC Brand's avatar JC Brand

Fix `_converse.api.user.login` to handle auto_login case

Also, set the resource in `setUserJID`
parent 3c6a17f8
...@@ -552,6 +552,10 @@ async function initUserSession (jid) { ...@@ -552,6 +552,10 @@ async function initUserSession (jid) {
} }
function setUserJID (jid) { function setUserJID (jid) {
if (!Strophe.getResourceFromJid(jid)) {
jid = jid.toLowerCase() + _converse.generateResource();
}
jid = jid.toLowerCase();
initUserSession(jid); initUserSession(jid);
_converse.jid = jid; _converse.jid = jid;
_converse.bare_jid = Strophe.getBareJidFromJid(jid); _converse.bare_jid = Strophe.getBareJidFromJid(jid);
...@@ -1539,15 +1543,13 @@ _converse.api = { ...@@ -1539,15 +1543,13 @@ _converse.api = {
_converse.attemptPreboundSession(reconnecting); _converse.attemptPreboundSession(reconnecting);
} else { } else {
let credentials; let credentials;
if (jid) { if (jid && password) {
const resource = Strophe.getResourceFromJid(jid);
if (!resource) {
jid = jid.toLowerCase() + _converse.generateResource();
} else {
jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+resource;
}
setUserJID(jid);
credentials = {'jid': jid, 'password': password}; credentials = {'jid': jid, 'password': password};
} else if (u.isValidJID(_converse.jid) && _converse.password) {
credentials = {'jid': _converse.jid, 'password': _converse.password};
}
if (credentials && credentials.jid) {
setUserJID(credentials.jid);
} }
_converse.attemptNonPreboundSession(credentials, reconnecting); _converse.attemptNonPreboundSession(credentials, reconnecting);
} }
......
...@@ -74,7 +74,10 @@ u.prefixMentions = function (message) { ...@@ -74,7 +74,10 @@ u.prefixMentions = function (message) {
}; };
u.isValidJID = function (jid) { u.isValidJID = function (jid) {
if (_.isString(jid)) {
return _.compact(jid.split('@')).length === 2 && !jid.startsWith('@') && !jid.endsWith('@'); return _.compact(jid.split('@')).length === 2 && !jid.startsWith('@') && !jid.endsWith('@');
}
return false;
}; };
u.isValidMUCJID = function (jid) { u.isValidMUCJID = function (jid) {
......
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