Address service-worker/notifications

This commit is contained in:
Max Leiter 2021-06-28 21:47:09 -07:00
parent b08120307d
commit a37958f6a9
3 changed files with 7 additions and 6 deletions

View file

@ -23,7 +23,7 @@ export function generateChannelContextMenu($root, channel, network) {
label: channel.name,
type: "item",
class: typeMap[channel.type],
link: `/chan-${channel.id}`,
link: `/${network.host}/${channel.name}`,
},
{
type: "divider",

View file

@ -133,11 +133,14 @@ function notifyMessage(targetId, channel, activeChannel, msg) {
const timestamp = Date.parse(msg.time);
try {
const channelTarget = store.getters.findChannel(targetId);
if (store.state.hasServiceWorker) {
navigator.serviceWorker.ready.then((registration) => {
registration.active.postMessage({
type: "notification",
chanId: targetId,
channelName: channelTarget.name,
networkHost: channelTarget.network.host,
timestamp: timestamp,
title: title,
body: body,
@ -155,8 +158,6 @@ function notifyMessage(targetId, channel, activeChannel, msg) {
this.close();
window.focus();
const channelTarget = store.getters.findChannel(targetId);
if (channelTarget) {
switchToChannel(channelTarget.network, channelTarget.channel);
}

View file

@ -129,7 +129,7 @@ function showNotification(event, payload) {
event.waitUntil(
self.registration
.getNotifications({
tag: `chan-${payload.chanId}`,
tag: `${payload.networkHost}/${payload.channelName}`,
})
.then((notifications) => {
for (const notification of notifications) {
@ -137,7 +137,7 @@ function showNotification(event, payload) {
}
return self.registration.showNotification(payload.title, {
tag: `chan-${payload.chanId}`,
tag: `${payload.networkHost}/${payload.channelName}`,
badge: "img/icon-alerted-black-transparent-bg-72x72px.png",
icon: "img/icon-alerted-grey-bg-192x192px.png",
body: payload.body,