This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "НаСвязи",
|
"name": "НаСвязи",
|
||||||
"short_name": "НаСвязи",
|
"short_name": "НаСвязи",
|
||||||
|
"categories": ["communication", "utilities", "social", "productivity"],
|
||||||
"start_url": "/",
|
"start_url": "/",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -98,13 +98,18 @@ self.addEventListener('notificationclick', (event) => {
|
|||||||
clients.matchAll({ type: 'window', includeUncontrolled: true }),
|
clients.matchAll({ type: 'window', includeUncontrolled: true }),
|
||||||
])
|
])
|
||||||
.then(([urlToOpen, clientList]) => {
|
.then(([urlToOpen, clientList]) => {
|
||||||
|
const urlToOpenObj = new URL(urlToOpen, location.origin)
|
||||||
for (const client of clientList) {
|
for (const client of clientList) {
|
||||||
console.log('client.url', client.url)
|
console.log('client.url', client.url)
|
||||||
if (client.url === urlToOpen && 'focus' in client) {
|
const clientUrlObj = new URL(client.url)
|
||||||
|
if (
|
||||||
|
urlToOpenObj.pathname + urlToOpenObj.search ===
|
||||||
|
clientUrlObj.pathname + clientUrlObj.search
|
||||||
|
) {
|
||||||
console.log('focus')
|
console.log('focus')
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
client.focus(),
|
'focus' in client && client.focus(),
|
||||||
client.postMessage({
|
client.postMessage({
|
||||||
type: 'notificationClick',
|
type: 'notificationClick',
|
||||||
tag: event.notification.tag,
|
tag: event.notification.tag,
|
||||||
@@ -122,15 +127,14 @@ self.addEventListener('notificationclick', (event) => {
|
|||||||
if (!client) {
|
if (!client) {
|
||||||
console.log('new window not opened')
|
console.log('new window not opened')
|
||||||
for (const client of clientList) {
|
for (const client of clientList) {
|
||||||
return client.navigate(urlToOpen)
|
return client.postMessage({
|
||||||
// return client.postMessage({
|
type: 'notificationClick',
|
||||||
// type: 'notificationClick',
|
url: urlToOpen,
|
||||||
// url: urlToOpen,
|
tag: event.notification.tag,
|
||||||
// tag: event.notification.tag,
|
payload: event.notification.payload,
|
||||||
// payload: event.notification.payload,
|
matchUrl: false,
|
||||||
// matchUrl: false,
|
msg: 'new window not opened',
|
||||||
// msg: 'new window not opened',
|
})
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -138,15 +142,14 @@ self.addEventListener('notificationclick', (event) => {
|
|||||||
console.log('clients.openWindow not available')
|
console.log('clients.openWindow not available')
|
||||||
|
|
||||||
for (const client of clientList) {
|
for (const client of clientList) {
|
||||||
return client.navigate(urlToOpen)
|
return client.postMessage({
|
||||||
// return client.postMessage({
|
type: 'notificationClick',
|
||||||
// type: 'notificationClick',
|
url: urlToOpen,
|
||||||
// url: urlToOpen,
|
tag: event.notification.tag,
|
||||||
// tag: event.notification.tag,
|
payload: event.notification.payload,
|
||||||
// payload: event.notification.payload,
|
matchUrl: false,
|
||||||
// matchUrl: false,
|
msg: 'clients.openWindow not available',
|
||||||
// msg: 'clients.openWindow not available',
|
})
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ const start = async () => {
|
|||||||
const topic = `chat-${msgDoc.qr_code_uri}-${msgDoc.chat}`;
|
const topic = `chat-${msgDoc.qr_code_uri}-${msgDoc.chat}`;
|
||||||
const timestamp = new Date(msgDoc.created_at).getTime();
|
const timestamp = new Date(msgDoc.created_at).getTime();
|
||||||
const tag = `${topic}-${(timestamp - new Date(qrDoc.created_at).getTime()).toString(36)}`;
|
const tag = `${topic}-${(timestamp - new Date(qrDoc.created_at).getTime()).toString(36)}`;
|
||||||
|
console.debug("subscription", subscription);
|
||||||
|
|
||||||
const title = limitStringLengthWithEllipsis(
|
const title = limitStringLengthWithEllipsis(
|
||||||
`${qrDoc.name}: новое сообщение`,
|
`${qrDoc.name}: новое сообщение`,
|
||||||
@@ -141,7 +142,8 @@ const start = async () => {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`Error sending notification to ${row.id} - ${JSON.stringify(error)}`,
|
`Error sending notification to owner ${row.id} - ${JSON.stringify((error as Error).message)}`,
|
||||||
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,7 +221,8 @@ const start = async () => {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`Error sending notification to ${row.id} - ${JSON.stringify(error)}`,
|
`Error sending notification to guest ${row.id} - ${JSON.stringify((error as Error).message)}`,
|
||||||
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user