Skip to content

Commit dbca134

Browse files
committed
chat: show message when ai assistant interaction happens
1 parent 5628238 commit dbca134

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ export class ChatActions extends Actions<ChatState> {
211211
editing: {},
212212
};
213213
this.syncdb.set(message);
214+
const messagesState = this.store.get("messages");
215+
let selectedThreadKey: string;
214216
if (!reply_to) {
215217
this.deleteDraft(0);
216218
// NOTE: we also clear search, since it's confusing to send a message and not
@@ -219,17 +221,26 @@ export class ChatActions extends Actions<ChatState> {
219221
// Also, only do this clearing when not replying.
220222
// For replies search find full threads not individual messages.
221223
this.clearAllFilters();
224+
selectedThreadKey = `${time_stamp.valueOf()}`;
222225
} else {
223226
// when replying we make sure that the thread is expanded, since otherwise
224227
// our reply won't be visible
225-
const messages = this.store.get("messages");
226228
if (
227-
messages
229+
messagesState
228230
?.getIn([`${reply_to.valueOf()}`, "folding"])
229231
?.includes(sender_id)
230232
) {
231233
this.toggleFoldThread(reply_to);
232234
}
235+
const root =
236+
getThreadRootDate({
237+
date: reply_to.valueOf(),
238+
messages: messagesState,
239+
}) ?? reply_to.valueOf();
240+
selectedThreadKey = `${root}`;
241+
}
242+
if (selectedThreadKey != "0") {
243+
this.setSelectedThread(selectedThreadKey);
233244
}
234245

235246
const project_id = this.store?.get("project_id");
@@ -1249,6 +1260,7 @@ export class ChatActions extends Actions<ChatState> {
12491260
};
12501261

12511262
setSelectedThread = (threadKey: string | null) => {
1263+
console.log("setSelectedThread", { threadKey });
12521264
this.frameTreeActions?.set_frame_data({
12531265
id: this.frameId,
12541266
selectedThreadKey: threadKey,

src/packages/frontend/chat/chatroom.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ export function ChatPanel({
172172
const [sidebarVisible, setSidebarVisible] = useState<boolean>(false);
173173
const isCompact = variant === "compact";
174174
const disableFilters = disableFiltersProp ?? isCompact;
175+
const storedThreadFromDesc =
176+
getDescValue(desc, "data-selectedThreadKey") ?? null;
175177
const [selectedThreadKey, setSelectedThreadKey0] = useState<string | null>(
176-
getDescValue(desc, "data-selectedThreadKey") ?? null,
178+
storedThreadFromDesc,
177179
);
178180
const setSelectedThreadKey = (x: string | null) => {
179181
if (x != null && x != ALL_THREADS_KEY) {
@@ -250,6 +252,16 @@ export function ChatPanel({
250252
});
251253
}, [rawThreads, account_id, actions]);
252254

255+
useEffect(() => {
256+
if (
257+
storedThreadFromDesc != null &&
258+
storedThreadFromDesc !== selectedThreadKey
259+
) {
260+
setSelectedThreadKey(storedThreadFromDesc);
261+
setAllowAutoSelectThread(false);
262+
}
263+
}, [storedThreadFromDesc]);
264+
253265
useEffect(() => {
254266
if (threads.length === 0) {
255267
if (selectedThreadKey !== null) {

0 commit comments

Comments
 (0)