Stop using model version to check if a message is brand new #1467

This commit is contained in:
Ben Gotow 2019-09-23 17:43:52 -05:00
parent 03dd94596c
commit d561d7d6a1
2 changed files with 11 additions and 7 deletions

View file

@ -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

@ -1 +1 @@
Subproject commit 0513c6dcb76e131ab864778d135aa6cb40e58dfe
Subproject commit b624685a1707b7573c58a0e157736e181169a877