Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
4a67ae11
Commit
4a67ae11
authored
Jun 16, 2024
by
Timothy J. Baek
Browse files
fix: message delete issue
parent
1efa25ee
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
82 deletions
+95
-82
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+36
-23
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+59
-59
No files found.
src/lib/components/chat/Messages.svelte
View file @
4a67ae11
...
@@ -202,38 +202,51 @@
...
@@ -202,38 +202,51 @@
}, 100);
}, 100);
};
};
const
messageDelet
eHandler = async (messageId) => {
const
deleteMessag
eHandler = async (messageId) => {
const messageToDelete = history.messages[messageId];
const messageToDelete = history.messages[messageId];
const messageParentId = messageToDelete.parentId;
const messageChildrenIds = messageToDelete.childrenIds ?? [];
const parentMessageId = messageToDelete.parentId;
const hasSibling = messageChildrenIds.some(
const childMessageIds = messageToDelete.childrenIds ?? [];
const hasDescendantMessages = childMessageIds.some(
(childId) => history.messages[childId]?.childrenIds?.length > 0
(childId) => history.messages[childId]?.childrenIds?.length > 0
);
);
messageChildrenIds.forEach((childId) => {
const child = history.messages[childId];
history.currentId = parentMessageId;
if (child && child.childrenIds) {
await tick();
if (child.childrenIds.length === 0 && !hasSibling) {
// if last prompt/response pair
// Remove the message itself from the parent message's children array
history.messages[messageParentId].childrenIds = [];
history.messages[parentMessageId].childrenIds = history.messages[
history.currentId = messageParentId;
parentMessageId
].childrenIds.filter((id) => id !== messageId);
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 {
} else {
child.childrenIds.forEach((grandChildId) => {
child
Message
.childrenIds.forEach((grandChildId) => {
if (history.messages[grandChildId]) {
if (history.messages[grandChildId]) {
history.messages[grandChildId].parentId =
messageParent
Id;
history.messages[grandChildId].parentId =
parentMessage
Id;
history.messages[
messageParent
Id].childrenIds.push(grandChildId);
history.messages[
parentMessage
Id].childrenIds.push(grandChildId);
}
}
});
});
}
}
}
}
// remove response
history.messages[messageParentId].childrenIds = history.messages[
// Remove child message id from the parent message's children array
messageParentId
history.messages[parentMessageId].childrenIds = history.messages[
parentMessageId
].childrenIds.filter((id) => id !== childId);
].childrenIds.filter((id) => id !== childId);
});
});
// remove prompt
history.messages[messageParentId].childrenIds = history.messages[
await tick();
messageParentId
].childrenIds.filter((id) => id !== messageId);
await updateChatById(localStorage.token, chatId, {
await updateChatById(localStorage.token, chatId, {
messages: messages,
messages: messages,
history: history
history: history
...
@@ -292,7 +305,7 @@
...
@@ -292,7 +305,7 @@
>
>
{#if message.role === 'user'}
{#if message.role === 'user'}
<UserMessage
<UserMessage
on:delete={() =>
messageDelet
eHandler(message.id)}
on:delete={() =>
deleteMessag
eHandler(message.id)}
{user}
{user}
{readOnly}
{readOnly}
{message}
{message}
...
@@ -308,7 +321,7 @@
...
@@ -308,7 +321,7 @@
copyToClipboard={copyToClipboardWithToast}
copyToClipboard={copyToClipboardWithToast}
/>
/>
{:else if $mobile || (history.messages[message.parentId]?.models?.length ?? 1) === 1}
{:else if $mobile || (history.messages[message.parentId]?.models?.length ?? 1) === 1}
{#key message.id}
{#key message.id
&& history.currentId
}
<ResponseMessage
<ResponseMessage
{message}
{message}
siblings={history.messages[message.parentId]?.childrenIds ?? []}
siblings={history.messages[message.parentId]?.childrenIds ?? []}
...
...
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
4a67ae11
...
@@ -940,9 +940,8 @@
...
@@ -940,9 +940,8 @@
>
>
</button>
</button>
</Tooltip>
</Tooltip>
{/if}
{#if isLastMessage
&& !readOnly
}
{#if isLastMessage}
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
<button
<button
type="button"
type="button"
...
@@ -1004,6 +1003,7 @@
...
@@ -1004,6 +1003,7 @@
</Tooltip>
</Tooltip>
{/if}
{/if}
{/if}
{/if}
{/if}
</div>
</div>
{/if}
{/if}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment