From 0c275f54ad37a09fa2bb5d7c9ab803b1088f13f7 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Tue, 11 Jan 2011 10:26:23 -0500 Subject: [PATCH] Removed almost all the presence tracking code as it is not unused. We still keep track of presences to get the presences before the client is fully binded --- lib/xmpp-client/basic-client.js | 86 +++------------------------------ lib/xmpp-client/client.js | 9 +--- lib/xmpp-client/room.js | 5 -- 3 files changed, 7 insertions(+), 93 deletions(-) diff --git a/lib/xmpp-client/basic-client.js b/lib/xmpp-client/basic-client.js index babf2af..2540cdc 100644 --- a/lib/xmpp-client/basic-client.js +++ b/lib/xmpp-client/basic-client.js @@ -98,92 +98,18 @@ var BasicClient = function(params, callback) { try { // This is a presences for a conference if (stanza.attrs.from.indexOf('conference') === -1 || stanza.attrs.from.indexOf('conference') < stanza.attrs.from.indexOf('@')) { - if (stanza.attrs.from.toString().indexOf('/') > -1) { - var user = stanza.attrs.from.split('/')[0]; - var resource = stanza.attrs.from.substr(stanza.attrs.from.indexOf('/')+1); - } else { - var user = stanza.attrs.from.toString(); - var resource = "unknown"; - } - - if (typeof jabber.presences.users === "undefined" || jabber.presences.users === null) { - jabber.presences.users = {}; - } + var user = stanza.attrs.from.toString(); if (stanza.attrs.type === "unavailable") { - if (typeof jabber.presences.users[user] !== "undefined" && jabber.presences[user] !== null) { - delete jabber.presences[user][resource]; - - if (Object.keys(jabber.presences[user]).length === 0) { - delete jabber.presences[user]; - } + if (typeof jabber.presences[user] !== "undefined") { + delete jabber.presences[user]; } } else { - if (typeof jabber.presences.users[user] === "undefined") { - jabber.presences.users[user] = {}; - } - - if (typeof jabber.presences.users[user][resource] === "undefined") { - jabber.presences.users[user][resource] = {}; - newPresence = true; - } - - jabber.presences.users[user][resource] = { - user: user, - resource: resource, - jid: stanza.attrs.from, - priority: stanza.getChildText('priority'), - show: stanza.getChildText('show'), - status: stanza.getChildText('status') - }; + jabber.presences[user] = stanza; } - } else { - var conference = stanza.attrs.from.split('/')[0]; - var nickname = stanza.attrs.from.substr(stanza.attrs.from.indexOf('/')+1); - - // Kill self references - if (nickname === jabber.params.nickname) { - return false; - } - - if (stanza.attrs.type === "unavailable") { - delete jabber.presences.muc[conference][nickname]; - } else { - if (typeof jabber.presences.muc[conference] === "undefined") { - jabber.presences.muc[conference] = {}; - } - - if (typeof jabber.presences.muc[conference][nickname] === "undefined") { - jabber.presences.muc[conference][nickname] = {}; - newPresence = true; - } - - jabber.presences.muc[conference][nickname] = { - priority: stanza.getChildText("priority"), - show: stanza.getChildText("show"), - status: stanza.getChildText("status") - }; - - // Look to see if we have access to the user"s full details or if this is an anonymous room - if (typeof stanza.getChild("x", "http://jabber.org/protocol/muc#user") !== "undefined") { - var userDetails = stanza.getChild("x", "http://jabber.org/protocol/muc#user").getChild("item"); - - jabber.presences.muc[conference][nickname].affiliation = userDetails.attrs.affiliation; - jabber.presences.muc[conference][nickname].role = userDetails.attrs.role; - - if (typeof userDetails.attrs.jid !== "undefined") { - var user = userDetails.attrs.jid.split("/")[0]; - var resource = userDetails.attrs.jid.split("/")[1]; - - jabber.presences.muc[conference][nickname].jid = user; - jabber.presences.muc[conference][nickname].resource = resource; - } - } - } - } - - jabber.emit('presence', stanza, newPresence); + + jabber.emit('presence', stanza); } catch (err) { console.log("Something went wrong parsing presences: " + err.toString()); console.log(stanza.toString()); diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index 2b58478..e453356 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -10,9 +10,7 @@ var Client = function(params, callback) { var params = params; var xmpp = this.xmpp; this.roster = {}; - this.presences = {}; - this.presences.users = {}; - this.presences.muc = {}; + this.presences = {}; BasicClient.call(this, params, function() { this.presence("dnd", "Loading..."); @@ -52,11 +50,6 @@ var Client = function(params, callback) { sys.inherits(Client, BasicClient); exports.Client = Client; -Client.prototype.getPresences = function() -{ - return this.presences.users; -}; - Client.prototype.getRoster = function(callback) { var jabber = this; this.iq(null, new xmpp.Element('query', {xmlns: 'jabber:iq:roster'}), function(iq) { diff --git a/lib/xmpp-client/room.js b/lib/xmpp-client/room.js index e58d676..1463001 100644 --- a/lib/xmpp-client/room.js +++ b/lib/xmpp-client/room.js @@ -40,11 +40,6 @@ sys.inherits(Room, events.EventEmitter); exports.Room = Room; -Room.prototype.getPresences = function() -{ - return this.client.presences.muc; -}; - Room.prototype.presence = function(status, message) { if (typeof status === "undefined")