Skip to content

Commit 60e97d0

Browse files
committed
fix #7728 -- pasting image into chat message in markdown mode breaks it
1 parent 826a4e6 commit 60e97d0

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ export class ChatActions extends Actions<ChatState> {
570570
}
571571

572572
public set_uploading(is_uploading: boolean): void {
573+
console.log("set_uploading", is_uploading);
573574
this.setState({ is_uploading });
574575
}
575576

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ function isThread(messages: ChatMessages, message: ChatMessageTyped) {
286286
if (message.get("reply_to") != null) {
287287
return true;
288288
}
289+
// TODO/WARNING!!! This is a linear search
290+
// through all messages to decide if a message is the root of a thread.
291+
// This is VERY BAD and must to be redone at some point, since we call isThread
292+
// on all messages (in getSortedDates), making that algorithm O(n^2),
293+
// which is hideous as the number of messages scales. Instead one must
294+
// use a proper data structure (or even a cache) to track this once
295+
// and for all. It's more complicated but everything needs to be at
296+
// most O(n).
289297
return messages.some(
290298
(m) => m.get("reply_to") === message.get("date").toISOString(),
291299
);

src/packages/frontend/editors/markdown-input/component.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,7 @@ export function MarkdownInput(props: Props) {
561561
// console.log("upload_sending", file);
562562
if (current_uploads_ref.current == null) {
563563
current_uploads_ref.current = { [file.name]: true };
564-
if (onUploadStart != null) {
565-
onUploadStart();
566-
}
564+
onUploadStart?.();
567565
} else {
568566
current_uploads_ref.current[file.name] = true;
569567
}
@@ -582,16 +580,16 @@ export function MarkdownInput(props: Props) {
582580
if (path == null) {
583581
throw Error("path must be set if enableUploads is set.");
584582
}
583+
const filename = file.name ?? file.upload.filename;
585584

586585
if (current_uploads_ref.current != null) {
587-
delete current_uploads_ref.current[file.name];
586+
delete current_uploads_ref.current[filename];
588587
if (len(current_uploads_ref.current) == 0) {
589588
current_uploads_ref.current = null;
590-
if (onUploadEnd != null) {
591-
onUploadEnd();
592-
}
589+
onUploadEnd?.();
593590
}
594591
}
592+
595593
if (cm.current == null) return;
596594
const input = cm.current.getValue();
597595
const s0 = upload_temp_link(file);

0 commit comments

Comments
 (0)