Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

user_group: Live update on subgroup edit.

Shubham Padiacbcd631afeb9
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js
index e77f5312eaa..e69afa046d6 100644
--- a/web/src/server_events_dispatch.js
+++ b/web/src/server_events_dispatch.js
@@ -973,11 +973,17 @@ export function dispatch_normal_event(event) {
break;
case "add_subgroups":
user_groups.add_subgroups(event.group_id, event.direct_subgroup_ids);
- user_group_edit.handle_subgroup_edit_event(event.group_id);
+ user_group_edit.handle_subgroup_edit_event(
+ event.group_id,
+ event.direct_subgroup_ids,
+ );
break;
case "remove_subgroups":
user_groups.remove_subgroups(event.group_id, event.direct_subgroup_ids);
- user_group_edit.handle_subgroup_edit_event(event.group_id);
+ user_group_edit.handle_subgroup_edit_event(
+ event.group_id,
+ event.direct_subgroup_ids,
+ );
break;
case "update":
user_groups.update(event);
diff --git a/web/src/user_group_edit.js b/web/src/user_group_edit.js
index fadc8c97f88..704e30dde1a 100644
--- a/web/src/user_group_edit.js
+++ b/web/src/user_group_edit.js
@@ -268,7 +268,53 @@ function update_group_membership_button(group_id) {
}
}
-export function handle_subgroup_edit_event(group_id) {
+function update_display_checkmark_on_group_edit(group) {
+ if (is_group_already_present(group)) {
+ const $row = row_for_group_id(group.id);
+
+ const item = group;
+ item.is_member = user_groups.is_user_in_group(group.id, people.my_current_user_id());
+ item.can_join = settings_data.can_join_user_group(item.id);
+ item.can_leave = settings_data.can_leave_user_group(item.id);
+ item.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(),
+ );
+ item.associated_subgroup_names = user_groups.format_group_list(associated_subgroups);
+ const html = render_browse_user_groups_list_item(item);
+ const $new_row = $(html);
+
+ // TODO: Remove this if/when we just handle "active" when rendering templates.
+ if ($row.hasClass("active")) {
+ $new_row.addClass("active");
+ }
+
+ $row.replaceWith($new_row);
+ }
+}
+
+function update_your_groups_list(group_id) {
+ if (user_groups.is_user_in_group(group_id, people.my_current_user_id())) {
+ // We add the group row to list if the current user
+ // is added to it. The whole list is redrawed to
+ // maintain the sorted order of groups.
+ redraw_user_group_list();
+ } else if (!settings_data.can_join_user_group(group_id)) {
+ // We remove the group row immediately only if the
+ // user cannot join the group again themselves.
+ const group_row = row_for_group_id(group_id);
+ if (group_row.length) {
+ group_row.remove();
+ update_empty_left_panel_message();
+ }
+ }
+}
+
+export function handle_subgroup_edit_event(group_id, direct_subgroup_ids) {
if (!overlays.groups_open()) {
return;
}
@@ -278,6 +324,23 @@ export function handle_subgroup_edit_event(group_id) {
if (is_editing_group(group_id)) {
user_group_edit_members.update_member_list_widget(group);
}
+
+ const tab_key = get_active_data().$tabs.first().attr("data-tab-key");
+ const subgroups_containing_current_user = direct_subgroup_ids.filter((group_id) =>
+ user_groups.is_user_in_group(group_id, people.my_current_user_id()),
+ );
+ // update display of group-rows on left panel.
+ // We need this update only if your-groups tab is active
+ // and current user is among the affect users as in that
+ // case the group widget list need to be updated and show
+ // or remove the group-row on the left panel accordingly.
+ if (tab_key === "your-groups" && subgroups_containing_current_user.length > 0) {
+ update_your_groups_list(group_id);
+ }
+
+ if (subgroups_containing_current_user.length > 0) {
+ update_display_checkmark_on_group_edit(group);
+ }
}
function update_settings_for_group_overlay(group_id, user_ids) {
@@ -299,48 +362,11 @@ function update_settings_for_group_overlay(group_id, user_ids) {
// or remove the group-row on the left panel accordingly.
const tab_key = get_active_data().$tabs.first().attr("data-tab-key");
if (tab_key === "your-groups" && user_ids.includes(people.my_current_user_id())) {
- if (user_groups.is_user_in_group(group_id, people.my_current_user_id())) {
- // We add the group row to list if the current user
- // is added to it. The whole list is redrawed to
- // maintain the sorted order of groups.
- redraw_user_group_list();
- } else if (!settings_data.can_join_user_group(group_id)) {
- // We remove the group row immediately only if the
- // user cannot join the group again themselves.
- const group_row = row_for_group_id(group_id);
- if (group_row.length) {
- group_row.remove();
- update_empty_left_panel_message();
- }
- }
+ update_your_groups_list(group_id);
}
- // update display of check-mark.
- if (is_group_already_present(group)) {
- const $row = row_for_group_id(group_id);
-
- const item = group;
- item.is_member = user_groups.is_user_in_group(group_id, people.my_current_user_id());
- item.can_join = settings_data.can_join_user_group(item.id);
- item.can_leave = settings_data.can_leave_user_group(item.id);
- item.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(),
- );
- item.associated_subgroup_names = user_groups.format_group_list(associated_subgroups);
- const html = render_browse_user_groups_list_item(item);
- const $new_row = $(html);
-
- // TODO: Remove this if/when we just handle "active" when rendering templates.
- if ($row.hasClass("active")) {
- $new_row.addClass("active");
- }
-
- $row.replaceWith($new_row);
+ if (user_ids.includes(people.my_current_user_id())) {
+ update_display_checkmark_on_group_edit(group);
}
}