refac
This commit is contained in:
1 parent
3319b6410e
commit
24b8619f64
1 file changed
+26
-15
@@ -13,7 +13,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { getChatList, updateChatById } from '$lib/apis/chats';
|
import { deleteChatMessageById, getChatList, updateChatById } from '$lib/apis/chats';
|
||||||
import { copyToClipboard, extractCurlyBraceWords } from '$lib/utils';
|
import { copyToClipboard, extractCurlyBraceWords } from '$lib/utils';
|
||||||
|
|
||||||
import Message from './Messages/Message.svelte';
|
import Message from './Messages/Message.svelte';
|
||||||
@@ -35,7 +35,6 @@
|
|||||||
export let atSelectedModel;
|
export let atSelectedModel;
|
||||||
|
|
||||||
let messages = [];
|
let messages = [];
|
||||||
let deletedMessageIds = new Set<string>();
|
|
||||||
|
|
||||||
export let setInputText: Function = () => {};
|
export let setInputText: Function = () => {};
|
||||||
|
|
||||||
@@ -169,16 +168,10 @@
|
|||||||
if (!$temporaryChatEnabled) {
|
if (!$temporaryChatEnabled) {
|
||||||
history = history;
|
history = history;
|
||||||
await tick();
|
await tick();
|
||||||
const res = await updateChatById(
|
const res = await updateChatById(localStorage.token, chatId, {
|
||||||
localStorage.token,
|
history: history,
|
||||||
chatId,
|
messages: messages
|
||||||
{
|
});
|
||||||
history: history,
|
|
||||||
messages: messages
|
|
||||||
},
|
|
||||||
Array.from(deletedMessageIds)
|
|
||||||
);
|
|
||||||
deletedMessageIds.clear();
|
|
||||||
|
|
||||||
// Refresh local message content from backend (e.g. re-derived via serialize_output)
|
// Refresh local message content from backend (e.g. re-derived via serialize_output)
|
||||||
if (res?.chat?.history?.messages) {
|
if (res?.chat?.history?.messages) {
|
||||||
@@ -468,11 +461,29 @@
|
|||||||
// Delete the message and its children
|
// Delete the message and its children
|
||||||
[messageId, ...childMessageIds].forEach((id) => {
|
[messageId, ...childMessageIds].forEach((id) => {
|
||||||
delete history.messages[id];
|
delete history.messages[id];
|
||||||
deletedMessageIds.add(id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
showMessage({ id: parentMessageId }, false, false);
|
let nextMessageId = parentMessageId;
|
||||||
await updateChat();
|
let nextChildrenIds =
|
||||||
|
nextMessageId === null
|
||||||
|
? Object.keys(history.messages).filter((id) => history.messages[id].parentId === null)
|
||||||
|
: (history.messages[nextMessageId]?.childrenIds ?? []);
|
||||||
|
while (nextChildrenIds.length > 0) {
|
||||||
|
nextMessageId = nextChildrenIds.at(-1);
|
||||||
|
nextChildrenIds = history.messages[nextMessageId]?.childrenIds ?? [];
|
||||||
|
}
|
||||||
|
history.currentId = nextMessageId;
|
||||||
|
history = history;
|
||||||
|
|
||||||
|
if (!$temporaryChatEnabled) {
|
||||||
|
const res = await deleteChatMessageById(localStorage.token, chatId, messageId);
|
||||||
|
if (res?.chat?.history) {
|
||||||
|
history = res.chat.history;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentChatPage.set(1);
|
||||||
|
await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerScroll = () => {
|
const triggerScroll = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user