mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
user_group_edit: Fix live update of checkmark in left panel.
This commit adds code to live update the checkmark in left panel on updating the user's membership even for groups whose membership is not updated directly but has updated group as its subgroup.
This commit is contained in:
@@ -314,22 +314,17 @@ function update_group_membership_button(group_id: number): void {
|
||||
}
|
||||
}
|
||||
|
||||
function update_display_checkmark_on_group_edit(group: UserGroup): void {
|
||||
if (is_group_already_present(group)) {
|
||||
function rerender_group_row(group: UserGroup): void {
|
||||
const $row = row_for_group_id(group.id);
|
||||
|
||||
const item = group;
|
||||
const is_member = user_groups.is_user_in_group(group.id, people.my_current_user_id());
|
||||
|
||||
const current_user_id = people.my_current_user_id();
|
||||
const is_member = user_groups.is_user_in_group(group.id, current_user_id);
|
||||
const can_join = settings_data.can_join_user_group(item.id);
|
||||
const can_leave = settings_data.can_leave_user_group(item.id);
|
||||
const is_direct_member = user_groups.is_direct_member_of(
|
||||
people.my_current_user_id(),
|
||||
item.id,
|
||||
);
|
||||
const associated_subgroups = user_groups.get_associated_subgroups(
|
||||
item,
|
||||
people.my_current_user_id(),
|
||||
);
|
||||
const is_direct_member = user_groups.is_direct_member_of(current_user_id, item.id);
|
||||
const associated_subgroups = user_groups.get_associated_subgroups(item, current_user_id);
|
||||
const associated_subgroup_names = user_groups.format_group_list(associated_subgroups);
|
||||
const item_render_data = {
|
||||
...item,
|
||||
@@ -349,6 +344,26 @@ function update_display_checkmark_on_group_edit(group: UserGroup): void {
|
||||
|
||||
$row.replaceWith($new_row);
|
||||
}
|
||||
|
||||
function update_display_checkmark_on_group_edit(group: UserGroup): void {
|
||||
const tab_key = get_active_data().$tabs.first().attr("data-tab-key");
|
||||
if (tab_key === "your-groups") {
|
||||
// There is no need to do anything if "Your groups" tab is
|
||||
// opened, because the whole list is already redrawn.
|
||||
return;
|
||||
}
|
||||
|
||||
rerender_group_row(group);
|
||||
|
||||
const current_user_id = people.my_current_user_id();
|
||||
const supergroups_of_group = user_groups.get_supergroups_of_user_group(group.id);
|
||||
for (const supergroup of supergroups_of_group) {
|
||||
if (user_groups.is_direct_member_of(current_user_id, supergroup.id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rerender_group_row(supergroup);
|
||||
}
|
||||
}
|
||||
|
||||
function update_your_groups_list_if_needed(): void {
|
||||
|
||||
@@ -332,6 +332,12 @@ export function is_subgroup_of_target_group(target_group_id: number, subgroup_id
|
||||
return recursive_subgroup_ids.has(subgroup_id);
|
||||
}
|
||||
|
||||
export function get_supergroups_of_user_group(group_id: number): UserGroup[] {
|
||||
return get_realm_user_groups().filter((user_group) =>
|
||||
is_subgroup_of_target_group(user_group.id, group_id),
|
||||
);
|
||||
}
|
||||
|
||||
export function get_recursive_group_members(target_user_group: UserGroup): Set<number> {
|
||||
const members = new Set(target_user_group.members);
|
||||
const subgroup_ids = get_recursive_subgroups(target_user_group);
|
||||
|
||||
Reference in New Issue
Block a user