1
0
Fork 0

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

master
Matthieu Lalonde 14 years ago committed by xSmurf
parent ef0fadde29
commit 0c275f54ad

@ -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());

@ -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) {

@ -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")

Loading…
Cancel
Save