Skip to content

Commit

Permalink
Fix threads incorrectly appearing unread
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Oct 2, 2023
1 parent a6799b2 commit c42a4b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 0 additions & 9 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions frontend/openchat-client/src/stores/markRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c42a4b7

Please sign in to comment.