mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-11 04:27:40 +01:00
Merge pull request #306 from vector-im/bwindels/prevent-reload-on-notif-click
Fix reloading or opening wrong page when clicking notif
This commit is contained in:
commit
5a54eda512
@ -76,6 +76,8 @@ export class ServiceWorkerHandler {
|
|||||||
// this flag is read in fetch.js
|
// this flag is read in fetch.js
|
||||||
this.haltRequests = true;
|
this.haltRequests = true;
|
||||||
event.source.postMessage({replyTo: data.id});
|
event.source.postMessage({replyTo: data.id});
|
||||||
|
} else if (data.type === "openRoom") {
|
||||||
|
this._navigation.push("room", data.payload.roomId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,13 +196,13 @@ async function openClientFromNotif(event) {
|
|||||||
const {sessionId, roomId} = event.notification.data;
|
const {sessionId, roomId} = event.notification.data;
|
||||||
const sessionHash = `#/session/${sessionId}`;
|
const sessionHash = `#/session/${sessionId}`;
|
||||||
const roomHash = `${sessionHash}/room/${roomId}`;
|
const roomHash = `${sessionHash}/room/${roomId}`;
|
||||||
const roomURL = `/${roomHash}`;
|
|
||||||
const clientWithSession = await findClient(async client => {
|
const clientWithSession = await findClient(async client => {
|
||||||
return await sendAndWaitForReply(client, "hasSessionOpen", {sessionId});
|
return await sendAndWaitForReply(client, "hasSessionOpen", {sessionId});
|
||||||
});
|
});
|
||||||
if (clientWithSession) {
|
if (clientWithSession) {
|
||||||
console.log("notificationclick: client has session open, showing room there");
|
console.log("notificationclick: client has session open, showing room there");
|
||||||
clientWithSession.navigate(roomURL);
|
// use a message rather than clientWithSession.navigate here as this refreshes the page on chrome
|
||||||
|
clientWithSession.postMessage({type: "openRoom", payload: {roomId}});
|
||||||
if ('focus' in clientWithSession) {
|
if ('focus' in clientWithSession) {
|
||||||
try {
|
try {
|
||||||
await clientWithSession.focus();
|
await clientWithSession.focus();
|
||||||
@ -210,6 +210,7 @@ async function openClientFromNotif(event) {
|
|||||||
}
|
}
|
||||||
} else if (self.clients.openWindow) {
|
} else if (self.clients.openWindow) {
|
||||||
console.log("notificationclick: no client found with session open, opening new window");
|
console.log("notificationclick: no client found with session open, opening new window");
|
||||||
|
const roomURL = new URL(`./${roomHash}`, baseURL).href;
|
||||||
await self.clients.openWindow(roomURL);
|
await self.clients.openWindow(roomURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user