diff --git a/client/js/router.js b/client/js/router.js index da12f55c..1ead0f9f 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -142,4 +142,18 @@ function switchToChannel(channel) { return navigate("RoutedChat", {id: channel.id}); } +if ("serviceWorker" in navigator) { + navigator.serviceWorker.addEventListener("message", (event) => { + if (event.data && event.data.type === "open") { + const id = parseInt(event.data.channel.substr(5), 10); // remove "chan-" prefix + + const channelTarget = store.getters.findChannel(id); + + if (channelTarget) { + switchToChannel(channelTarget.channel); + } + } + }); +} + export {initialize, router, navigate, switchToChannel}; diff --git a/client/js/webpush.js b/client/js/webpush.js index 4161dfeb..0c0cbcc4 100644 --- a/client/js/webpush.js +++ b/client/js/webpush.js @@ -2,24 +2,9 @@ import socket from "./socket"; import store from "./store"; -import {switchToChannel} from "./router"; export default {togglePushSubscription}; -if ("serviceWorker" in navigator) { - navigator.serviceWorker.addEventListener("message", (event) => { - if (event.data && event.data.type === "open") { - const id = parseInt(event.data.channel.substr(5), 10); // remove "chan-" prefix - - const channelTarget = store.getters.findChannel(id); - - if (channelTarget) { - switchToChannel(channelTarget.channel); - } - } - }); -} - socket.once("push:issubscribed", function(hasSubscriptionOnServer) { if (!isAllowedServiceWorkersHost()) { store.commit("pushNotificationState", "nohttps");