From 15f9f6ae0799c0c7d522e83ba043844501b69390 Mon Sep 17 00:00:00 2001 From: hobokenchicken Date: Thu, 2 Jul 2026 15:11:07 -0400 Subject: [PATCH] fix: push delivery when app is closed - TTL 30s -> 86400 (24h): push services were dropping undelivered notifs - Urgency: high: wakes device from doze/sleep - Topic: per-user to collapse duplicate pending pushes - SW push handler: try/catch for malformed payloads, always call waitUntil - Bump SW cache to v6 --- internal/push/handlers.go | 8 ++++++-- web/public/sw.js | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/push/handlers.go b/internal/push/handlers.go index 85f9be7..95a1947 100644 --- a/internal/push/handlers.go +++ b/internal/push/handlers.go @@ -167,7 +167,9 @@ func (h *Handler) SendPush(ctx context.Context, userID string, payload map[strin Subscriber: h.vapidSubj, VAPIDPublicKey: h.vapidPub, VAPIDPrivateKey: h.vapidPriv, - TTL: 30, + TTL: 86400, + Urgency: webpush.UrgencyHigh, + Topic: userID, }) if err != nil { h.logger.Error("failed to send push", "error", err, "user_id", userID) @@ -242,7 +244,9 @@ func (h *Handler) SendChannelNotification(ctx context.Context, channelID, author Subscriber: h.vapidSubj, VAPIDPublicKey: h.vapidPub, VAPIDPrivateKey: h.vapidPriv, - TTL: 30, + TTL: 86400, + Urgency: webpush.UrgencyHigh, + Topic: userID, }) if err != nil { h.logger.Error("failed to send push", "error", err, "user_id", userID) diff --git a/web/public/sw.js b/web/public/sw.js index de4216d..38f538e 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -75,17 +75,23 @@ self.addEventListener('fetch', (event) => { // Push notifications self.addEventListener('push', (event) => { - if (!event.data) return; - const data = event.data.json(); + let data = { title: 'Dumpster', body: '', url: '/', tag: 'dumpster-notification' }; + try { + if (event.data) { + data = { ...data, ...event.data.json() }; + } + } catch (e) { + data.body = event.data ? event.data.text() : ''; + } event.waitUntil( - self.registration.showNotification(data.title || 'Dumpster', { + self.registration.showNotification(data.title, { body: data.body, icon: '/icons/icon-192.png', badge: '/icons/icon-192.png', vibrate: [100, 50, 100], - tag: data.tag || 'dumpster-notification', + tag: data.tag, renotify: true, - data: { url: data.url || '/' }, + data: { url: data.url }, }) ); });