mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
fix: message delete
This commit is contained in:
parent
aedd77b81d
commit
276d629a14
@ -1787,6 +1787,7 @@
|
|||||||
{regenerateResponse}
|
{regenerateResponse}
|
||||||
{mergeResponses}
|
{mergeResponses}
|
||||||
{chatActionHandler}
|
{chatActionHandler}
|
||||||
|
{showMessage}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
export let regenerateResponse: Function;
|
export let regenerateResponse: Function;
|
||||||
export let mergeResponses: Function;
|
export let mergeResponses: Function;
|
||||||
export let chatActionHandler: Function;
|
export let chatActionHandler: Function;
|
||||||
|
export let showMessage: Function = () => {};
|
||||||
|
|
||||||
export let user = $_user;
|
export let user = $_user;
|
||||||
export let prompt;
|
export let prompt;
|
||||||
@ -244,49 +245,39 @@
|
|||||||
|
|
||||||
const deleteMessageHandler = async (messageId) => {
|
const deleteMessageHandler = async (messageId) => {
|
||||||
const messageToDelete = history.messages[messageId];
|
const messageToDelete = history.messages[messageId];
|
||||||
|
|
||||||
const parentMessageId = messageToDelete.parentId;
|
const parentMessageId = messageToDelete.parentId;
|
||||||
const childMessageIds = messageToDelete.childrenIds ?? [];
|
const childMessageIds = messageToDelete.childrenIds ?? [];
|
||||||
|
|
||||||
const hasDescendantMessages = childMessageIds.some(
|
// Collect all grandchildren
|
||||||
(childId) => history.messages[childId]?.childrenIds?.length > 0
|
const grandchildrenIds = childMessageIds.flatMap(
|
||||||
|
(childId) => history.messages[childId]?.childrenIds ?? []
|
||||||
);
|
);
|
||||||
|
|
||||||
history.currentId = parentMessageId;
|
// Update parent's children
|
||||||
await tick();
|
if (parentMessageId && history.messages[parentMessageId]) {
|
||||||
|
history.messages[parentMessageId].childrenIds = [
|
||||||
|
...history.messages[parentMessageId].childrenIds.filter((id) => id !== messageId),
|
||||||
|
...grandchildrenIds
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the message itself from the parent message's children array
|
// Update grandchildren's parent
|
||||||
history.messages[parentMessageId].childrenIds = history.messages[
|
grandchildrenIds.forEach((grandchildId) => {
|
||||||
parentMessageId
|
if (history.messages[grandchildId]) {
|
||||||
].childrenIds.filter((id) => id !== messageId);
|
history.messages[grandchildId].parentId = parentMessageId;
|
||||||
|
|
||||||
await tick();
|
|
||||||
|
|
||||||
childMessageIds.forEach((childId) => {
|
|
||||||
const childMessage = history.messages[childId];
|
|
||||||
|
|
||||||
if (childMessage && childMessage.childrenIds) {
|
|
||||||
if (childMessage.childrenIds.length === 0 && !hasDescendantMessages) {
|
|
||||||
// If there are no other responses/prompts
|
|
||||||
history.messages[parentMessageId].childrenIds = [];
|
|
||||||
} else {
|
|
||||||
childMessage.childrenIds.forEach((grandChildId) => {
|
|
||||||
if (history.messages[grandChildId]) {
|
|
||||||
history.messages[grandChildId].parentId = parentMessageId;
|
|
||||||
history.messages[parentMessageId].childrenIds.push(grandChildId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Remove child message id from the parent message's children array
|
// Delete the message and its children
|
||||||
history.messages[parentMessageId].childrenIds = history.messages[
|
[messageId, ...childMessageIds].forEach((id) => {
|
||||||
parentMessageId
|
delete history.messages[id];
|
||||||
].childrenIds.filter((id) => id !== childId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
|
showMessage({ id: parentMessageId });
|
||||||
|
|
||||||
|
// Update the chat
|
||||||
await updateChatById(localStorage.token, chatId, {
|
await updateChatById(localStorage.token, chatId, {
|
||||||
messages: messages,
|
messages: messages,
|
||||||
history: history
|
history: history
|
||||||
|
Loading…
Reference in New Issue
Block a user