From cc53cbdcb686dbf92c497cc2c040ad8baf9eab64 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 19 Nov 2021 17:26:18 +0300 Subject: [PATCH] Notifications: Skip toast and sound when app is focused --- src/modules/actions/apiUpdaters/chats.ts | 1 - src/util/notifications.ts | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/modules/actions/apiUpdaters/chats.ts b/src/modules/actions/apiUpdaters/chats.ts index 5074c5f9e..ea9b3fe93 100644 --- a/src/modules/actions/apiUpdaters/chats.ts +++ b/src/modules/actions/apiUpdaters/chats.ts @@ -133,7 +133,6 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { notifyAboutNewMessage({ chat, message, - isActiveChat, }); break; diff --git a/src/util/notifications.ts b/src/util/notifications.ts index 4af6e1d80..7af5a7a68 100644 --- a/src/util/notifications.ts +++ b/src/util/notifications.ts @@ -239,15 +239,15 @@ export async function subscribe() { } } -function checkIfShouldNotify(chat: ApiChat, isActive: boolean) { +function checkIfShouldNotify(chat: ApiChat) { if (!areSettingsLoaded) return false; const global = getGlobal(); const isMuted = selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global)); if (isMuted || chat.isNotJoined || !chat.isListed) { return false; } - // Dont show notification for active chat if client has focus - return !(isActive && document.hasFocus()); + + return document.hasFocus(); } function getNotificationContent(chat: ApiChat, message: ApiMessage) { @@ -319,10 +319,9 @@ async function getAvatar(chat: ApiChat) { export async function notifyAboutNewMessage({ chat, message, - isActiveChat, -}: { chat: ApiChat; message: Partial; isActiveChat: boolean }) { +}: { chat: ApiChat; message: Partial }) { const { hasWebNotifications } = await loadNotificationSettings(); - if (!checkIfShouldNotify(chat, isActiveChat)) return; + if (!checkIfShouldNotify(chat)) return; if (!hasWebNotifications) { // only play sound if web notifications are disabled playNotifySoundDebounced(String(message.id) || chat.id);