Skip to content

Commit bf5a678

Browse files
committed
fix #7662 -- this might fix this chat issue; it makes sense, but I wasn't able to reproduce it, so I'm not sure. Reopen if still broken.
1 parent 938adad commit bf5a678

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ export class ChatActions extends Actions<ChatState> {
355355
}
356356

357357
// Used to edit sent messages.
358-
// TODO: this is **Extremely** shockingly inefficient; it assumes
359-
// the number of edits is small.
358+
// NOTE: this is inefficient; it assumes
359+
// the number of edits is small, which is reasonable -- nobody makes hundreds of distinct
360+
// edits of a single message.
360361
public send_edit(message: ChatMessageTyped, content: string): void {
361362
if (this.syncdb == null) {
362363
// WARNING: give an error or try again later?
@@ -432,13 +433,24 @@ export class ChatActions extends Actions<ChatState> {
432433
this.store?.get("messages") ?? (fromJS({}) as ChatMessages),
433434
);
434435
const time = reply_to?.valueOf() ?? 0;
435-
this.delete_draft(-time);
436-
return this.send_chat({
436+
const time_stamp_str = this.send_chat({
437437
input: reply,
438438
sender_id: from ?? this.redux.getStore("account").get_account_id(),
439439
reply_to,
440440
noNotification,
441441
});
442+
this.delete_draft(-time);
443+
// it's conceivable that for some clients they recreate the draft
444+
// message right as the editor for that message is being removed.
445+
// Thus we do an extra delete a moment after send (after successfully
446+
// sending the message) to be sure the draft is really gone.
447+
// See https://github.com/sagemathinc/cocalc/issues/7662
448+
// and note that I'm not able to reproduce this, so it might not
449+
// be the right solution.
450+
setTimeout(() => {
451+
this.delete_draft(-time);
452+
}, 500);
453+
return time_stamp_str;
442454
}
443455

444456
// negative date is used for replies.
@@ -451,11 +463,13 @@ export class ChatActions extends Actions<ChatState> {
451463
sender_id = sender_id ?? this.redux.getStore("account").get_account_id();
452464
// date should always be negative for drafts (stupid, but that's the code),
453465
// so I'm just deleting both for now.
454-
this.syncdb.delete({
455-
event: "draft",
456-
sender_id,
457-
date,
458-
});
466+
if (date) {
467+
this.syncdb.delete({
468+
event: "draft",
469+
sender_id,
470+
date,
471+
});
472+
}
459473
this.syncdb.delete({
460474
event: "draft",
461475
sender_id,

src/packages/frontend/chat/message.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,10 @@ export default function Message(props: Readonly<Props>) {
624624

625625
function sendReply() {
626626
if (props.actions == null) return;
627+
setReplying(false);
627628
const reply = replyMentionsRef.current?.() ?? replyMessageRef.current;
628629
props.actions.send_reply({ message: message.toJS(), reply });
629-
props.actions.delete_draft(date);
630630
props.actions.scrollToBottom(props.index);
631-
setReplying(false);
632631
}
633632

634633
function renderComposeReply() {
@@ -664,7 +663,7 @@ export default function Message(props: Readonly<Props>) {
664663
}}
665664
placeholder={"Reply to the above message..."}
666665
/>
667-
<div style={{ margin: "5px 0" }}>
666+
<div style={{ margin: "5px 0", display: "flex" }}>
668667
<Button
669668
style={{ marginRight: "5px" }}
670669
onClick={() => {

src/packages/frontend/chat/side-chat.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,6 @@ export default function SideChat({ project_id, path, style }: Props) {
162162
Send
163163
</Button>
164164
</Tooltip>
165-
{/*
166-
This seems hard to implement with our current model and
167-
below doesn't work
168-
<Button
169-
style={{ marginLeft: "5px" }}
170-
onClick={() => {
171-
actions.delete_draft(0);
172-
actions.set_input('');
173-
}}
174-
>
175-
Cancel
176-
</Button> */}
177165
<LLMCostEstimationChat
178166
compact
179167
llm_cost={llm_cost_room}

0 commit comments

Comments
 (0)