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
// 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;
}

View File

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