Update display when contact colors change

// FREEBIE
This commit is contained in:
lilia 2016-09-11 15:03:05 -07:00
parent 6a4b720b89
commit edd6f58539
3 changed files with 37 additions and 8 deletions

View file

@ -349,11 +349,7 @@
this.trigger('change');
}
},
getAvatar: function() {
if (this.avatarUrl === undefined) {
this.updateAvatarUrl(true);
}
getColor: function() {
var title = this.get('name');
var color = this.get('color');
if (!color) {
@ -367,6 +363,15 @@
color = 'default';
}
}
return color;
},
getAvatar: function() {
if (this.avatarUrl === undefined) {
this.updateAvatarUrl(true);
}
var title = this.get('name');
var color = this.getColor();
if (this.avatarUrl) {
return { url: this.avatarUrl, color: color };
@ -543,4 +548,6 @@
});
}
});
Whisper.Conversation.COLORS = COLORS.concat(['grey', 'default']).join(' ');
})();

View file

@ -39,7 +39,7 @@
},
initialize: function(options) {
this.listenTo(this.model, 'destroy', this.stopListening);
this.listenTo(this.model, 'change:avatar', this.updateAvatar);
this.listenTo(this.model, 'change:color', this.updateColor);
this.listenTo(this.model, 'change:name', this.updateTitle);
this.listenTo(this.model, 'newmessage', this.addMessage);
this.listenTo(this.model, 'opened', this.onOpened);
@ -319,12 +319,17 @@
this.$('.conversation-title').text(this.model.getTitle());
},
updateAvatar: function() {
updateColor: function(model, color) {
var header = this.$('.conversation-header');
header.removeClass(Whisper.Conversation.COLORS);
if (color) {
header.addClass(color);
}
var avatarView = new (Whisper.View.extend({
templateName: 'avatar',
render_attributes: { avatar: this.model.getAvatar() }
}))();
this.$('.conversation-header .avatar').replaceWith(avatarView.render().$('.avatar'));
header.find('.avatar').replaceWith(avatarView.render().$('.avatar'));
},
updateMessageFieldSize: function (event) {

View file

@ -39,6 +39,11 @@
this.listenTo(this.model, 'pending', this.renderPending);
this.listenTo(this.model, 'done', this.renderDone);
this.timeStampView = new Whisper.ExtendedTimestampView();
this.contact = this.model.isIncoming() ? this.model.getContact() : null;
if (this.contact) {
this.listenTo(this.contact, 'change:color', this.updateColor);
}
},
events: {
'click .retry': 'retryMessage',
@ -143,6 +148,18 @@
return this;
},
updateColor: function(model, color) {
var bubble = this.$('.bubble');
bubble.removeClass(Whisper.Conversation.COLORS);
if (color) {
bubble.addClass(color);
}
var avatarView = new (Whisper.View.extend({
templateName: 'avatar',
render_attributes: { avatar: model.getAvatar() }
}))();
this.$('.avatar').replaceWith(avatarView.render().$('.avatar'));
},
loadAttachments: function() {
this.model.get('attachments').forEach(function(attachment) {
var view = new Whisper.AttachmentView({ model: attachment });