Message List: Fix messages in the current chat are not marked read

This commit is contained in:
Alexander Zinchuk 2021-04-27 20:00:22 +03:00
parent 44058300e5
commit 46ae88a6b0
2 changed files with 17 additions and 8 deletions

View File

@ -20,6 +20,9 @@ import {
const TYPING_STATUS_CLEAR_DELAY = 6000; // 6 seconds 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) => { addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
switch (update['@type']) { switch (update['@type']) {
case 'updateChat': { case 'updateChat': {
@ -93,7 +96,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
const { message } = update; const { message } = update;
const { chatId: currentChatId } = selectCurrentMessageList(global) || {}; const { chatId: currentChatId } = selectCurrentMessageList(global) || {};
if (message.chatId === currentChatId || (message.senderId === global.currentUserId && !message.isFromScheduled)) { if (message.senderId === global.currentUserId && !message.isFromScheduled) {
return; return;
} }
@ -102,12 +105,18 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
return; return;
} }
setGlobal(updateChat(global, update.chatId, { if (update.chatId === currentChatId) {
unreadCount: chat.unreadCount ? chat.unreadCount + 1 : 1, setTimeout(() => {
...(update.message.hasUnreadMention && { actions.requestChatUpdate({ chatId: update.chatId });
unreadMentionsCount: chat.unreadMentionsCount ? chat.unreadMentionsCount + 1 : 1, }, 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; break;
} }

View File

@ -503,7 +503,7 @@ export function selectRealLastReadId(global: GlobalState, chatId: number, thread
export function selectFirstUnreadId(global: GlobalState, chatId: number, threadId: number) { export function selectFirstUnreadId(global: GlobalState, chatId: number, threadId: number) {
if (threadId === MAIN_THREAD_ID) { if (threadId === MAIN_THREAD_ID) {
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
if (!chat || !chat.unreadCount) { if (!chat) {
return undefined; return undefined;
} }
} else { } else {