Handle image and link

This commit is contained in:
Nicolas Mowen 2024-07-19 14:27:45 -06:00
parent 4fd9a38be7
commit 41a0518cfb
2 changed files with 16 additions and 2 deletions

View File

@ -50,9 +50,16 @@ class FirebaseMessenger(threading.Thread):
state = payload["type"]
# Don't notify if message is an update and important fields don't have an update
if state == "update" and len(payload["before"]["objects"]) == len(payload["after"]["objects"]) and len(payload["before"]["zones"]) == len(payload["after"]["zones"]):
if (
state == "update"
and len(payload["before"]["data"]["objects"])
== len(payload["after"]["data"]["objects"])
and len(payload["before"]["data"]["zones"])
== len(payload["after"]["data"]["zones"])
):
return
reviewId = payload["after"]["id"]
sorted_objects: set[str] = set()
for obj in payload["after"]["data"]["objects"]:
@ -66,6 +73,12 @@ class FirebaseMessenger(threading.Thread):
title=f"{', '.join(sorted_objects).replace('_', ' ').title()}{' was' if state == 'end' else ''} detected in {', '.join(payload['after']['data']['zones']).replace('_', ' ').title()}",
body=f"Detected on {payload['after']['camera'].replace('_', ' ').title()}",
),
webpush=messaging.WebpushConfig(
fcm_options=messaging.WebpushFCMOptions(
link=f"https://localhost:5173/review?id={reviewId}"
)
),
data={"id": reviewId, "imageUrl": f'https://localhost:5173{payload["after"]["thumb_path"].replace("/media/frigate", "")}'},
tokens=[
"cNNicZp6S92qn4kAVJnzd7:APA91bGv-MvDmNoZ2xqJTkPyCTmyv2WG0tfwIqWUuNtq3SXlpQJpdPCCjTEehOLDa0Yphv__KdxOQYEfaFvYfTW2qQevX-tSnRCVa_sJazQ_rfTervpo_zBVJD1T5GfYaY6kr41Wr_fP"
],

View File

@ -29,7 +29,8 @@ messaging.onBackgroundMessage((payload) => {
// Customize notification here
const notificationOptions = {
body: payload.notification.body,
icon: '/images/maskable-icon.png',
icon: ,
tag: payload.data.id, // ensure that the notifications for same items are written over
};
self.registration.showNotification(