From 99787753a8265a9f797ce43f38f30f8a976c60ef Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 5 Mar 2015 16:13:53 -0800 Subject: [PATCH] Stop re-rendering attachments on delivery receipt Only re-render a message if the body changed. Re-render only the delivery receipt checkmark if the delivered property changes. Fix a bug where attachments flash in and out of existance when a delivery receipt arrives. --- js/views/message_view.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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: {