SHA256
Добавить диагностику PWA/Push и endpoint тестового push
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user