@@ -18,11 +18,14 @@ router.post('/', (req, res) => {
18
18
actions,
19
19
closeButtonText,
20
20
toastXml,
21
- event : customEvent
21
+ event : customEvent ,
22
+ reference,
22
23
} = req . body ;
23
24
24
25
const eventName = customEvent ?? '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked' ;
25
26
27
+ const notificationReference = reference ?? ( Date . now ( ) + '.' + Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) ) ;
28
+
26
29
const notification = new Notification ( {
27
30
title,
28
31
body,
@@ -42,13 +45,50 @@ router.post('/', (req, res) => {
42
45
notification . on ( "click" , ( event ) => {
43
46
notifyLaravel ( 'events' , {
44
47
event : eventName || '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked' ,
45
- payload : JSON . stringify ( event )
48
+ payload : {
49
+ reference : notificationReference ,
50
+ event : JSON . stringify ( event ) ,
51
+ } ,
52
+ } ) ;
53
+ } ) ;
54
+
55
+ notification . on ( "action" , ( event , index ) => {
56
+ notifyLaravel ( 'events' , {
57
+ event : '\\Native\\Laravel\\Events\\Notifications\\NotificationActionClicked' ,
58
+ payload : {
59
+ reference : notificationReference ,
60
+ index,
61
+ event : JSON . stringify ( event ) ,
62
+ } ,
63
+ } ) ;
64
+ } ) ;
65
+
66
+ notification . on ( "reply" , ( event , reply ) => {
67
+ notifyLaravel ( 'events' , {
68
+ event : '\\Native\\Laravel\\Events\\Notifications\\NotificationReply' ,
69
+ payload : {
70
+ reference : notificationReference ,
71
+ reply,
72
+ event : JSON . stringify ( event ) ,
73
+ } ,
74
+ } ) ;
75
+ } ) ;
76
+
77
+ notification . on ( "close" , ( event ) => {
78
+ notifyLaravel ( 'events' , {
79
+ event : '\\Native\\Laravel\\Events\\Notifications\\NotificationClosed' ,
80
+ payload : {
81
+ reference : notificationReference ,
82
+ event : JSON . stringify ( event ) ,
83
+ } ,
46
84
} ) ;
47
85
} ) ;
48
86
49
87
notification . show ( ) ;
50
88
51
- res . sendStatus ( 200 ) ;
89
+ res . status ( 200 ) . json ( {
90
+ reference : notificationReference ,
91
+ } ) ;
52
92
} ) ;
53
93
54
94
export default router ;
0 commit comments