From 2d139e6381686247088e68c71aed622e4cfc3cac Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 20 Nov 2019 16:47:00 +0900 Subject: [PATCH] Improved notifications --- arn/User.go | 7 ++++++- pages/settings/notifications.pixy | 8 ++++---- scripts/AnimeNotifier.ts | 10 ++++++---- scripts/PushManager.ts | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/arn/User.go b/arn/User.go index e5f9ff2e..a53920d9 100644 --- a/arn/User.go +++ b/arn/User.go @@ -166,10 +166,15 @@ func (user *User) SendNotification(pushNotification *PushNotification) { expired := []*PushSubscription{} for _, sub := range subs.Items { + if sub.Endpoint == "" { + expired = append(expired, sub) + continue + } + response, err := sub.SendNotification(pushNotification) // It is possible to receive a non-nil response with an error, so check the status. - if response != nil && response.StatusCode == http.StatusGone { + if response != nil && (response.StatusCode == http.StatusGone || response.StatusCode == http.StatusForbidden) { expired = append(expired, sub) } diff --git a/pages/settings/notifications.pixy b/pages/settings/notifications.pixy index 59f5eed1..04e1ddce 100644 --- a/pages/settings/notifications.pixy +++ b/pages/settings/notifications.pixy @@ -9,25 +9,25 @@ component SettingsNotifications(user *arn.User) Icon("bell") span Instant notifications - #enable-notifications.widget-section + #notifications-enable.widget-section label Instant notifications: button.action(data-action="enableNotifications", data-trigger="click") Icon("toggle-off") span OFF - #disable-notifications.widget-section.hidden + #notifications-disable.widget-section.hidden label Instant notifications: button.action(data-action="disableNotifications", data-trigger="click") Icon("toggle-on") span ON - #test-notification.widget-section + #notifications-test.widget-section label Test: button.action(data-action="testNotification", data-trigger="click") Icon("paper-plane") span Send test notification - footer.footer + footer#notifications-footer.footer p(title="This setting is not account bound, instead it is bound to your browser.") You can customize this setting on every device you own. //- .widget.mountable(data-api="/api/settings/" + user.ID) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 47a460ba..769985e1 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -306,14 +306,16 @@ export default class AnimeNotifier { return } - const enableButton = document.getElementById("enable-notifications") as HTMLButtonElement - const disableButton = document.getElementById("disable-notifications") as HTMLButtonElement - const testButton = document.getElementById("test-notification") as HTMLButtonElement + const enableButton = document.getElementById("notifications-enable") as HTMLButtonElement + const disableButton = document.getElementById("notifications-disable") as HTMLButtonElement + const testButton = document.getElementById("notifications-test") as HTMLButtonElement + const footer = document.getElementById("notifications-footer") as HTMLElement if(!this.pushManager.pushSupported) { enableButton.classList.add("hidden") disableButton.classList.add("hidden") - testButton.innerHTML = "Your browser doesn't support push notifications!" + testButton.classList.add("hidden") + footer.innerHTML = "Your browser doesn't support push notifications!" return } diff --git a/scripts/PushManager.ts b/scripts/PushManager.ts index 886bb443..9da996ad 100644 --- a/scripts/PushManager.ts +++ b/scripts/PushManager.ts @@ -77,7 +77,7 @@ export default class PushManager { } } - return fetch("/api/pushsubscriptions/" + userId + "/add", { + return fetch(`/api/pushsubscriptions/${userId}/add`, { method: "POST", credentials: "same-origin", body: JSON.stringify(pushSubscription)