Add isOwnUser method. Return the number of resources left when removing one.
This commit is contained in:
parent
440900626d
commit
0935fd62f1
15
chat.js
15
chat.js
@ -36,6 +36,10 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||||||
ob.Messages = jarnxmpp.Messages || {};
|
ob.Messages = jarnxmpp.Messages || {};
|
||||||
ob.Presence = jarnxmpp.Presence || {};
|
ob.Presence = jarnxmpp.Presence || {};
|
||||||
|
|
||||||
|
ob.isOwnUser = function (jid) {
|
||||||
|
return (Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(xmppchat.connection.jid));
|
||||||
|
};
|
||||||
|
|
||||||
ob.ChatPartners = (function () {
|
ob.ChatPartners = (function () {
|
||||||
/* A mapping of bare JIDs to resources, to keep track of
|
/* A mapping of bare JIDs to resources, to keep track of
|
||||||
* how many resources we have per chat partner.
|
* how many resources we have per chat partner.
|
||||||
@ -54,19 +58,30 @@ var xmppchat = (function (jarnxmpp, $, console) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
methods.remove = function (bare_jid, resource) {
|
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 (Object.prototype.hasOwnProperty.call(storage, bare_jid)) {
|
||||||
if (!(resource in helpers.oc(storage[bare_jid]))) {
|
if (!(resource in helpers.oc(storage[bare_jid]))) {
|
||||||
var idx = storage[bare_jid].indexOf(resource);
|
var idx = storage[bare_jid].indexOf(resource);
|
||||||
if (idx !== undefined) {
|
if (idx !== undefined) {
|
||||||
storage[bare_jid].splice(idx, 1);
|
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 () {
|
methods.getTotal = function () {
|
||||||
return helpers.size(storage);
|
return helpers.size(storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
return methods;
|
return methods;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user