Chat: Fix flickering badge for incoming message in current chat

This commit is contained in:
Alexander Zinchuk 2022-10-17 17:51:29 +02:00
parent d0735fcc0e
commit dc41aa0ea9

View File

@ -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,