mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +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({
|
notifyAboutNewMessage({
|
||||||
chat,
|
chat,
|
||||||
message,
|
message,
|
||||||
isActiveChat,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -239,15 +239,15 @@ export async function subscribe() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfShouldNotify(chat: ApiChat, isActive: boolean) {
|
function checkIfShouldNotify(chat: ApiChat) {
|
||||||
if (!areSettingsLoaded) return false;
|
if (!areSettingsLoaded) return false;
|
||||||
const global = getGlobal();
|
const global = getGlobal();
|
||||||
const isMuted = selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global));
|
const isMuted = selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global));
|
||||||
if (isMuted || chat.isNotJoined || !chat.isListed) {
|
if (isMuted || chat.isNotJoined || !chat.isListed) {
|
||||||
return false;
|
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) {
|
function getNotificationContent(chat: ApiChat, message: ApiMessage) {
|
||||||
@ -319,10 +319,9 @@ async function getAvatar(chat: ApiChat) {
|
|||||||
export async function notifyAboutNewMessage({
|
export async function notifyAboutNewMessage({
|
||||||
chat,
|
chat,
|
||||||
message,
|
message,
|
||||||
isActiveChat,
|
}: { chat: ApiChat; message: Partial<ApiMessage> }) {
|
||||||
}: { chat: ApiChat; message: Partial<ApiMessage>; isActiveChat: boolean }) {
|
|
||||||
const { hasWebNotifications } = await loadNotificationSettings();
|
const { hasWebNotifications } = await loadNotificationSettings();
|
||||||
if (!checkIfShouldNotify(chat, isActiveChat)) return;
|
if (!checkIfShouldNotify(chat)) return;
|
||||||
if (!hasWebNotifications) {
|
if (!hasWebNotifications) {
|
||||||
// only play sound if web notifications are disabled
|
// only play sound if web notifications are disabled
|
||||||
playNotifySoundDebounced(String(message.id) || chat.id);
|
playNotifySoundDebounced(String(message.id) || chat.id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user