Fixed redis error, and added link on click on notifications
This commit is contained in:
@@ -13,6 +13,12 @@
|
||||
v-model="pushMessage"
|
||||
placeholder="Push meldingtekst"
|
||||
/>
|
||||
<input
|
||||
id="notification-link"
|
||||
type="text"
|
||||
v-model="pushLink"
|
||||
placeholder="Push-click link"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="button-container">
|
||||
@@ -173,6 +179,7 @@ export default {
|
||||
winners: [],
|
||||
wines: [],
|
||||
pushMessage: "",
|
||||
pushLink: "/",
|
||||
toastText: undefined,
|
||||
showToast: false,
|
||||
showCamera: false,
|
||||
@@ -239,7 +246,7 @@ export default {
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
method: "POST",
|
||||
body: JSON.stringify({ message: this.pushMessage })
|
||||
body: JSON.stringify({ message: this.pushMessage, link: this.pushLink })
|
||||
});
|
||||
let response = await _response.json();
|
||||
if (response) {
|
||||
|
||||
@@ -14,6 +14,18 @@ self.addEventListener("activate", event => {
|
||||
event.waitUntil(addCache(CACHE_NAME, STATIC_CACHE_URLS));
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", function(event) {
|
||||
event.notification.close();
|
||||
if (
|
||||
event.notification.data != undefined &&
|
||||
event.notification.data.link != undefined
|
||||
) {
|
||||
event.waitUntil(clients.openWindow(event.notification.data.link));
|
||||
} else {
|
||||
event.waitUntil(clients.openWindow("/"));
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener("message", event => {
|
||||
if (!__PUBLICKEY__) {
|
||||
return;
|
||||
@@ -52,8 +64,17 @@ self.addEventListener("message", event => {
|
||||
self.addEventListener("push", function(event) {
|
||||
if (event.data) {
|
||||
var message = JSON.parse(event.data.text());
|
||||
var link = "/";
|
||||
if (message.link != undefined) {
|
||||
link = message.link;
|
||||
}
|
||||
|
||||
showLocalNotification(message.title, message.message, self.registration);
|
||||
showLocalNotification(
|
||||
message.title,
|
||||
message.message,
|
||||
link,
|
||||
self.registration
|
||||
);
|
||||
} else {
|
||||
}
|
||||
});
|
||||
@@ -105,12 +126,13 @@ self.addEventListener("fetch", event => {
|
||||
}
|
||||
});
|
||||
|
||||
function showLocalNotification(title, body, swRegistration) {
|
||||
function showLocalNotification(title, body, link, swRegistration) {
|
||||
const options = {
|
||||
body,
|
||||
icon: "https://lottis.vin/public/assets/images/favicon.png",
|
||||
image: "https://lottis.vin/public/assets/images/favicon.png",
|
||||
vibrate: [300]
|
||||
vibrate: [300],
|
||||
data: { link: link }
|
||||
};
|
||||
swRegistration.showNotification(title, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user