瀏覽代碼

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

JC Brand 7 年之前
父節點
當前提交
05e7cc8529
共有 2 個文件被更改,包括 7 次插入9 次删除
  1. 3 1
      docs/source/developer_api.rst
  2. 4 8
      src/converse-core.js

+ 3 - 1
docs/source/developer_api.rst

@@ -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      |                                                                                                                 |

+ 4 - 8
src/converse-core.js

@@ -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, '@')) {