Skip to content

Commit a955df7

Browse files
committed
Immediate: forgot to add one more button to add it back
1 parent 102b894 commit a955df7

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

server-src/server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ async function destroyAccount(username) {
861861
try {
862862
await storage.deleteFile(`userlist-${username}.json`);
863863
} catch (e) {}
864+
try {
865+
await storage.deleteFile(`push_sub_${username}.json`);
866+
} catch (e) {}
864867
}
865868

866869
async function updateUserPassword(username, newPassword) {

src/chat/interface/notifications/index.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RealTimeNotifications {
1717
this.menuElement = null;
1818
this.notificationDiv = null;
1919
this.removeSWPButton = null;
20+
this.addSWPButton = null;
2021
var _this = this;
2122

2223
this.dialogElement = elements.appendElementsFromJSON(document.body, [
@@ -133,6 +134,20 @@ class RealTimeNotifications {
133134
},
134135
],
135136
},
137+
{
138+
element: "div",
139+
className: "divButton roundborder",
140+
textContent: "Enable push notifications",
141+
GPWhenCreated: function (elm) {
142+
_this.addSWPButton = elm;
143+
},
144+
eventListeners: [
145+
{
146+
event: "click",
147+
func: this.requestEnablePush.bind(this),
148+
},
149+
],
150+
},
136151
{
137152
element: "br",
138153
},
@@ -304,8 +319,9 @@ class RealTimeNotifications {
304319
loadNotifications() {
305320
var _this = this;
306321
(async function () {
307-
_this.removeSWPButton.hidden = !(await accountHelper.pushNotificationHelper.getSubscription());
308-
322+
var sub = await accountHelper.pushNotificationHelper.getSubscription();
323+
_this.removeSWPButton.hidden = !sub;
324+
_this.addSWPButton.hidden = !!sub;
309325
})();
310326
this.notificationDot.textContent = this.notifications.length;
311327
this.notificationDot.hidden = false;
@@ -409,6 +425,11 @@ class RealTimeNotifications {
409425
}
410426

411427
async requestDisablePush() {
428+
if (this._disablingSWP) {
429+
return;
430+
}
431+
this._disablingSWP = true;
432+
412433
var output = await dialogs.confirm("Are you sure you want to disable push notifications? If you do that, you'll not recieve any more system notifications from the bell.");
413434

414435
if (!output) {
@@ -424,6 +445,27 @@ class RealTimeNotifications {
424445
}
425446

426447
this.loadNotifications();
448+
this._disablingSWP = false;
449+
}
450+
451+
async requestEnablePush() {
452+
if (this._enablingSWP) {
453+
return;
454+
}
455+
this._enablingSWP = true;
456+
var prevText = this.addSWPButton.textContent;
457+
try{
458+
this.addSWPButton.textContent = "Click allow if it appears anywhere";
459+
await notify.requestPermission();
460+
this.addSWPButton.textContent = "Subscribing to push notifications...";
461+
await accountHelper.pushNotificationHelper.subscribe();
462+
}catch(e){
463+
dialog.alert("Unable to enable push notifications: "+e);
464+
console.error(e);
465+
}
466+
this.loadNotifications();
467+
this._enablingSWP = false;
468+
this.addSWPButton.textContent = prevText;
427469
}
428470
}
429471

wpstatic/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"timestamp":"1770740200809"}
1+
{"timestamp":"1770740815933"}

0 commit comments

Comments
 (0)