SHA256
Поправил пуши для личных сообщений
This commit is contained in:
+20
-8
@@ -15,6 +15,7 @@ import {
|
||||
import { attachScrollToBottomButton } from './components/scroll-to-bottom-button.js';
|
||||
import { initPwaInstallPromptHandling } from './services/pwa-install-service.js';
|
||||
import { initPwaPush } from './services/pwa-push-service.js';
|
||||
import { dmNotificationTag, dmUnreadLabel } from './services/dm-push-notifications.js';
|
||||
import { initCallUiOverlay } from './services/call-ui-service.js';
|
||||
import { showToast } from './services/channels-ux.js';
|
||||
import { toUserMessage } from './services/ui-error-texts.js';
|
||||
@@ -49,6 +50,7 @@ import {
|
||||
deleteConversationMessagesBefore,
|
||||
deleteSignedMessageByBaseKey,
|
||||
markIncomingReadByBaseKey,
|
||||
getChatMessages,
|
||||
markOutgoingDeliveryState,
|
||||
markOutgoingReadByBaseKey,
|
||||
normalizeDmChatId,
|
||||
@@ -718,19 +720,24 @@ async function tryLockPortraitOrientation() {
|
||||
}
|
||||
}
|
||||
|
||||
async function notifyHiddenIncomingMessage(fromLogin, text) {
|
||||
const body = String(text || '').trim() || `Вам пришло сообщение от ${fromLogin}`;
|
||||
async function notifyHiddenIncomingMessage(fromLogin, toLogin, unreadCount, messageKey, notificationVersionMs) {
|
||||
const title = `Сообщение от ${fromLogin}`;
|
||||
const body = dmUnreadLabel(unreadCount);
|
||||
try {
|
||||
const registration = await navigator.serviceWorker?.getRegistration?.();
|
||||
if (registration?.showNotification) {
|
||||
await registration.showNotification(title, {
|
||||
body,
|
||||
tag: `shine-hidden-dm-${String(fromLogin || '').trim().toLowerCase() || 'unknown'}`,
|
||||
renotify: true,
|
||||
tag: dmNotificationTag(toLogin, fromLogin),
|
||||
renotify: true, // каждое новое DM — отдельный сигнал, но одна карточка на собеседника
|
||||
silent: false,
|
||||
data: {
|
||||
kind: 'new_message',
|
||||
fromLogin,
|
||||
toLogin,
|
||||
messageKey,
|
||||
unreadCount,
|
||||
notificationVersionMs,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
@@ -1849,14 +1856,19 @@ async function init() {
|
||||
// Чат «без звука»: сообщение и счётчик непрочитанных приходят как обычно, но без сигнала и уведомления.
|
||||
if (added && isIncomingForCurrent && !payload.backlog && !isDmChatMuted(chatId)) {
|
||||
const parsedText = parseDmTechBlocks(text);
|
||||
const displayText = String(parsedText.displayText || '');
|
||||
const suppressHiddenNotification = parsedText.callSummary?.status === 'completed';
|
||||
const toLogin = String(state.session.login || payload.toLogin || '').trim();
|
||||
const serverUnread = Number(payload.unreadCount);
|
||||
const localUnread = getChatMessages(chatId)
|
||||
.filter((row) => row?.from === 'in' && row?.unread && Number(row?.messageType) === 1).length;
|
||||
const unreadCount = Number.isFinite(serverUnread) && serverUnread > 0
|
||||
? serverUnread : Math.max(1, localUnread);
|
||||
if (document.visibilityState === 'visible') {
|
||||
void playDmSignal({ extended: false });
|
||||
} else if (Notification.permission === 'granted' && !suppressHiddenNotification) {
|
||||
try {
|
||||
void notifyHiddenIncomingMessage(fromLogin, displayText || '');
|
||||
} catch {}
|
||||
void notifyHiddenIncomingMessage(
|
||||
fromLogin, toLogin, unreadCount, messageKey, Number(payload.notificationVersionMs || 0),
|
||||
);
|
||||
} else if (!suppressHiddenNotification) {
|
||||
void playDmSignal({ extended: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user