Skip to content

Commit 0e1113a

Browse files
committed
fix chat bugs -- fix #6606, fix #6668
1 parent 591d523 commit 0e1113a

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

src/packages/frontend/chat/message.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,15 @@ export default function Message(props: Readonly<Props>) {
186186

187187
const submitMentionsRef = useRef<SubmitMentionsFn>();
188188

189-
const [replying, setReplying] = useState<boolean>(false);
189+
const [replying, setReplying] = useState<boolean>(() => {
190+
return (
191+
props.actions?.syncdb?.get_one({
192+
event: "draft",
193+
sender_id: props.account_id,
194+
date: -date,
195+
}) != null
196+
);
197+
});
190198

191199
const replyMessageRef = useRef<string>("");
192200
const replyMentionsRef = useRef<SubmitMentionsFn>();
@@ -484,19 +492,6 @@ export default function Message(props: Readonly<Props>) {
484492
</Popconfirm>
485493
</Tooltip>
486494
) : undefined}
487-
{/* {!is_thread_body && props.allowReply && !replying ? (
488-
<Button
489-
type="text"
490-
disabled={replying}
491-
style={{
492-
color: is_viewers_message ? "white" : "#555",
493-
}}
494-
size="small"
495-
onClick={() => setReplying(true)}
496-
>
497-
<Icon name="reply" /> Reply
498-
</Button>
499-
) : undefined} */}
500495
{message.get("history").size > 1 ||
501496
message.get("editing").size > 0
502497
? editing_status(isEditing)
@@ -659,20 +654,25 @@ export default function Message(props: Readonly<Props>) {
659654
placeholder={"Reply to the above message..."}
660655
/>
661656
<div style={{ margin: "5px 0" }}>
662-
<Button
663-
onClick={sendReply}
664-
type="primary"
665-
style={{ marginRight: "5px" }}
666-
>
667-
<Icon name="paper-plane" /> Send Reply
668-
</Button>
669657
<Button
670658
onClick={() => {
671659
setReplying(false);
660+
props.actions?.syncdb?.delete({
661+
event: "draft",
662+
sender_id: props.account_id,
663+
date: -date,
664+
});
672665
}}
673666
>
674667
Cancel
675668
</Button>
669+
<Button
670+
onClick={sendReply}
671+
type="primary"
672+
style={{ marginRight: "5px" }}
673+
>
674+
<Icon name="paper-plane" /> Send Reply
675+
</Button>
676676
<LLMCostEstimationChat
677677
llm_cost={llm_cost_reply}
678678
compact={false}

src/packages/frontend/chat/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export interface MessageHistory {
3030
}
3131

3232
export interface ChatMessage {
33-
sender_id: string;
3433
event: "chat";
34+
sender_id: string;
3535
history: MessageHistory[];
3636
date: Date | string; // string is used to create it
3737
reply_to?: string;
@@ -40,6 +40,22 @@ export interface ChatMessage {
4040
folding?: string[];
4141
}
4242

43+
// this type isn't explicitly used anywhere yet, but the actual structure is and I just
44+
// wanted to document it.
45+
export interface Draft {
46+
event: "draft";
47+
// account_id of the user writing this draft
48+
sender_id: string;
49+
// ms since epoch when this draft was last edited. This is used to show a message to
50+
// other users that one user is writing a message.
51+
active: number;
52+
// date = 0 when composing an entirely new message
53+
// data = -[timestamp in ms] of the message being replied to
54+
date: number;
55+
// input = string contents of current version of the message
56+
input: "string";
57+
}
58+
4359
export type ChatMessageTyped = TypedMap<{
4460
sender_id: string;
4561
event: "chat";

0 commit comments

Comments
 (0)