Skip to content

Commit d4cde45

Browse files
committed
PushNotifications: Fix dynamic url passthrough
1 parent 78e1d9c commit d4cde45

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

application/Model/Email.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ private function execPushNotifications() {
508508
'publicKey' => $row['p256dh'],
509509
'authToken' => $row['auth']
510510
]),
511-
'payload' => '{msg: "Please continue your survey!", url: "' . run_url($this->run->name) . '"}'
511+
'payload' => '{"msg": "' . $this->body . '", "url": "' . run_url($this->run->name) . '"}'
512512
];
513+
error_log('body: ' . $this->body_parsed);
514+
error_log('payload: ' . $notifications[sizeof($notifications)-1]['payload']);
513515
}
514516

515517
$webPush = new WebPush($push_auth);

webroot/sw.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ notification_options = {
1414
}
1515

1616
function dispatchNotification() {
17-
console.log('dispatchingNotification');
1817
self.registration.showNotification('Please continue your Survey', notification_options);
1918

2019
}
@@ -31,18 +30,41 @@ self.addEventListener('activate', function(event) {
3130

3231

3332
self.addEventListener('push', function(event) {
34-
console.log('Got a push event');
3533
if (!(self.Notification && self.Notification.permission === 'granted')) {
3634
return;
3735
}
38-
dispatchNotification();
36+
37+
if (event.data) {
38+
console.log('there is data...');
39+
var data = event.data.json();
40+
console.log(data);
41+
console.log(data.msg);
42+
console.log(data.url);
43+
}
44+
let notification_options = {
45+
"icon": "assets/site/img/logo.png",
46+
"image": "assets/site/img/logo.png",
47+
"vibrate": [300,100,400],
48+
"requireInteraction": true,
49+
"data": data,
50+
tag: 'renotify',
51+
renotify: true,
52+
}
53+
54+
self.registration.showNotification(data.msg, notification_options);
55+
56+
//dispatchNotification();
3957
});
4058

4159
self.addEventListener('notificationclick', function(event) {
4260
var notification = event.notification;
4361
var action = event.action;
4462

45-
console.log(notification);
63+
if (event.notification.data) {
64+
console.log(event.notification.data);
65+
console.log(event.notification.data.msg);
66+
console.log(event.notification.data.url);
67+
}
4668

4769
if (action === 'confirm') {
4870
console.log('Confirm was chosen');
@@ -57,10 +79,10 @@ self.addEventListener('notificationclick', function(event) {
5779
});
5880

5981
if (client !== undefined) {
60-
client.navigate('https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest');
82+
client.navigate(event.notification.data.url);
6183
client.focus();
6284
} else {
63-
clients.openWindow('https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest');
85+
clients.openWindow(event.notification.data.url);
6486
}
6587
notification.close();
6688
})

0 commit comments

Comments
 (0)