Recursively set delete=true flag for all children messages

This commit is contained in:
Danny Liu 2024-02-20 19:47:30 -08:00
parent 7c4d818f2d
commit c42ac39dc4

View file

@ -223,15 +223,18 @@
}, 100); }, 100);
}; };
const deleteMessagePair = async (messageId) => { const deleteMessageAndDescendants = async (messageId: string) => {
history.messages[messageId].deleted = true; if (history.messages[messageId]) {
history.messages[history.messages[messageId].childrenIds[0]].deleted = true; history.messages[messageId].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}