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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update.chatId === currentChatId) {
|
const isActiveChat = update.chatId === currentChatId;
|
||||||
|
|
||||||
|
if (isActiveChat) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
actions.requestChatUpdate({ chatId: update.chatId });
|
actions.requestChatUpdate({ chatId: update.chatId });
|
||||||
}, CURRENT_CHAT_UNREAD_DELAY);
|
}, CURRENT_CHAT_UNREAD_DELAY);
|
||||||
} else {
|
} else {
|
||||||
showNewMessageNotification({ chat, message });
|
|
||||||
setGlobal(updateChat(global, update.chatId, {
|
setGlobal(updateChat(global, update.chatId, {
|
||||||
unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1,
|
unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1,
|
||||||
...(update.message.hasUnreadMention && {
|
...(update.message.hasUnreadMention && {
|
||||||
@ -120,6 +121,8 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showNewMessageNotification({ chat, message, isActiveChat });
|
||||||
|
|
||||||
break;
|
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;
|
if (chat.isMuted) return false;
|
||||||
|
|
||||||
|
// Dont show notification for active chat if client has focus
|
||||||
|
if (isActive && document.hasFocus()) return false;
|
||||||
|
|
||||||
await getDispatch().loadNotificationsSettings();
|
await getDispatch().loadNotificationsSettings();
|
||||||
const global = getGlobal();
|
const global = getGlobal();
|
||||||
switch (chat.type) {
|
switch (chat.type) {
|
||||||
@ -225,11 +229,12 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage) {
|
|||||||
export async function showNewMessageNotification({
|
export async function showNewMessageNotification({
|
||||||
chat,
|
chat,
|
||||||
message,
|
message,
|
||||||
}: { chat: ApiChat; message: Partial<ApiMessage> }) {
|
isActiveChat,
|
||||||
|
}: { chat: ApiChat; message: Partial<ApiMessage>; isActiveChat: boolean}) {
|
||||||
if (!checkIfNotificationsSupported()) return;
|
if (!checkIfNotificationsSupported()) return;
|
||||||
if (!message.id) return;
|
if (!message.id) return;
|
||||||
|
|
||||||
const shouldNotify = await checkIfShouldNotify(chat);
|
const shouldNotify = await checkIfShouldNotify(chat, isActiveChat);
|
||||||
if (!shouldNotify) return;
|
if (!shouldNotify) return;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -260,6 +265,9 @@ export async function showNewMessageNotification({
|
|||||||
chatId: chat.id,
|
chatId: chat.id,
|
||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
});
|
});
|
||||||
|
if (window.focus) {
|
||||||
|
window.focus();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user