Skip to content

Commit 4b00a05

Browse files
committed
fix #7662 - chat: browser refresh opens editors of past messages
1 parent cd6d4d0 commit 4b00a05

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,19 @@ export class ChatActions extends Actions<ChatState> {
448448
sender_id: string | undefined = undefined,
449449
) {
450450
if (!this.syncdb) return;
451+
sender_id = sender_id ?? this.redux.getStore("account").get_account_id();
452+
// date should always be negative for drafts (stupid, but that's the code),
453+
// so I'm just deleting both for now.
451454
this.syncdb.delete({
452455
event: "draft",
453-
sender_id: sender_id ?? this.redux.getStore("account").get_account_id(),
456+
sender_id,
454457
date,
455458
});
459+
this.syncdb.delete({
460+
event: "draft",
461+
sender_id,
462+
date: -date,
463+
});
456464
if (commit) {
457465
this.syncdb.commit();
458466
}
@@ -833,9 +841,12 @@ export class ChatActions extends Actions<ChatState> {
833841
// submit question to the given language model
834842
const id = uuid();
835843
this.chatStreams.add(id);
836-
setTimeout(() => {
837-
this.chatStreams.delete(id);
838-
}, 3 * 60 * 1000);
844+
setTimeout(
845+
() => {
846+
this.chatStreams.delete(id);
847+
},
848+
3 * 60 * 1000,
849+
);
839850

840851
// construct the LLM history for the given thread
841852
const history = reply_to ? this.getLLMHistory(reply_to) : undefined;

src/packages/frontend/chat/message.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,7 @@ export default function Message(props: Readonly<Props>) {
626626
if (props.actions == null) return;
627627
const reply = replyMentionsRef.current?.() ?? replyMessageRef.current;
628628
props.actions.send_reply({ message: message.toJS(), reply });
629-
props.actions.syncdb?.delete({
630-
event: "draft",
631-
sender_id: props.account_id,
632-
date: -date,
633-
});
629+
props.actions.delete_draft(date);
634630
props.actions.scrollToBottom(props.index);
635631
setReplying(false);
636632
}
@@ -673,11 +669,7 @@ export default function Message(props: Readonly<Props>) {
673669
style={{ marginRight: "5px" }}
674670
onClick={() => {
675671
setReplying(false);
676-
props.actions?.syncdb?.delete({
677-
event: "draft",
678-
sender_id: props.account_id,
679-
date: -date,
680-
});
672+
props.actions?.delete_draft(date);
681673
}}
682674
>
683675
Cancel

0 commit comments

Comments
 (0)