Remove cyclical dependency in router<->webpush

This commit is contained in:
Pavel Djundik 2020-01-03 20:02:22 +02:00
parent 7b507e5248
commit 5fe0710724
2 changed files with 14 additions and 15 deletions

View file

@ -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};

View file

@ -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");