From 24002149f695a08c0787d725e569cee214b99750 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 10 May 2018 17:03:06 -0400 Subject: [PATCH] Log read sync reception and remove notification --- js/read_syncs.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/js/read_syncs.js b/js/read_syncs.js index 5f123505a..3a248fd2e 100644 --- a/js/read_syncs.js +++ b/js/read_syncs.js @@ -24,21 +24,32 @@ message.get('source') === receipt.get('sender') ); }); - if (message) { - Whisper.Notifications.remove(message); - return message.markRead(receipt.get('read_at')).then( - function() { - this.notifyConversation(message); - this.remove(receipt); - }.bind(this) - ); - } else { - console.log( - 'No message for read sync', - receipt.get('sender'), - receipt.get('timestamp') - ); - } + const notificationForMessage = message + ? Whisper.Notifications.findWhere({ messageId: message.id }) + : null; + const removedNotification = Whisper.Notifications.remove( + notificationForMessage + ); + const receiptSender = receipt.get('sender'); + const receiptTimestamp = receipt.get('timestamp'); + const wasMessageFound = Boolean(message); + const wasNotificationFound = Boolean(notificationForMessage); + const wasNotificationRemoved = Boolean(removedNotification); + console.log('Receive read sync:', { + receiptSender, + receiptTimestamp, + wasMessageFound, + wasNotificationFound, + wasNotificationRemoved, + }); + return message + ? message.markRead(receipt.get('read_at')).then( + function() { + this.notifyConversation(message); + this.remove(receipt); + }.bind(this) + ) + : Promise.resolve(); }.bind(this) ); },