Let api.contacts.get return the RosterContact model

This commit is contained in:
JC Brand 2018-03-14 13:01:19 +00:00
parent daff088c97
commit 05e7cc8529
2 changed files with 7 additions and 9 deletions

View File

@ -695,7 +695,9 @@ To return all contacts, simply call ``get`` without any parameters:
});
The returned roster contact objects have these attributes:
The returned roster contact is a `Backbone.Model <http://backbonejs.org/#Model>`_ of type _converse.RosterContacts.
It has the following attributes (which should be accessed via `get <http://backbonejs.org/#Model-get>`_).
+----------------+-----------------------------------------------------------------------------------------------------------------+
| Attribute | |

View File

@ -1929,19 +1929,15 @@
},
'contacts': {
'get' (jids) {
const _transform = function (jid) {
const contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
if (contact) {
return contact.attributes;
}
return null;
const _getter = function (jid) {
return _converse.roster.get(Strophe.getBareJidFromJid(jid)) || null;
};
if (_.isUndefined(jids)) {
jids = _converse.roster.pluck('jid');
} else if (_.isString(jids)) {
return _transform(jids);
return _getter(jids);
}
return _.map(jids, _transform);
return _.map(jids, _getter);
},
'add' (jid, name) {
if (!_.isString(jid) || !_.includes(jid, '@')) {