Commit 63ce5017 authored by JC Brand's avatar JC Brand

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

so rename model and only use it in the VCards collection.
parent d0f490bb
......@@ -230,7 +230,7 @@
});
_converse.ChatBox = _converse.ModelWithDefaultAvatar.extend({
_converse.ChatBox = Backbone.Model.extend({
defaults: {
'bookmarked': false,
'chat_state': undefined,
......
......@@ -239,33 +239,6 @@
_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) {
"use strict";
settings = !_.isUndefined(settings) ? settings : {};
......@@ -832,7 +805,7 @@
this.connfeedback = new this.ConnectionFeedback();
this.XMPPStatus = this.ModelWithDefaultAvatar.extend({
this.XMPPStatus = Backbone.Model.extend({
defaults () {
return {
......
......@@ -20,8 +20,35 @@
*/
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({
model: _converse.ModelWithDefaultAvatar,
model: _converse.VCard,
initialize () {
this.on('add', (vcard) => _converse.api.vcard.update(vcard));
......@@ -72,11 +99,7 @@
function setVCard (data) {
return new Promise((resolve, reject) => {
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);
});
}
......
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