Commit 60c784a3 authored by JC Brand's avatar JC Brand

Ensure that default image is used for avatars.

By overriding the `set` method.
parent 58ca4a56
......@@ -187,7 +187,7 @@
});
_converse.ChatBox = Backbone.Model.extend({
_converse.ChatBox = _converse.ModelWithDefaultAvatar.extend({
defaults: {
'bookmarked': false,
'chat_state': undefined,
......
......@@ -1505,7 +1505,35 @@
});
this.connfeedback = new this.ConnectionFeedback();
this.XMPPStatus = Backbone.Model.extend({
this.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);
}
}
});
this.XMPPStatus = this.ModelWithDefaultAvatar.extend({
defaults () {
return {
......
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