1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-12-14 11:47:33 +00:00

Re-increate Dexie version number

This commit is contained in:
binwiederhier 2023-06-14 13:08:35 -04:00
parent ad36f5db46
commit 9403873a7b
3 changed files with 14 additions and 6 deletions

View file

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

View file

@ -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]);

View file

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