Forum notifications

This commit is contained in:
Eduard Urbach 2017-07-15 02:32:54 +02:00
parent c4bc17ae7f
commit 1fd9c284de
2 changed files with 13 additions and 4 deletions

View File

@ -43,6 +43,8 @@ component Settings(user *arn.User)
button.action(data-action="testNotification", data-trigger="click")
Icon("paper-plane")
span Send test notification
p Notifications are currently used for forum replies only.
.widget.mountable
h3.widget-title

View File

@ -145,7 +145,8 @@ self.addEventListener("push", (evt: PushEvent) => {
(self as any).registration.showNotification(payload.title, {
body: payload.message,
icon: payload.icon,
image: payload.image
image: payload.image,
data: payload.link
})
)
})
@ -155,12 +156,18 @@ self.addEventListener("pushsubscriptionchange", (evt: any) => {
})
self.addEventListener("notificationclick", (evt: NotificationEvent) => {
console.log(evt)
evt.notification.close()
let notification = evt.notification
notification.close()
evt.waitUntil(
(self as any).clients.matchAll().then(function(clientList) {
// If we have a link, use that link to open a new window.
let url = notification.data
if(url) {
return (self as any).clients.openWindow(url)
}
// If there is at least one client, focus it.
if(clientList.length > 0) {
return clientList[0].focus()