Ensure that default image is used for avatars.
By overriding the `set` method.
This commit is contained in:
parent
58ca4a5664
commit
60c784a39e
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user