1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 19:33:27 +01:00

Tiny fixes

This commit is contained in:
binwiederhier 2023-06-14 13:31:34 -04:00
parent 9403873a7b
commit 4dc89f6bc5
2 changed files with 7 additions and 12 deletions

View file

@ -48,7 +48,7 @@ class Notifier {
} }
} }
async getBrowserSubscription() { async webPushSubscription() {
if (!this.pushPossible()) { if (!this.pushPossible()) {
throw new Error("Unsupported or denied"); throw new Error("Unsupported or denied");
} }
@ -58,11 +58,9 @@ class Notifier {
return existingSubscription; return existingSubscription;
} }
// Create a new subscription only if web push is enabled. // Create a new subscription only if Web Push is enabled. It is possible that Web Push
// It is possible that web push was previously enabled and then disabled again // was previously enabled and then disabled again in which case there would be an existingSubscription.
// in which case there would be an existingSubscription. // If, however, it was _not_ enabled previously, we create a new subscription if it is now enabled.
// but if it was _not_ enabled previously, we reach here, and only create a new
// subscription if it is now enabled.
if (await this.pushEnabled()) { if (await this.pushEnabled()) {
return pushManager.subscribe({ return pushManager.subscribe({

View file

@ -35,9 +35,7 @@ class SubscriptionManager {
return []; return [];
} }
const subscriptions = await this.db.subscriptions.where({ baseUrl: config.base_url, mutedUntil: 0 }).toArray(); const subscriptions = await this.db.subscriptions.where({ baseUrl: config.base_url, mutedUntil: 0 }).toArray();
return subscriptions return subscriptions.filter(({ internal }) => !internal).map(({ topic }) => topic);
.filter(({ internal }) => !internal)
.map(({ topic }) => topic);
} }
async get(subscriptionId) { async get(subscriptionId) {
@ -46,8 +44,7 @@ class SubscriptionManager {
async notify(subscriptionId, notification, defaultClickAction) { async notify(subscriptionId, notification, defaultClickAction) {
const subscription = await this.get(subscriptionId); const subscription = await this.get(subscriptionId);
if (subscription.mutedUntil > 0) {
if (subscription.mutedUntil === 1) {
return; return;
} }
@ -120,7 +117,7 @@ class SubscriptionManager {
async updateWebPushSubscriptions(presetTopics) { async updateWebPushSubscriptions(presetTopics) {
const topics = presetTopics ?? (await this.webPushTopics()); const topics = presetTopics ?? (await this.webPushTopics());
const browserSubscription = await notifier.getBrowserSubscription(); const browserSubscription = await notifier.webPushSubscription();
if (!browserSubscription) { if (!browserSubscription) {
console.log("[SubscriptionManager] No browser subscription currently exists, so web push was never enabled. Skipping."); console.log("[SubscriptionManager] No browser subscription currently exists, so web push was never enabled. Skipping.");