mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +01:00
Notification: Fix focusing window on click (#1067)
This commit is contained in:
parent
278b94ca49
commit
2c1197592a
@ -106,12 +106,13 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (update.chatId === currentChatId) {
|
||||
const isActiveChat = update.chatId === currentChatId;
|
||||
|
||||
if (isActiveChat) {
|
||||
setTimeout(() => {
|
||||
actions.requestChatUpdate({ chatId: update.chatId });
|
||||
}, CURRENT_CHAT_UNREAD_DELAY);
|
||||
} else {
|
||||
showNewMessageNotification({ chat, message });
|
||||
setGlobal(updateChat(global, update.chatId, {
|
||||
unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1,
|
||||
...(update.message.hasUnreadMention && {
|
||||
@ -120,6 +121,8 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
}));
|
||||
}
|
||||
|
||||
showNewMessageNotification({ chat, message, isActiveChat });
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -161,8 +161,12 @@ export async function subscribe() {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkIfShouldNotify(chat: ApiChat) {
|
||||
async function checkIfShouldNotify(chat: ApiChat, isActive: boolean) {
|
||||
if (chat.isMuted) return false;
|
||||
|
||||
// Dont show notification for active chat if client has focus
|
||||
if (isActive && document.hasFocus()) return false;
|
||||
|
||||
await getDispatch().loadNotificationsSettings();
|
||||
const global = getGlobal();
|
||||
switch (chat.type) {
|
||||
@ -225,11 +229,12 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage) {
|
||||
export async function showNewMessageNotification({
|
||||
chat,
|
||||
message,
|
||||
}: { chat: ApiChat; message: Partial<ApiMessage> }) {
|
||||
isActiveChat,
|
||||
}: { chat: ApiChat; message: Partial<ApiMessage>; isActiveChat: boolean}) {
|
||||
if (!checkIfNotificationsSupported()) return;
|
||||
if (!message.id) return;
|
||||
|
||||
const shouldNotify = await checkIfShouldNotify(chat);
|
||||
const shouldNotify = await checkIfShouldNotify(chat, isActiveChat);
|
||||
if (!shouldNotify) return;
|
||||
|
||||
const {
|
||||
@ -260,6 +265,9 @@ export async function showNewMessageNotification({
|
||||
chatId: chat.id,
|
||||
messageId: message.id,
|
||||
});
|
||||
if (window.focus) {
|
||||
window.focus();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user