Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
dispatch: Update DM list when users are added or removed.
Evy Kassirer25478c7bd168
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.jsindex f562237512e..2edec15c1d0 100644--- a/web/src/server_events_dispatch.js+++ b/web/src/server_events_dispatch.js@@ -628,6 +628,11 @@ export function dispatch_normal_event(event) {activity_ui.redraw_user(event.person.user_id);}+ // The user may already appear in direct message+ // conversations, previously rendered with a+ // placeholder user record.+ pm_list.update_private_messages();+if (!event.person.is_bot) {settings_exports.update_export_consent_data_and_redraw({user_id: event.person.user_id,@@ -651,6 +656,7 @@ export function dispatch_normal_event(event) {user_id,people.INACCESSIBLE_USER_NAME,);+ pm_list.update_private_messages();break;}default:diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjsindex 69426e09b51..39291ef9d0a 100644--- a/web/tests/dispatch.test.cjs+++ b/web/tests/dispatch.test.cjs@@ -970,6 +970,7 @@ run_test("add_realm_user_redraw_logic", ({override}) => {override(settings_account, "maybe_update_deactivate_account_button", noop);override(settings_exports, "update_export_consent_data_and_redraw", noop);+ override(pm_list, "update_private_messages", noop);const check_should_redraw_new_user_stub = make_stub();// make_stub().f returns true by default, so it's already doing what we want.@@ -989,8 +990,11 @@ run_test("realm_user", ({override}) => {override(settings_account, "maybe_update_deactivate_account_button", noop);override(activity_ui, "check_should_redraw_new_user", noop);override(settings_exports, "update_export_consent_data_and_redraw", noop);+ const pm_list_stub = make_stub();+ override(pm_list, "update_private_messages", pm_list_stub.f);let event = event_fixtures.realm_user__add;dispatch({...event});+ assert.equal(pm_list_stub.num_calls, 1);const added_person = people.get_by_user_id(event.person.user_id);// sanity check a few individual fieldsassert.equal(added_person.full_name, "Test User");@@ -1027,7 +1031,10 @@ run_test("realm_user", ({override}) => {override(settings_data, "user_can_access_all_other_users", () => false);event = event_fixtures.realm_user__remove;+ // The second and third update_private_messages calls are from+ // dispatching realm_user__add_bot above and this remove event.dispatch(event);+ assert.equal(pm_list_stub.num_calls, 3);const removed_person = people.get_by_user_id(event.person.user_id);assert.equal(removed_person.full_name, "translated: Unknown user");});diff --git a/web/tests/example4.test.cjs b/web/tests/example4.test.cjsindex d372c85b535..1baa2d74767 100644--- a/web/tests/example4.test.cjs+++ b/web/tests/example4.test.cjs@@ -99,6 +99,7 @@ run_test("add users with event", ({override}) => {// Keep reading to see how overriding works!override(settings_bots, "redraw_all_bots_list", noop);override(activity_ui, "check_should_redraw_new_user", noop);+ override(pm_list, "update_private_messages", noop);// Let's simulate dispatching our event!server_events_dispatch.dispatch_normal_event(event);@@ -109,10 +110,10 @@ run_test("add users with event", ({override}) => {/*It's actually a little surprising that adding a user does- not have side effects beyond the people object and the bots list.- I guess we don't immediately update the buddy list, but that's- because the buddy list gets updated on the next server- fetch.+ not have side effects beyond the people object, the bots list,+ and the direct messages list. I guess we don't immediately+ update the buddy list, but that's because the buddy list gets+ updated on the next server fetch.Let's try an update next. To make this work, we will wantto override some more of our stubs.