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: Update pills and pm_list on deactivation.

santhoshkumarCodesd1ca4a6d6aa1
diff --git a/web/src/user_events.ts b/web/src/user_events.ts
index c6f7c48c126..21511b983ec 100644
--- a/web/src/user_events.ts
+++ b/web/src/user_events.ts
@@ -9,6 +9,7 @@ import * as z from "zod/mini";
import * as activity_ui from "./activity_ui.ts";
import * as blueslip from "./blueslip.ts";
import {buddy_list} from "./buddy_list.ts";
+import * as compose_pm_pill from "./compose_pm_pill.ts";
import * as compose_state from "./compose_state.ts";
import * as message_live_update from "./message_live_update.ts";
import * as narrow_state from "./narrow_state.ts";
@@ -238,6 +239,9 @@ export const update_person = function update(event: UserUpdate): void {
settings_users.update_view_on_deactivate(event.user_id, is_bot_user);
}
buddy_list.insert_or_move([event.user_id]);
+ // Update UI elements to reflect the user's deactivated/reactivated status
+ pm_list.update_private_messages();
+ compose_pm_pill.update_user_pill_active_status(user, event.is_active);
settings_account.maybe_update_deactivate_account_button();
if (is_bot_user) {
settings_bots.update_bot_data(event.user_id);
diff --git a/web/tests/user_events.test.cjs b/web/tests/user_events.test.cjs
index 1ebcd4491df..bbc54237774 100644
--- a/web/tests/user_events.test.cjs
+++ b/web/tests/user_events.test.cjs
@@ -36,6 +36,13 @@ const buddy_list = mock_esm("../src/buddy_list", {
},
});
+const compose_pm_pill = mock_esm("../src/compose_pm_pill", {
+ update_user_pill_active_status() {},
+});
+const pm_list = mock_esm("../src/pm_list", {
+ update_private_messages() {},
+});
+
const buddy_data = new buddy_list.BuddyList();
buddy_list.buddy_list = buddy_data;
@@ -45,9 +52,6 @@ mock_esm("../src/activity_ui", {
mock_esm("../src/compose_state", {
update_email() {},
});
-mock_esm("../src/pm_list", {
- update_private_messages() {},
-});
mock_esm("../src/settings", {
update_lock_icon_in_sidebar() {},
});
@@ -276,21 +280,65 @@ run_test("updates", ({override}) => {
assert.equal(person.bot_owner_id, me.user_id);
buddy_list.BuddyList.insert_or_move = noop;
+
+ // Test that UI elements are updated when a user is deactivated/reactivated
+ let pm_list_updated = false;
+ let compose_pill_updated = false;
+ let expected_user_id = isaac.user_id;
+ let expected_is_active;
+
+ pm_list.update_private_messages = () => {
+ pm_list_updated = true;
+ };
+ compose_pm_pill.update_user_pill_active_status = (user, is_active) => {
+ compose_pill_updated = true;
+ assert.equal(user.user_id, expected_user_id);
+ assert.equal(is_active, expected_is_active);
+ };
+
+ // Deactivate a user and verify UI updates are triggered
+ expected_is_active = false;
user_events.update_person({user_id: isaac.user_id, is_active: false});
assert.ok(!people.is_person_active(isaac.user_id));
+ assert.ok(pm_list_updated);
+ assert.ok(compose_pill_updated);
+
+ // Reset flags and test reactivation
+ pm_list_updated = false;
+ compose_pill_updated = false;
+ // Reactivate the user and verify UI updates are triggered again
+ expected_is_active = true;
user_events.update_person({user_id: isaac.user_id, is_active: true});
assert.ok(people.is_person_active(isaac.user_id));
+ assert.ok(pm_list_updated);
+ assert.ok(compose_pill_updated);
let bot_data_updated = false;
settings_bots.update_bot_data = (user_id) => {
assert.equal(user_id, test_bot.user_id);
bot_data_updated = true;
};
+
+ // Reset flags and test bot deactivation
+ pm_list_updated = false;
+ compose_pill_updated = false;
+
+ expected_is_active = false;
+ expected_user_id = test_bot.user_id;
user_events.update_person({user_id: test_bot.user_id, is_active: false});
assert.equal(bot_data_updated, true);
+ assert.ok(pm_list_updated);
+ assert.ok(compose_pill_updated);
+ // Reset flags and test bot reactivation
bot_data_updated = false;
+ pm_list_updated = false;
+ compose_pill_updated = false;
+
+ expected_is_active = true;
user_events.update_person({user_id: test_bot.user_id, is_active: true});
assert.ok(bot_data_updated);
+ assert.ok(pm_list_updated);
+ assert.ok(compose_pill_updated);
});