feat(dm): implement signed direct messaging with web push fallback

This commit is contained in:
ai5590
2026-04-12 19:34:55 +03:00
parent 1ee2a1cf62
commit 62e55dbaec
21 changed files with 875 additions and 189 deletions
+16 -26
View File
@@ -1,30 +1,20 @@
/* global importScripts, firebase */
importScripts('https://www.gstatic.com/firebasejs/10.12.2/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.12.2/firebase-messaging-compat.js');
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
// Заполните теми же значениями, что и в shine-UI/index.html
const FIREBASE_CONFIG = {
apiKey: '',
authDomain: '',
projectId: '',
messagingSenderId: '',
appId: '',
};
if (FIREBASE_CONFIG.apiKey && firebase && firebase.messaging) {
if (!firebase.apps.length) {
firebase.initializeApp(FIREBASE_CONFIG);
self.addEventListener('push', (event) => {
let body = 'Новое сообщение SHiNE';
try {
if (event.data) {
const text = event.data.text();
body = text || body;
}
} catch {
// ignore
}
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
const title = payload?.notification?.title || 'Новое сообщение';
const options = {
body: payload?.notification?.body || '',
data: payload?.data || {},
};
self.registration.showNotification(title, options);
});
}
event.waitUntil(self.registration.showNotification('SHiNE: входящее сообщение', {
body,
tag: 'shine-direct-message',
renotify: true,
}));
});