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);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteMessagePair = async (messageId) => {
|
const deleteMessageAndDescendants = async (messageId: string) => {
|
||||||
|
if (history.messages[messageId]) {
|
||||||
history.messages[messageId].deleted = true;
|
history.messages[messageId].deleted = true;
|
||||||
history.messages[history.messages[messageId].childrenIds[0]].deleted = true;
|
|
||||||
|
|
||||||
const responseId = history.messages[messageId].childrenIds[0];
|
for (const childId of history.messages[messageId].childrenIds) {
|
||||||
if (history.messages[responseId].childrenIds.length === 0) {
|
await deleteMessageAndDescendants(childId);
|
||||||
await cancelChatCompletion(localStorage.token, chatId);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerDeleteMessageRecursive = async (messageId: string) => {
|
||||||
|
await deleteMessageAndDescendants(messageId);
|
||||||
await updateChatById(localStorage.token, chatId, { history });
|
await updateChatById(localStorage.token, chatId, { history });
|
||||||
await chats.set(await getChatList(localStorage.token));
|
await chats.set(await getChatList(localStorage.token));
|
||||||
};
|
};
|
||||||
|
@ -252,7 +255,7 @@
|
||||||
>
|
>
|
||||||
{#if message.role === 'user'}
|
{#if message.role === 'user'}
|
||||||
<UserMessage
|
<UserMessage
|
||||||
on:delete={() => deleteMessagePair(message.id)}
|
on:delete={() => triggerDeleteMessageRecursive(message.id)}
|
||||||
user={$user}
|
user={$user}
|
||||||
{message}
|
{message}
|
||||||
isFirstMessage={messageIdx === 0}
|
isFirstMessage={messageIdx === 0}
|
||||||
|
|
Loading…
Reference in a new issue