Ensure that default image is used for avatars.

By overriding the `set` method.
This commit is contained in:
JC Brand 2018-04-30 10:38:02 +02:00
parent 58ca4a5664
commit 60c784a39e
2 changed files with 30 additions and 2 deletions

View File

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

View File

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