Fix resubscribing when notifications are re-granted
(case: from denied to granted)
This commit is contained in:
parent
365a0b2832
commit
e8216ae9e7
4 changed files with 13 additions and 15 deletions
|
@ -44,9 +44,6 @@ class Notifier {
|
|||
}
|
||||
|
||||
async webPushSubscription(hasWebPushTopics) {
|
||||
if (!this.pushPossible()) {
|
||||
throw new Error("Unsupported or denied");
|
||||
}
|
||||
const pushManager = await this.pushManager();
|
||||
const existingSubscription = await pushManager.getSubscription();
|
||||
if (existingSubscription) {
|
||||
|
|
|
@ -27,7 +27,7 @@ class SubscriptionManager {
|
|||
* 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(pushPossible = notifier.pushPossible()) {
|
||||
async webPushTopics(pushPossible) {
|
||||
if (!pushPossible) {
|
||||
return [];
|
||||
}
|
||||
|
@ -120,13 +120,14 @@ class SubscriptionManager {
|
|||
);
|
||||
}
|
||||
|
||||
async updateWebPushSubscriptions(presetTopics) {
|
||||
const topics = presetTopics ?? (await this.webPushTopics());
|
||||
async updateWebPushSubscriptions(topics) {
|
||||
const hasWebPushTopics = topics.length > 0;
|
||||
const browserSubscription = await notifier.webPushSubscription(hasWebPushTopics);
|
||||
|
||||
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 or the notification permission was removed. Skipping."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue