mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-13 06:35:24 +03:00
Add support for mark as reviewed notification action
This commit is contained in:
parent
315f26b48d
commit
005c3a7c77
@ -165,6 +165,7 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
||||
"direct_url": direct_url,
|
||||
"image": image,
|
||||
"id": reviewId,
|
||||
"type": "alert",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
@ -1,10 +1,29 @@
|
||||
// Notifications Worker
|
||||
|
||||
self.addEventListener("push", function (event) {
|
||||
console.log(`received push at ${new Date()}`)
|
||||
// @ts-expect-error we know this exists
|
||||
if (event.data) {
|
||||
// @ts-expect-error we know this exists
|
||||
const data = event.data.json();
|
||||
|
||||
let actions = [];
|
||||
|
||||
switch (data.type ?? "unknown") {
|
||||
case "alert":
|
||||
actions = [
|
||||
{
|
||||
action: "markReviewed",
|
||||
title: "Mark as Reviewed",
|
||||
},
|
||||
{
|
||||
action: "snooze",
|
||||
title: "Snooze",
|
||||
},
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
// @ts-expect-error we know this exists
|
||||
self.registration.showNotification(data.title, {
|
||||
body: data.message,
|
||||
@ -13,6 +32,7 @@ self.addEventListener("push", function (event) {
|
||||
badge: "/images/maskable-badge.png",
|
||||
tag: data.id,
|
||||
data: { id: data.id, link: data.direct_url },
|
||||
actions,
|
||||
});
|
||||
} else {
|
||||
// pass
|
||||
@ -26,6 +46,18 @@ self.addEventListener("notificationclick", (event) => {
|
||||
// @ts-expect-error we know this exists
|
||||
event.notification.close();
|
||||
|
||||
switch (event.action ?? "default") {
|
||||
case "markReviewed":
|
||||
if (event.notification.data) {
|
||||
fetch("/api/reviews/viewed", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ ids: [event.notification.data.id] }),
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "snooze":
|
||||
break;
|
||||
default:
|
||||
// @ts-expect-error we know this exists
|
||||
if (event.notification.data) {
|
||||
const url = event.notification.data.link;
|
||||
@ -36,4 +68,5 @@ self.addEventListener("notificationclick", (event) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user