diff --git a/app/internal_packages/unread-notifications/lib/main.ts b/app/internal_packages/unread-notifications/lib/main.ts index f44bc1dab..4a86bb7b7 100644 --- a/app/internal_packages/unread-notifications/lib/main.ts +++ b/app/internal_packages/unread-notifications/lib/main.ts @@ -30,29 +30,33 @@ export class Notifier { } // async for testing - async _onDatabaseChanged({ objectClass, objects }) { + async _onDatabaseChanged({ objectClass, objects, objectsRawJSON }) { if (AppEnv.config.get('core.notifications.enabled') === false) { return; } if (objectClass === Thread.name) { - return this._onThreadsChanged(objects); + this._onThreadsChanged(objects); } if (objectClass === Message.name) { - return this._onMessagesChanged(objects); + const newIds = objectsRawJSON.filter(json => json.headersSyncComplete).map(json => json.id); + if (!newIds.length) return; + this._onMessagesChanged(objects, newIds); } } // async for testing - async _onMessagesChanged(msgs) { + async _onMessagesChanged(msgs, newIds: string[]) { const notifworthy = {}; for (const msg of msgs) { // ensure the message is unread if (msg.unread !== true) continue; - // ensure the message was just created (eg: this is not a modification) - if (msg.version !== 1) continue; + // ensure the message was just created (eg: this is not a modification). + // The sync engine attaches a JSON key to let us know that this is the first + // message emitted about this Message. (Hooray hacks around reactive patterns) + if (!newIds.includes(msg.id)) continue; // ensure the message was received after the app launched (eg: not syncing an old email) if (!msg.date || msg.date.valueOf() < this.activationTime) continue; // ensure the message is not a loopback diff --git a/mailsync b/mailsync index 0513c6dcb..b624685a1 160000 --- a/mailsync +++ b/mailsync @@ -1 +1 @@ -Subproject commit 0513c6dcb76e131ab864778d135aa6cb40e58dfe +Subproject commit b624685a1707b7573c58a0e157736e181169a877