mirror of
				https://github.com/open-webui/open-webui
				synced 2025-06-26 18:26:48 +00:00 
			
		
		
		
	fix: message delete issue
This commit is contained in:
		
							parent
							
								
									1efa25eed5
								
							
						
					
					
						commit
						4a67ae1195
					
				| @ -202,38 +202,51 @@ | |||||||
| 		}, 100); | 		}, 100); | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const messageDeleteHandler = async (messageId) => { | 	const deleteMessageHandler = 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) => { | 					childMessage.childrenIds.forEach((grandChildId) => { | ||||||
| 						if (history.messages[grandChildId]) { | 						if (history.messages[grandChildId]) { | ||||||
| 							history.messages[grandChildId].parentId = messageParentId; | 							history.messages[grandChildId].parentId = parentMessageId; | ||||||
| 							history.messages[messageParentId].childrenIds.push(grandChildId); | 							history.messages[parentMessageId].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 @@ | |||||||
| 						> | 						> | ||||||
| 							{#if message.role === 'user'} | 							{#if message.role === 'user'} | ||||||
| 								<UserMessage | 								<UserMessage | ||||||
| 									on:delete={() => messageDeleteHandler(message.id)} | 									on:delete={() => deleteMessageHandler(message.id)} | ||||||
| 									{user} | 									{user} | ||||||
| 									{readOnly} | 									{readOnly} | ||||||
| 									{message} | 									{message} | ||||||
| @ -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 ?? []} | ||||||
|  | |||||||
| @ -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 @@ | |||||||
| 												</Tooltip> | 												</Tooltip> | ||||||
| 											{/if} | 											{/if} | ||||||
| 										{/if} | 										{/if} | ||||||
|  | 									{/if} | ||||||
| 								</div> | 								</div> | ||||||
| 							{/if} | 							{/if} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user