MessageView: Make Quotes resilient to re-renders

This commit is contained in:
Scott Nonnenberg 2018-04-12 16:57:50 -07:00
parent b458c7d449
commit 0100e279f5
No known key found for this signature in database
GPG key ID: 5F82280C35134661

View file

@ -378,7 +378,7 @@
return null; return null;
}, },
renderReply() { renderQuote() {
const VOICE_FLAG = textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE; const VOICE_FLAG = textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE;
const objectUrl = this.getQuoteObjectUrl(); const objectUrl = this.getQuoteObjectUrl();
const quote = this.model.get('quote'); const quote = this.model.get('quote');
@ -426,18 +426,18 @@
text: quote.text, text: quote.text,
}; };
if (!this.replyView) { if (this.replyView) {
if (contact) { this.replyView.remove();
this.listenTo(contact, 'change:color', this.renderReply); this.replyView = null;
} } else if (contact) {
this.replyView = new Whisper.ReactWrapperView({ this.listenTo(contact, 'change:color', this.renderQuote);
el: this.$('.quote-wrapper'),
Component: window.Signal.Components.Quote,
props,
});
} else {
this.replyView.update(props);
} }
this.replyView = new Whisper.ReactWrapperView({
el: this.$('.quote-wrapper'),
Component: window.Signal.Components.Quote,
props,
});
}, },
isImageWithoutCaption() { isImageWithoutCaption() {
const attachments = this.model.get('attachments'); const attachments = this.model.get('attachments');
@ -486,8 +486,7 @@
this.renderRead(); this.renderRead();
this.renderErrors(); this.renderErrors();
this.renderExpiring(); this.renderExpiring();
this.renderReply(); this.renderQuote();
// NOTE: We have to do this in the background (`then` instead of `await`) // NOTE: We have to do this in the background (`then` instead of `await`)
// as our code / Backbone seems to rely on `render` synchronously returning // as our code / Backbone seems to rely on `render` synchronously returning