Добавить диагностику PWA/Push и endpoint тестового push

This commit is contained in:
AidarKC
2026-04-21 01:10:56 +03:00
parent 185ba5b1d3
commit d07602b0a9
11 changed files with 811 additions and 4 deletions
+8 -3
View File
@@ -16,6 +16,7 @@ self.addEventListener('push', (event) => {
let rawText = '';
let kind = '';
let fromLogin = '';
let title = '';
try {
if (event.data) {
const text = event.data.text();
@@ -23,6 +24,7 @@ self.addEventListener('push', (event) => {
try {
const json = JSON.parse(rawText || '{}');
kind = String(json.kind || '');
title = String(json.title || '');
body = String(json.text || '');
fromLogin = String(json.fromLogin || '');
} catch {
@@ -33,11 +35,14 @@ self.addEventListener('push', (event) => {
// ignore
}
const shouldNotify = kind === 'new_message' || (!kind && body);
const shouldNotify = kind === 'new_message' || kind === 'test_push' || (!kind && body);
const notificationTitle = kind === 'test_push'
? (title || 'SHiNE: тестовый push')
: 'SHiNE: входящее сообщение';
const notifyPromise = shouldNotify
? self.registration.showNotification('SHiNE: входящее сообщение', {
? self.registration.showNotification(notificationTitle, {
body: body || (fromLogin ? `Вам пришло сообщение от ${fromLogin}` : 'Вам пришло сообщение'),
tag: 'shine-direct-message',
tag: kind === 'test_push' ? 'shine-test-push' : 'shine-direct-message',
renotify: true,
})
: Promise.resolve();