From b5cfaa4581891f53034cffb9c1dc0fd59bbd93ae Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Mon, 2 Oct 2023 15:43:08 +0100 Subject: [PATCH] Fix latest message in thread appearing unread incorrectly (#4472) --- frontend/openchat-client/src/openchat.ts | 9 --------- frontend/openchat-client/src/stores/markRead.ts | 7 +++++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/frontend/openchat-client/src/openchat.ts b/frontend/openchat-client/src/openchat.ts index 7ce1b16def..c2afceef49 100644 --- a/frontend/openchat-client/src/openchat.ts +++ b/frontend/openchat-client/src/openchat.ts @@ -2174,15 +2174,6 @@ export class OpenChat extends OpenChatAgentWorker { this.config.meteredApiKey, ); - const isFollowedByMe = - this._liveState.threadsFollowedByMe.get(chat.id)?.has(threadRootMessageIndex) ?? - false; - if (isFollowedByMe) { - const lastLoadedMessageIdx = this.lastMessageIndex(this._liveState.threadEvents); - if (lastLoadedMessageIdx !== undefined) { - this.markThreadRead(chat.id, threadRootMessageIndex, lastLoadedMessageIdx); - } - } if (ascending) { this.dispatchEvent(new LoadedNewThreadMessages()); } else { diff --git a/frontend/openchat-client/src/stores/markRead.ts b/frontend/openchat-client/src/stores/markRead.ts index 7c52384df5..337ddb4897 100644 --- a/frontend/openchat-client/src/stores/markRead.ts +++ b/frontend/openchat-client/src/stores/markRead.ts @@ -53,7 +53,10 @@ export class MessagesRead { } updateThread(rootIndex: number, readUpTo: number): void { - this.threads[rootIndex] = readUpTo; + const current = this.threads[rootIndex]; + if (current === undefined || current < readUpTo) { + this.threads[rootIndex] = readUpTo; + } } setThreads(threads: ThreadRead[]): void { @@ -378,7 +381,7 @@ export class MessageReadTracker { return this.waiting.get(context)?.has(messageId) ?? false; } else if (context.threadRootMessageIndex !== undefined) { const serverState = this.serverState.get(context.chatId); - if ((serverState?.threads[context.threadRootMessageIndex] ?? -1) > messageIndex) + if ((serverState?.threads[context.threadRootMessageIndex] ?? -1) >= messageIndex) return true; const localState = this.state.get(context.chatId); if ((localState?.threads[context.threadRootMessageIndex] ?? -1) >= messageIndex)