From c313514f340f1be58527ca645634c346559857bc Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Fri, 5 Mar 2021 14:26:10 -0500 Subject: [PATCH] Auto healing unreferenced quotes --- ts/models/messages.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 0e54194a1a..ee3c30df04 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -1135,6 +1135,35 @@ export class MessageModel extends window.Backbone.Model { ); const authorColor = contact ? contact.getColor() : 'grey'; + let reallyNotFound = referencedMessageNotFound; + // Is the quote really without a reference? Check with our in memory store + // first to make sure it's not there. + if (referencedMessageNotFound) { + const messageId = this.get('sent_at'); + window.log.info( + `getPropsForQuote: Verifying that ${messageId} referencing ${sentAt} is really not found` + ); + const inMemoryMessage = window.MessageController.findBySentAt( + Number(sentAt) + ); + reallyNotFound = !inMemoryMessage; + + // We found the quote in memory so update the message in the database + // so we don't have to do this check again + if (!reallyNotFound) { + window.log.info( + `getPropsForQuote: Found ${sentAt}, scheduling an update to ${messageId}` + ); + this.set({ + quote: { + ...quote, + referencedMessageNotFound: false, + }, + }); + window.Signal.Util.updateMessageBatcher.add(this.attributes); + } + } + const authorPhoneNumber = format(author, { ourRegionCode: regionCode, }); @@ -1158,7 +1187,7 @@ export class MessageModel extends window.Backbone.Model { authorTitle, authorName, authorColor, - referencedMessageNotFound, + referencedMessageNotFound: reallyNotFound, onClick: () => this.trigger('scroll-to-message'), }; }