mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-27 17:11:14 +01:00
feat: notification rescind support
This commit is contained in:
@@ -40,10 +40,21 @@ self.addEventListener('fetch', function (event) {
|
|||||||
// Register event listener for the 'push' event.
|
// Register event listener for the 'push' event.
|
||||||
self.addEventListener('push', function (event) {
|
self.addEventListener('push', function (event) {
|
||||||
// Keep the service worker alive until the notification is created.
|
// Keep the service worker alive until the notification is created.
|
||||||
const { title, body, data } = event.data.json();
|
const { title, body, tag, data } = event.data.json();
|
||||||
event.waitUntil(
|
|
||||||
self.registration.showNotification(title, { body, data })
|
if (title && body) {
|
||||||
);
|
event.waitUntil(
|
||||||
|
self.registration.showNotification(title, { body, tag, data })
|
||||||
|
);
|
||||||
|
} else if (tag) {
|
||||||
|
event.waitUntil(
|
||||||
|
self.registration.getNotifications({ tag }).then((notifications) => {
|
||||||
|
notifications.forEach((notification) => {
|
||||||
|
notification.close();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('notificationclick', (event) => {
|
self.addEventListener('notificationclick', (event) => {
|
||||||
|
|||||||
@@ -317,10 +317,13 @@ Notifications.pushGroups = async function (notification, groupNames) {
|
|||||||
|
|
||||||
Notifications.rescind = async function (nids) {
|
Notifications.rescind = async function (nids) {
|
||||||
nids = Array.isArray(nids) ? nids : [nids];
|
nids = Array.isArray(nids) ? nids : [nids];
|
||||||
|
|
||||||
|
await plugins.hooks.fire('static:notifications.rescind', { nids });
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetRemove('notifications', nids),
|
db.sortedSetRemove('notifications', nids),
|
||||||
db.deleteAll(nids.map(nid => `notifications:${nid}`)),
|
db.deleteAll(nids.map(nid => `notifications:${nid}`)),
|
||||||
]);
|
]);
|
||||||
|
plugins.hooks.fire('action:notifications.rescind', { nids });
|
||||||
};
|
};
|
||||||
|
|
||||||
Notifications.markRead = async function (nid, uid) {
|
Notifications.markRead = async function (nid, uid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user