Add isOwnUser method. Return the number of resources left when removing one.

This commit is contained in:
JC Brand 2012-06-24 12:06:37 +02:00
parent 440900626d
commit 0935fd62f1

15
chat.js
View File

@ -36,6 +36,10 @@ var xmppchat = (function (jarnxmpp, $, console) {
ob.Messages = jarnxmpp.Messages || {};
ob.Presence = jarnxmpp.Presence || {};
ob.isOwnUser = function (jid) {
return (Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(xmppchat.connection.jid));
};
ob.ChatPartners = (function () {
/* A mapping of bare JIDs to resources, to keep track of
* how many resources we have per chat partner.
@ -54,19 +58,30 @@ var xmppchat = (function (jarnxmpp, $, console) {
};
methods.remove = function (bare_jid, resource) {
// Removes the resource for a user and returns the number of
// resources left over.
if (Object.prototype.hasOwnProperty.call(storage, bare_jid)) {
if (!(resource in helpers.oc(storage[bare_jid]))) {
var idx = storage[bare_jid].indexOf(resource);
if (idx !== undefined) {
storage[bare_jid].splice(idx, 1);
if (storage[bare_jid].length === 0) {
delete storage[bare_jid];
return 0;
}
else {
return storage[bare_jid].length;
}
}
}
}
return 0;
};
methods.getTotal = function () {
return helpers.size(storage);
};
return methods;
})();