nodebb-plugin-web-push 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/library.js
CHANGED
|
@@ -85,6 +85,18 @@ plugin.addRoutes = async ({ router, middleware, helpers }) => {
|
|
|
85
85
|
await subscriptions.remove(req.uid, subscription);
|
|
86
86
|
helpers.formatApiResponse(200, res);
|
|
87
87
|
});
|
|
88
|
+
|
|
89
|
+
routeHelpers.setupApiRoute(router, 'post', '/web-push/test', middlewares, async (req, res) => {
|
|
90
|
+
if (!req.uid) {
|
|
91
|
+
return helpers.notAllowed(req, res);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { subscription } = req.body;
|
|
95
|
+
await webPush.sendNotification(subscription, JSON.stringify({
|
|
96
|
+
title: 'Test notification',
|
|
97
|
+
body: 'This is a test message sent from NodeBB',
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
88
100
|
};
|
|
89
101
|
|
|
90
102
|
plugin.addAdminNavigation = (header) => {
|
package/package.json
CHANGED
|
@@ -3,5 +3,9 @@
|
|
|
3
3
|
"profile.introduction": "In addition to in-application and email notifications, you may opt-in to receive push notifications as well. This will allow you to be notified even if the app is not open on your device.",
|
|
4
4
|
"profile.option": "Enable push notifications on this device",
|
|
5
5
|
"profile.devices": "Currently notifying <strong>%1</strong> device(s).",
|
|
6
|
-
"profile.permissionBlocked": "Your device is currently disallowing notifications from this site. Please grant the notification permission to continue."
|
|
6
|
+
"profile.permissionBlocked": "Your device is currently disallowing notifications from this site. Please grant the notification permission to continue.",
|
|
7
|
+
"profile.send-test": "Send Test Notification",
|
|
8
|
+
|
|
9
|
+
"toast.test_success": "Test notification sent.",
|
|
10
|
+
"toast.test_unavailable": "Cannot send test notification as push notifications are not enabled on this device."
|
|
7
11
|
}
|
package/public/lib/settings.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/* eslint-disable import/no-unresolved */
|
|
2
|
+
|
|
1
3
|
'use strict';
|
|
2
4
|
|
|
3
5
|
import { post, del } from 'api';
|
|
4
|
-
import { success } from 'alerts';
|
|
6
|
+
import { success, warning } from 'alerts';
|
|
5
7
|
|
|
6
8
|
// eslint-disable-next-line import/prefer-default-export
|
|
7
9
|
export async function init() {
|
|
@@ -16,11 +18,15 @@ export async function init() {
|
|
|
16
18
|
const action = e.target.getAttribute('data-action');
|
|
17
19
|
|
|
18
20
|
switch (action) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
case 'test': {
|
|
22
|
+
if (subscription) {
|
|
23
|
+
await post('/plugins/web-push/test', { subscription });
|
|
24
|
+
success('[[web-push:toast.test_success]]');
|
|
25
|
+
} else {
|
|
26
|
+
warning('[[web-push:toast.test_unavailable]]');
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
24
30
|
|
|
25
31
|
case 'toggle': {
|
|
26
32
|
const countEl = document.querySelector('#deviceCount strong');
|
|
@@ -77,7 +83,7 @@ export async function init() {
|
|
|
77
83
|
function urlBase64ToUint8Array(base64String) {
|
|
78
84
|
var padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
|
79
85
|
var base64 = (base64String + padding)
|
|
80
|
-
.replace(
|
|
86
|
+
.replace(/-/g, '+')
|
|
81
87
|
.replace(/_/g, '/');
|
|
82
88
|
|
|
83
89
|
var rawData = window.atob(base64);
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
<div class="alert alert-warning d-none" id="permission-warning">[[web-push:profile.permissionBlocked]]</div>
|
|
8
8
|
|
|
9
9
|
<form role="form">
|
|
10
|
-
<div class="form-check form-switch">
|
|
10
|
+
<div class="form-check form-switch mb-3">
|
|
11
11
|
<input type="checkbox" class="form-check-input" id="enabled" name="enabled" autocomplete="off" data-action="toggle">
|
|
12
12
|
<label for="enabled" class="form-check-label">[[web-push:profile.option]]</label>
|
|
13
13
|
<p class="form-text" id="deviceCount">[[web-push:profile.devices, {count}]]</p>
|
|
14
14
|
</div>
|
|
15
|
+
<div class="mb-3">
|
|
16
|
+
<button type="button" class="btn btn-primary" data-action="test">[[web-push:profile.send-test]]</button>
|
|
17
|
+
</div>
|
|
15
18
|
</form>
|
|
16
19
|
|
|
17
20
|
<!-- IMPORT partials/account/footer.tpl -->
|