user_group: Don't open edit panel on remove members.

When the current user was part of a group through both subgroup and a
direct membership, leaving the group would only remove the direct
membership. But since the user is part of the group through subgroup,
`is_user_in_group` will be true inside `handle_member_edit_event` which
should only be triggered when a user is on another group edit panel and
they join a group via the left panel plus button. In that case, the edit
panel of the newly joined group should open.
Instead of handling this on event, where we could not tell who triggered
the event, the current user or someone else, we now handle this in the
success callback of `add_or_remove_from_group`.
Fixes https://chat.zulip.org/#narrow/channel/9-issues/topic/group.20panel.20error/near/1987891
This commit is contained in:
Shubham Padia
2024-11-26 04:25:41 +00:00
committed by Tim Abbott
parent 513b8aabb5
commit a491b83b79

View File

@@ -329,15 +329,6 @@ export function handle_member_edit_event(group_id, user_ids) {
$row.replaceWith($new_row);
}
if (
!is_editing_group(group_id) &&
user_ids.includes(people.my_current_user_id()) &&
user_groups.is_user_in_group(group_id, people.my_current_user_id())
) {
const $group_row = row_for_group_id(group.id);
open_group_edit_panel_for_row($group_row);
}
}
export function update_group_details(group) {
@@ -740,6 +731,17 @@ export function add_or_remove_from_group(group, group_row) {
function success_callback() {
if (group_row.length) {
hide_membership_toggle_spinner(group_row);
// This should only be triggered when a user is on another group
// edit panel and they join a group via the left panel plus button.
// In that case, the edit panel of the newly joined group should
// open. `is_user_in_group` with direct_members_only set to true acts
// as a proxy to check if it's an `add_members` event.
if (
!is_editing_group(group.id) &&
user_groups.is_user_in_group(group.id, user_id, true)
) {
open_group_edit_panel_for_row(group_row);
}
}
}
@@ -756,15 +758,15 @@ export function add_or_remove_from_group(group, group_row) {
user_group_edit_members.edit_user_group_membership({
group,
removed: [user_id],
success_callback,
error_callback,
success: success_callback,
error: error_callback,
});
} else {
user_group_edit_members.edit_user_group_membership({
group,
added: [user_id],
success_callback,
error_callback,
success: success_callback,
error: error_callback,
});
}
}