diff --git a/src/api/gramjs/updates/mtpUpdateHandler.ts b/src/api/gramjs/updates/mtpUpdateHandler.ts index d9d7891ec..937c6ea20 100644 --- a/src/api/gramjs/updates/mtpUpdateHandler.ts +++ b/src/api/gramjs/updates/mtpUpdateHandler.ts @@ -514,6 +514,7 @@ export function updater(update: Update) { readState: { lastReadInboxMessageId: update.maxId, unreadCount: update.stillUnreadCount, + hasUnreadMark: undefined, }, }); } else if (update instanceof GramJs.UpdateReadHistoryOutbox) { @@ -533,6 +534,7 @@ export function updater(update: Update) { readState: { lastReadInboxMessageId: update.maxId, unreadCount: update.stillUnreadCount, + hasUnreadMark: undefined, }, }); } else if (update instanceof GramJs.UpdateReadChannelOutbox) { diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 68e165fc5..6f659d982 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -1516,6 +1516,7 @@ addActionHandler('markChatMessagesRead', async (global, actions, payload): Promi if (!result?.topics?.length) return; + const topicIdsToMarkRead: number[] = []; result.topics.forEach((topicWithState) => { global = updateTopicWithState(global, id, topicWithState); @@ -1530,7 +1531,13 @@ addActionHandler('markChatMessagesRead', async (global, actions, payload): Promi return; } - actions.markTopicRead({ chatId: id, topicId: topicWithState.topic.id }); + topicIdsToMarkRead.push(topicWithState.topic.id); + }); + + setGlobal(global); + + topicIdsToMarkRead.forEach((topicId) => { + actions.markTopicRead({ chatId: id, topicId }); }); lastTopic = result.topics[result.topics.length - 1].topic; @@ -1539,6 +1546,10 @@ addActionHandler('markChatMessagesRead', async (global, actions, payload): Promi hasMoreTopics = false; } } + + if (chatReadState?.hasUnreadMark) { + actions.markChatRead({ id }); + } }); addActionHandler('markChatRead', (global, actions, payload): ActionReturnType => { diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index ac7b73952..80b762f10 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -1314,9 +1314,11 @@ addActionHandler('markMessageListRead', (global, actions, payload): ActionReturn }; } + const threadReadState = selectThreadReadState(global, chatId, threadId); + global = replaceThreadReadStateParam(global, chatId, threadId, 'hasUnreadMark', undefined); + const viewportIds = selectViewportIds(global, chatId, threadId, tabId); const minId = selectFirstUnreadId(global, chatId, threadId); - const threadReadState = selectThreadReadState(global, chatId, threadId); if (!viewportIds || !minId || !threadReadState?.unreadCount) { return global;