From c9cf028c752e703d7d372961b949615c9031597f Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 17 Oct 2012 11:51:04 +0200 Subject: [PATCH] Improved the presence handling when auto-subscribe is on. --- converse.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/converse.js b/converse.js index 19abc04e4..126f4e6b6 100644 --- a/converse.js +++ b/converse.js @@ -911,6 +911,8 @@ }, this)); return; } + } else if (!view.isVisible()) { + this.showChat(bare_jid); } view.messageReceived(message); xmppchat.roster.addResource(bare_jid, resource); @@ -1219,13 +1221,24 @@ item = this.getItem(bare_jid); if (xmppchat.auto_subscribe) { - //XXX: Probably need to get fullname support here... - xmppchat.connection.roster.authorize(bare_jid); - if (!(item) || (item.get('subscription') == 'none')) { - // Subscribe back - xmppchat.connection.roster.add(jid, name, [], function (iq) { - xmppchat.connection.roster.subscribe(jid); - }); + if ((!item) || (item.get('subscription') != 'to')) { + if (xmppchat.connection.roster.get(jid)) { + $.getJSON(portal_url + "/xmpp-userinfo?user_id=" + Strophe.getNodeFromJid(jid), $.proxy(function (data) { + xmppchat.connection.roster.update(jid, data.fullname, [], function (iq) { + xmppchat.connection.roster.authorize(bare_jid); + xmppchat.connection.roster.subscribe(jid); + }); + }, this)); + } else { + $.getJSON(portal_url + "/xmpp-userinfo?user_id=" + Strophe.getNodeFromJid(jid), $.proxy(function (data) { + xmppchat.connection.roster.add(jid, data.fullname, [], function (iq) { + xmppchat.connection.roster.authorize(bare_jid); + xmppchat.connection.roster.subscribe(jid); + }); + }, this)); + } + } else { + xmppchat.connection.roster.authorize(bare_jid); } } else { if ((item) && (item.get('subscription') != 'none')) { @@ -1269,7 +1282,9 @@ } else { if (this.removeResource(bare_jid, resource) === 0) { model = this.getItem(bare_jid); - model.set({'presence_type': presence_type}); + if (model) { + model.set({'presence_type': presence_type}); + } } } }