Commit 05e7cc85 authored by JC Brand's avatar JC Brand

Let `api.contacts.get` return the RosterContact model

parent daff088c
...@@ -695,7 +695,9 @@ To return all contacts, simply call ``get`` without any parameters: ...@@ -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 | | | Attribute | |
......
...@@ -1929,19 +1929,15 @@ ...@@ -1929,19 +1929,15 @@
}, },
'contacts': { 'contacts': {
'get' (jids) { 'get' (jids) {
const _transform = function (jid) { const _getter = function (jid) {
const contact = _converse.roster.get(Strophe.getBareJidFromJid(jid)); return _converse.roster.get(Strophe.getBareJidFromJid(jid)) || null;
if (contact) {
return contact.attributes;
}
return null;
}; };
if (_.isUndefined(jids)) { if (_.isUndefined(jids)) {
jids = _converse.roster.pluck('jid'); jids = _converse.roster.pluck('jid');
} else if (_.isString(jids)) { } else if (_.isString(jids)) {
return _transform(jids); return _getter(jids);
} }
return _.map(jids, _transform); return _.map(jids, _getter);
}, },
'add' (jid, name) { 'add' (jid, name) {
if (!_.isString(jid) || !_.includes(jid, '@')) { if (!_.isString(jid) || !_.includes(jid, '@')) {
......
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