From d0d48b57c1f7a453e3311b954a5fab8e7119b292 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Mon, 24 Jul 2023 15:52:39 -0600 Subject: [PATCH] Add support for custom events https://nativephp.com/docs/1/the-basics/notifications#notification-click-events says that you can send custom events when clicking on a notification. However, this code currently always sends the same static event, and furthermore can be improved by sending the payload of the click event for better handling of the click event in PHP. This code will also benefit from a related PR to nativephp/laravel. --- src/server/api/notification.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/server/api/notification.ts b/src/server/api/notification.ts index f8ad207..a8b427c 100644 --- a/src/server/api/notification.ts +++ b/src/server/api/notification.ts @@ -4,14 +4,15 @@ import {notifyLaravel} from "../utils"; const router = express.Router(); router.post('/', (req, res) => { - const {title, body} = req.body + const {title, body, customEvent: event} = req.body + const eventName = customEvent ?? '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked'; const notification = new Notification({title, body}); notification.on("click", (event)=>{ notifyLaravel('events', { - event: '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked', - payload: [] + event: eventName, + payload: JSON.stringify(event) }) })