Message List: Fix topic unread count (#4554)

This commit is contained in:
Alexander Zinchuk 2024-05-17 15:45:24 +02:00
parent 6e37c5b163
commit 5f4103f64f
2 changed files with 10 additions and 1 deletions

View File

@ -958,6 +958,12 @@ export async function markMessageListRead({
if (threadId === MAIN_THREAD_ID) {
void requestChatUpdate({ chat, noLastMessage: true });
} else if (chat.isForum) {
onUpdate({
'@type': 'updateTopic',
chatId: chat.id,
topicId: Number(threadId),
});
}
}

View File

@ -857,7 +857,7 @@ addActionHandler('markMessageListRead', (global, actions, payload): ActionReturn
return global;
}
const readCount = countSortedIds(viewportIds!, minId, maxId);
const readCount = countSortedIds(viewportIds, minId, maxId);
if (!readCount) {
return global;
}
@ -2136,6 +2136,9 @@ addActionHandler('copyMessageLink', async (global, actions, payload): Promise<vo
});
function countSortedIds(ids: number[], from: number, to: number) {
// If ids are outside viewport, we cannot get correct count
if (ids.length === 0 || from < ids[0] || to > ids[ids.length - 1]) return undefined;
let count = 0;
for (let i = 0, l = ids.length; i < l; i++) {