From dc41aa0ea9a880bb8c7f773c61d5186bd628cf59 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 17 Oct 2022 17:51:29 +0200 Subject: [PATCH] Chat: Fix flickering badge for incoming message in current chat --- src/global/actions/apiUpdaters/chats.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/global/actions/apiUpdaters/chats.ts b/src/global/actions/apiUpdaters/chats.ts index ca18cacae..ddfcbeb02 100644 --- a/src/global/actions/apiUpdaters/chats.ts +++ b/src/global/actions/apiUpdaters/chats.ts @@ -105,19 +105,26 @@ addActionHandler('apiUpdate', (global, actions, update) => { && update.chatId === currentChatId ); + const hasMention = Boolean(update.message.id && update.message.hasUnreadMention); + if (isActiveChat) { setTimeout(() => { actions.requestChatUpdate({ chatId: update.chatId }); }, CURRENT_CHAT_UNREAD_DELAY); + } else { + global = updateChat(global, update.chatId, { + unreadCount: (chat.unreadCount || 0) + 1, + ...(hasMention && { unreadMentionsCount: (chat.unreadMentionsCount || 0) + 1 }), + }); } - setGlobal(updateChat(global, update.chatId, { - unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1, - ...(update.message.id && update.message.hasUnreadMention && { - unreadMentionsCount: (chat.unreadMentionsCount || 0) + 1, - unreadMentions: [...(chat.unreadMentions || []), update.message.id], - }), - })); + if (hasMention) { + global = updateChat(global, update.chatId, { + unreadMentions: [...(chat.unreadMentions || []), update.message.id!], + }); + } + + setGlobal(global); notifyAboutMessage({ chat,