Chat: Mark as read fixes (#6904)

This commit is contained in:
zubiden 2026-05-05 13:46:16 +02:00 committed by Alexander Zinchuk
parent 6ca0fbfacb
commit c89d8089a1
3 changed files with 17 additions and 2 deletions

View File

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

View File

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

View File

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