diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index fd0a6e83..77e6cad0 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -223,32 +223,22 @@ }, 100); }; - // TODO: change delete behaviour - // const deleteMessageAndDescendants = async (messageId: string) => { - // if (history.messages[messageId]) { - // history.messages[messageId].deleted = true; - - // 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)); - // }; - const messageDeleteHandler = async (messageId) => { - if (history.messages[messageId]) { - history.messages[messageId].deleted = true; + const messageParentId = history.messages[messageId]?.parentId; - for (const childId of history.messages[messageId].childrenIds) { - history.messages[childId].deleted = true; - } + if (messageParentId !== null) { + history.messages[messageParentId].childrenIds = [] } - await updateChatById(localStorage.token, chatId, { history }); + + delete history.messages[messageId]; + history.currentId = messageParentId; + + await tick(); + + await updateChatById(localStorage.token, chatId, { + messages: messages, + history: history + }); }; @@ -258,57 +248,55 @@