forked from open-webui/open-webui
Recursively set delete=true flag for all children messages
This commit is contained in:
parent
7c4d818f2d
commit
c42ac39dc4
1 changed files with 10 additions and 7 deletions
|
@ -223,15 +223,18 @@
|
|||
}, 100);
|
||||
};
|
||||
|
||||
const deleteMessagePair = async (messageId) => {
|
||||
history.messages[messageId].deleted = true;
|
||||
history.messages[history.messages[messageId].childrenIds[0]].deleted = true;
|
||||
const deleteMessageAndDescendants = async (messageId: string) => {
|
||||
if (history.messages[messageId]) {
|
||||
history.messages[messageId].deleted = true;
|
||||
|
||||
const responseId = history.messages[messageId].childrenIds[0];
|
||||
if (history.messages[responseId].childrenIds.length === 0) {
|
||||
await cancelChatCompletion(localStorage.token, chatId);
|
||||
for (const childId of history.messages[messageId].childrenIds) {
|
||||
await deleteMessageAndDescendants(childId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const triggerDeleteMessageRecursive = async (messageId: string) => {
|
||||
await deleteMessageAndDescendants(messageId);
|
||||
await updateChatById(localStorage.token, chatId, { history });
|
||||
await chats.set(await getChatList(localStorage.token));
|
||||
};
|
||||
|
@ -252,7 +255,7 @@
|
|||
>
|
||||
{#if message.role === 'user'}
|
||||
<UserMessage
|
||||
on:delete={() => deleteMessagePair(message.id)}
|
||||
on:delete={() => triggerDeleteMessageRecursive(message.id)}
|
||||
user={$user}
|
||||
{message}
|
||||
isFirstMessage={messageIdx === 0}
|
||||
|
|
Loading…
Reference in a new issue