From 46ae88a6b0436a3c1e15afc1585a6997b5c28c23 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 27 Apr 2021 20:00:22 +0300 Subject: [PATCH] Message List: Fix messages in the current chat are not marked read --- src/modules/actions/apiUpdaters/chats.ts | 23 ++++++++++++++++------- src/modules/selectors/messages.ts | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/modules/actions/apiUpdaters/chats.ts b/src/modules/actions/apiUpdaters/chats.ts index d66d875c5..eb0208bab 100644 --- a/src/modules/actions/apiUpdaters/chats.ts +++ b/src/modules/actions/apiUpdaters/chats.ts @@ -20,6 +20,9 @@ import { const TYPING_STATUS_CLEAR_DELAY = 6000; // 6 seconds +// Enough to animate and mark as read in Message List +const CURRENT_CHAT_UNREAD_DELAY = 1000; + addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'updateChat': { @@ -93,7 +96,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { const { message } = update; const { chatId: currentChatId } = selectCurrentMessageList(global) || {}; - if (message.chatId === currentChatId || (message.senderId === global.currentUserId && !message.isFromScheduled)) { + if (message.senderId === global.currentUserId && !message.isFromScheduled) { return; } @@ -102,12 +105,18 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { return; } - setGlobal(updateChat(global, update.chatId, { - unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1, - ...(update.message.hasUnreadMention && { - unreadMentionsCount: chat.unreadMentionsCount ? chat.unreadMentionsCount + 1 : 1, - }), - })); + if (update.chatId === currentChatId) { + setTimeout(() => { + actions.requestChatUpdate({ chatId: update.chatId }); + }, CURRENT_CHAT_UNREAD_DELAY); + } else { + setGlobal(updateChat(global, update.chatId, { + unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1, + ...(update.message.hasUnreadMention && { + unreadMentionsCount: chat.unreadMentionsCount ? chat.unreadMentionsCount + 1 : 1, + }), + })); + } break; } diff --git a/src/modules/selectors/messages.ts b/src/modules/selectors/messages.ts index ea9599d0c..4ed966814 100644 --- a/src/modules/selectors/messages.ts +++ b/src/modules/selectors/messages.ts @@ -503,7 +503,7 @@ export function selectRealLastReadId(global: GlobalState, chatId: number, thread export function selectFirstUnreadId(global: GlobalState, chatId: number, threadId: number) { if (threadId === MAIN_THREAD_ID) { const chat = selectChat(global, chatId); - if (!chat || !chat.unreadCount) { + if (!chat) { return undefined; } } else {