Make web app work for updated notifications

This commit is contained in:
Philipp Heckel 2022-03-25 11:01:07 -04:00
parent 86baa80ab8
commit a327fe802e

View file

@ -65,13 +65,17 @@ class SubscriptionManager {
/** Adds notification, or returns false if it already exists */ /** Adds notification, or returns false if it already exists */
async addNotification(subscriptionId, notification) { async addNotification(subscriptionId, notification) {
const exists = await db.notifications.get(notification.id); const existingNotification = await db.notifications.get(notification.id);
if (exists) { if (existingNotification) {
return false; const upToDate = (existingNotification?.updated ?? 0) >= (notification.updated ?? 0);
if (upToDate) {
console.error(`[SubscriptionManager] up to date`, existingNotification, notification);
return false;
}
} }
try { try {
notification.new = 1; // New marker (used for bubble indicator); cannot be boolean; Dexie index limitation notification.new = 1; // New marker (used for bubble indicator); cannot be boolean; Dexie index limitation
await db.notifications.add({ ...notification, subscriptionId }); // FIXME consider put() for double tab await db.notifications.put({ ...notification, subscriptionId });
await db.subscriptions.update(subscriptionId, { await db.subscriptions.update(subscriptionId, {
last: notification.id last: notification.id
}); });