Repository navigation
fix: simplify chat user group deletion logic - #7720
Merged
Merged
Conversation
shaohuzhang1
commented
Nov 6, 2026
| return loadChatUserGroups() | ||
| }) | ||
| }) | ||
| .catch(() => {}) |
Contributor
Author
There was a problem hiding this comment.
The change itself is probably an improvement: always calling loadChatUserGroups() after a successful delete avoids a stale list when a non-current group is deleted. The old code only refreshed the list when the deleted group was the current group.
However, there are several things to check/fix:
-
currentGroupmay remain stale- If the deleted group is the current group, you should explicitly clear or reselect
currentGroup, unlessloadChatUserGroups()already does that. - Capture the check before reloading:
const wasCurrent = currentGroup.value?.id === group.id await ChatGroupsApi.deleteChatUserGroup(group.id) if (wasCurrent) currentGroup.value = null await loadChatUserGroups()
- If the deleted group is the current group, you should explicitly clear or reselect
-
Always reloading may be unnecessary or disruptive
- If
loadChatUserGroups()resets selection, pagination, scroll position, or filters, deleting a non-current group may cause UI regressions. - If possible, remove the group from the local
groupslist and only reload when needed. Otherwise, confirmloadChatUserGroups()preserves state.
- If
-
Loading state is not reset on failure
groupsLoading.value = trueis set, but there is nofinally/reset in the shown code.- If delete or reload fails, the UI may stay stuck in a loading state.
-
Errors are swallowed
.catch(() => {})hides both delete failures and reload failures. Users get no error feedback, and callers cannot detect failure.- At minimum, show an error message or log it.
-
Possible brace/parenthesis issue in the pasted snippet
- As shown, there is an extra
})before.catch(...):
return ChatGroupsApi.deleteChatUserGroup(group.id).then(() => { ... }) }) .catch(() => {})
- Verify the actual code. If it is a single promise chain, it should be:
return ChatGroupsApi.deleteChatUserGroup(group.id) .then(() => { ... }) .catch(() => {})
- As shown, there is an extra
-
Double-click / concurrent delete protection
- Consider guarding against repeated clicks, or using a per-group deleting state.
Suggested refactor:
async function deleteGroup(group: ListItem) {
groupsLoading.value = true
try {
await ChatGroupsApi.deleteChatUserGroup(group.id)
MsgSuccess('删除成功')
const wasCurrent = currentGroup.value?.id === group.id
if (wasCurrent) {
currentGroup.value = null // or select the next group
}
await loadChatUserGroups()
} catch (error) {
// MsgError('删除失败')
console.error(error)
} finally {
groupsLoading.value = false
}
}If loadChatUserGroups() manages groupsLoading itself, use a separate flag such as deleting.value to avoid conflicting loading states.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: simplify chat user group deletion logic