Răsfoiți Sursa

We now only need to override `set` for the actual VCards

so rename model and only use it in the VCards collection.
JC Brand 7 ani în urmă
părinte
comite
63ce501798
3 a modificat fișierele cu 31 adăugiri și 35 ștergeri
  1. 1 1
      src/converse-chatboxes.js
  2. 1 28
      src/converse-core.js
  3. 29 6
      src/converse-vcard.js

+ 1 - 1
src/converse-chatboxes.js

@@ -230,7 +230,7 @@
             });
             });
 
 
 
 
-            _converse.ChatBox = _converse.ModelWithDefaultAvatar.extend({
+            _converse.ChatBox = Backbone.Model.extend({
                 defaults: {
                 defaults: {
                     'bookmarked': false,
                     'bookmarked': false,
                     'chat_state': undefined,
                     'chat_state': undefined,

+ 1 - 28
src/converse-core.js

@@ -239,33 +239,6 @@
     _converse.router = new Backbone.Router();
     _converse.router = new Backbone.Router();
 
 
 
 
-    _converse.ModelWithDefaultAvatar = Backbone.Model.extend({
-        defaults: {
-            'image': _converse.DEFAULT_IMAGE,
-            'image_type': _converse.DEFAULT_IMAGE_TYPE
-        },
-
-        set (key, val, options) {
-            // Override Backbone.Model.prototype.set to make sure that the
-            // default `image` and `image_type` values are maintained.
-            let attrs;
-            if (typeof key === 'object') {
-                attrs = key;
-                options = val;
-            } else {
-                (attrs = {})[key] = val;
-            }
-            if (_.has(attrs, 'image') && _.isUndefined(attrs['image'])) {
-                attrs['image'] = _converse.DEFAULT_IMAGE;
-                attrs['image_type'] = _converse.DEFAULT_IMAGE_TYPE;
-                return Backbone.Model.prototype.set.call(this, attrs, options);
-            } else {
-                return Backbone.Model.prototype.set.apply(this, arguments);
-            }
-        }
-    });
-
-
     _converse.initialize = function (settings, callback) {
     _converse.initialize = function (settings, callback) {
         "use strict";
         "use strict";
         settings = !_.isUndefined(settings) ? settings : {};
         settings = !_.isUndefined(settings) ? settings : {};
@@ -832,7 +805,7 @@
         this.connfeedback = new this.ConnectionFeedback();
         this.connfeedback = new this.ConnectionFeedback();
 
 
 
 
-        this.XMPPStatus = this.ModelWithDefaultAvatar.extend({
+        this.XMPPStatus = Backbone.Model.extend({
 
 
             defaults () {
             defaults () {
                 return {
                 return {

+ 29 - 6
src/converse-vcard.js

@@ -20,8 +20,35 @@
              */
              */
             const { _converse } = this;
             const { _converse } = this;
 
 
+            _converse.VCard = Backbone.Model.extend({
+                defaults: {
+                    'image': _converse.DEFAULT_IMAGE,
+                    'image_type': _converse.DEFAULT_IMAGE_TYPE
+                },
+
+                set (key, val, options) {
+                    // Override Backbone.Model.prototype.set to make sure that the
+                    // default `image` and `image_type` values are maintained.
+                    let attrs;
+                    if (typeof key === 'object') {
+                        attrs = key;
+                        options = val;
+                    } else {
+                        (attrs = {})[key] = val;
+                    }
+                    if (_.has(attrs, 'image') && !attrs['image']) {
+                        attrs['image'] = _converse.DEFAULT_IMAGE;
+                        attrs['image_type'] = _converse.DEFAULT_IMAGE_TYPE;
+                        return Backbone.Model.prototype.set.call(this, attrs, options);
+                    } else {
+                        return Backbone.Model.prototype.set.apply(this, arguments);
+                    }
+                }
+            });
+
+
             _converse.VCards = Backbone.Collection.extend({
             _converse.VCards = Backbone.Collection.extend({
-                model: _converse.ModelWithDefaultAvatar,
+                model: _converse.VCard,
 
 
                 initialize () {
                 initialize () {
                     this.on('add', (vcard) => _converse.api.vcard.update(vcard));
                     this.on('add', (vcard) => _converse.api.vcard.update(vcard));
@@ -72,11 +99,7 @@
             function setVCard (data) {
             function setVCard (data) {
                 return new Promise((resolve, reject) => {
                 return new Promise((resolve, reject) => {
                     const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild;
                     const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild;
-                    _converse.connection.sendIQ(
-                        createStanza("set", data.jid, vcard_el),
-                        resolve,
-                        reject
-                    );
+                    _converse.connection.sendIQ(createStanza("set", data.jid, vcard_el), resolve, reject);
                 });
                 });
             }
             }