瀏覽代碼

Make the fetching of VCards optional. Updates #100

JC Brand 11 年之前
父節點
當前提交
cbde2a1d49
共有 3 個文件被更改,包括 22 次插入11 次删除
  1. 12 11
      converse.js
  2. 1 0
      docs/CHANGES.rst
  3. 9 0
      docs/source/index.rst

+ 12 - 11
converse.js

@@ -87,6 +87,7 @@
         this.show_only_online_users = false;
         this.show_emoticons = true;
         this.show_toolbar = true;
+        this.use_vcards = true;
         this.xhr_custom_status = false;
         this.xhr_custom_status_url = '';
         this.xhr_user_search = false;
@@ -114,6 +115,7 @@
             'show_only_online_users',
             'show_toolbar',
             'sid',
+            'use_vcards',
             'xhr_custom_status',
             'xhr_custom_status_url',
             'xhr_user_search',
@@ -205,6 +207,12 @@
         };
 
         this.getVCard = function (jid, callback, errback) {
+            if (!this.use_vcards) {
+                if (callback) {
+                    callback(jid, jid);
+                }
+                return;
+            }
             converse.connection.vcard.get(
                 $.proxy(function (iq) {
                     // Successful callback
@@ -242,7 +250,8 @@
                     if (errback) {
                         errback(iq);
                     }
-                });
+                }
+            );
         };
 
         this.onConnect = function (status) {
@@ -1384,16 +1393,7 @@
                     $input.addClass('error');
                     return;
                 }
-                converse.getVCard(
-                    jid,
-                    $.proxy(function (jid, fullname, image, image_type, url) {
-                        this.addContact(jid, fullname);
-                    }, this),
-                    $.proxy(function (stanza) {
-                        converse.log("An error occured while fetching vcard");
-                        var jid = $(stanza).attr('from');
-                        this.addContact(jid, jid);
-                    }, this));
+                this.addContact(jid);
                 $('.search-xmpp').hide();
             },
 
@@ -1408,6 +1408,7 @@
             },
 
             addContact: function (jid, name) {
+                name = _.isEmpty(name)? jid: name;
                 converse.connection.roster.add(jid, name, [], function (iq) {
                     converse.connection.roster.subscribe(jid, null, converse.xmppstatus.get('fullname'));
                 });

+ 1 - 0
docs/CHANGES.rst

@@ -5,6 +5,7 @@ Changelog
 ------------------
 
 * #48 Add event emitter support and emit events. [jcbrand]
+* #100 Make the fetching of vCards optional (enabled by default). [jcbrand]
 
 0.7.1 (2013-11-17)
 ------------------

+ 9 - 0
docs/source/index.rst

@@ -815,6 +815,15 @@ Default = ``false``
 If set to ``true``, only online users will be shown in the contacts roster.
 Users with any other status (e.g. away, busy etc.) will not be shown.
 
+use_vcards
+----------
+
+Default = ``true``
+
+Determines whether the XMPP server will be queried for roster contacts' VCards
+or not. VCards contain extra personal information such as your fullname and
+avatar image.
+
 xhr_custom_status
 -----------------