Commit 05c9f2cc authored by Adrien Dorsaz's avatar Adrien Dorsaz

entity: update to use Map

parent 0bb2edcb
......@@ -8,48 +8,34 @@
* [XEP-0030](https://xmpp.org/extensions/xep-0030.html)
*/
class Entity {
constructor() {
this.identities = [];
constructor(_jid) {
this.jid = _id;
// Services supported by the Entity
// key: category and type of the identity
// value: identity name
this.identities = new Map();
// Features and protocols supported by the entity
this.features = [];
this.protocols = {};
this.features = new Map();
this.protocols = new Map();
}
/*
* _identity is a <identity> XML Node
* _xmllang is the client preerend language
*/
addIdentity(_identity, _xmllang) {
addIdentity(_identity) {
let type = _identity.getAttribute('type');
let category = _identity.getAttribute('category');
let xmllang = _identity.getAttribute('xml:lang');
let name = _identity.getAttribute('name');
let identity;
let found = false;
for (let identity of this.identities){
if (identity.type === type
&& identity.category === category)
{
found = true;
break;
}
}
let idKey = ['type': type, 'category': category];
let identity = this.identities.get(idKey)
if (found) {
if (xmllang === _xmllang
&& xmllang !== identity.xmllang)
{
identity.name = name;
identity.xmllang = xmllang;
}
if (identity) {
identity = name;
}
else {
this.identities.add({
'type': type,
'category': category,
'xmllang': xmllang,
'name': name
});
this.identities.set(idKey, name);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment