diff --git a/js/views/message_view.js b/js/views/message_view.js index 2ba3d33e..ddae6183 100644 --- a/js/views/message_view.js +++ b/js/views/message_view.js @@ -35,9 +35,16 @@ var ContentMessageView = Whisper.View.extend({ tagName: 'div', template: $('#message').html(), + initialize: function() { + this.listenTo(this.model, 'change:body', this.render); + this.listenTo(this.model, 'change:delivered', this.renderDelivered); + }, className: function() { if (this.model.get('delivered')) { return 'delivered'; } }, + renderDelivered: function() { + if (this.model.get('delivered')) { this.$el.addClass('delivered'); } + }, render: function() { this.$el.html( Mustache.render(this.template, { @@ -47,7 +54,7 @@ }) ); - if (this.model.get('delivered')) { this.$el.addClass('delivered'); } + this.renderDelivered(); this.$el.find('.attachments').append( this.model.get('attachments').map(function(attachment) { @@ -85,7 +92,6 @@ } this.$el.append(this.view.el); - this.listenTo(this.model, 'change', this.render); // auto update this.listenTo(this.model, 'destroy', this.remove); // auto update }, events: {