Skip to content

Commit c63f2cc

Browse files
committed
chat: show only thread containing a fragment
1 parent 723027a commit c63f2cc

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/packages/frontend/chat/chatroom.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ import Filter from "./filter";
4040
import ChatInput from "./input";
4141
import { LLMCostEstimationChat } from "./llm-cost-estimation";
4242
import type { ChatState } from "./store";
43-
import type { ChatMessages, SubmitMentionsFn } from "./types";
44-
import { INPUT_HEIGHT, markChatAsReadIfUnseen } from "./utils";
43+
import type {
44+
ChatMessageTyped,
45+
ChatMessages,
46+
SubmitMentionsFn,
47+
} from "./types";
48+
import { INPUT_HEIGHT, markChatAsReadIfUnseen, getThreadRootDate } from "./utils";
4549
import { ALL_THREADS_KEY, useThreadList } from "./threads";
4650

4751
const FILTER_RECENT_NONE = {
@@ -190,6 +194,38 @@ export function ChatRoom({
190194
}
191195
}, [selectedThreadKey]);
192196

197+
useEffect(() => {
198+
if (!fragmentId || isAllThreadsSelected || messages == null) {
199+
return;
200+
}
201+
const parsed = parseFloat(fragmentId);
202+
if (!isFinite(parsed)) {
203+
return;
204+
}
205+
const keyStr = `${parsed}`;
206+
let message = messages.get(keyStr) as ChatMessageTyped | undefined;
207+
if (message == null) {
208+
for (const [, msg] of messages) {
209+
const dateField = msg?.get("date");
210+
if (
211+
dateField != null &&
212+
typeof dateField.valueOf === "function" &&
213+
dateField.valueOf() === parsed
214+
) {
215+
message = msg;
216+
break;
217+
}
218+
}
219+
}
220+
if (message == null) return;
221+
const root = getThreadRootDate({ date: parsed, messages }) || parsed;
222+
const threadKey = `${root}`;
223+
if (threadKey !== selectedThreadKey) {
224+
setAllowAutoSelectThread(false);
225+
setSelectedThreadKey(threadKey);
226+
}
227+
}, [fragmentId, isAllThreadsSelected, messages, selectedThreadKey]);
228+
193229
const handleToggleAllChats = (checked: boolean) => {
194230
if (checked) {
195231
setAllowAutoSelectThread(false);

0 commit comments

Comments
 (0)