diff --git a/web/src/app/SubscriptionManager.js b/web/src/app/SubscriptionManager.js index 5b876ae1..bb5207e7 100644 --- a/web/src/app/SubscriptionManager.js +++ b/web/src/app/SubscriptionManager.js @@ -20,7 +20,13 @@ class SubscriptionManager { ); } - /** List of topics for which Web Push is enabled, excludes internal topics; returns empty list if Web Push is disabled */ + /** + * List of topics for which Web Push is enabled. This excludes (a) internal topics, (b) topics that are muted, + * and (c) topics from other hosts. Returns an empty list if Web Push is disabled. + * + * It is important to note that "mutedUntil" must be part of the where() query, otherwise the Dexie live query + * will not react to it, and the Web Push topics will not be updated when the user mutes a topic. + */ async webPushTopics() { // the Promise.resolve wrapper is not superfluous, without it the live query breaks: // https://dexie.org/docs/dexie-react-hooks/useLiveQuery()#calling-non-dexie-apis-from-querier @@ -28,8 +34,10 @@ class SubscriptionManager { if (!pushEnabled) { return []; } - const subscriptions = await this.db.subscriptions.where({ mutedUntil: 0, baseUrl: config.base_url }).toArray(); - return subscriptions.filter(({ internal }) => !internal).map(({ topic }) => topic); + const subscriptions = await this.db.subscriptions.where({ baseUrl: config.base_url, mutedUntil: 0 }).toArray(); + return subscriptions + .filter(({ internal }) => !internal) + .map(({ topic }) => topic); } async get(subscriptionId) { diff --git a/web/src/app/WebPush.js b/web/src/app/WebPush.js index 1a9b59eb..efd06816 100644 --- a/web/src/app/WebPush.js +++ b/web/src/app/WebPush.js @@ -21,11 +21,11 @@ export const useWebPushTopicListener = () => { (async () => { try { - console.log("[useWebPushUpdateWorker] Refreshing web push subscriptions"); + console.log("[useWebPushTopicListener] Refreshing web push subscriptions", topics); await subscriptionManager.updateWebPushSubscriptions(topics); setLastTopics(topics); } catch (e) { - console.error("[useWebPushUpdateWorker] Error refreshing web push subscriptions", e); + console.error("[useWebPushTopicListener] Error refreshing web push subscriptions", e); } })(); }, [topics, lastTopics]); diff --git a/web/src/app/db.js b/web/src/app/db.js index 77ac2562..b28fb716 100644 --- a/web/src/app/db.js +++ b/web/src/app/db.js @@ -11,7 +11,7 @@ const createDatabase = (username) => { const dbName = username ? `ntfy-${username}` : "ntfy"; // IndexedDB database is based on the logged-in user const db = new Dexie(dbName); - db.version(1).stores({ + db.version(2).stores({ subscriptions: "&id,baseUrl,[baseUrl+mutedUntil]", notifications: "&id,subscriptionId,time,new,[subscriptionId+new]", // compound key for query performance users: "&baseUrl,username",