mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-21 21:01:29 +01:00
Notifications: Skip toast and sound when app is focused
This commit is contained in:
parent
58d251b67e
commit
cc53cbdcb6
@ -133,7 +133,6 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
notifyAboutNewMessage({
|
||||
chat,
|
||||
message,
|
||||
isActiveChat,
|
||||
});
|
||||
|
||||
break;
|
||||
|
@ -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<ApiMessage>; isActiveChat: boolean }) {
|
||||
}: { chat: ApiChat; message: Partial<ApiMessage> }) {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user