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.

pm_list: Hide conversations with deactivated users by default.

santhoshkumarCodes0d91dad76f73
diff --git a/web/src/pm_list_data.ts b/web/src/pm_list_data.ts
index fb7ceab9d1e..d311cc1307c 100644
--- a/web/src/pm_list_data.ts
+++ b/web/src/pm_list_data.ts
@@ -46,7 +46,7 @@ export type DisplayObject = {
is_group: boolean;
is_bot: boolean;
has_unread_mention: boolean;
- is_deactivated: boolean;
+ includes_deactivated_user: boolean;
};
export function get_conversations(search_string = ""): DisplayObject[] {
@@ -68,9 +68,8 @@ export function get_conversations(search_string = ""): DisplayObject[] {
for (const conversation of conversations) {
const user_ids_string = conversation.user_ids_string;
- const users = people.get_users_from_ids(
- people.user_ids_string_to_ids_array(user_ids_string),
- );
+ const user_ids = people.user_ids_string_to_ids_array(user_ids_string);
+ const users = people.get_users_from_ids(user_ids);
if (!people.dm_matches_search_string(users, search_string)) {
// Skip adding the conversation to the display_objects array if it does
// not match the search_term.
@@ -84,8 +83,8 @@ export function get_conversations(search_string = ""): DisplayObject[] {
unread.num_unread_mentions_for_user_ids_strings(user_ids_string) > 0;
const is_group = user_ids_string.includes(",");
const is_active = user_ids_string === active_user_ids_string;
- const is_deactivated = !people.is_active_user_for_popover(
- Number.parseInt(user_ids_string, 10) || 0,
+ const includes_deactivated_user = user_ids.some(
+ (id) => !people.is_active_user_for_popover(id),
);
let user_circle_class;
@@ -95,7 +94,10 @@ export function get_conversations(search_string = ""): DisplayObject[] {
if (!is_group) {
const user_id = Number.parseInt(user_ids_string, 10);
- user_circle_class = buddy_data.get_user_circle_class(user_id, is_deactivated);
+ user_circle_class = buddy_data.get_user_circle_class(
+ user_id,
+ includes_deactivated_user,
+ );
const recipient_user_obj = people.get_by_user_id(user_id);
if (recipient_user_obj.is_bot) {
@@ -119,7 +121,7 @@ export function get_conversations(search_string = ""): DisplayObject[] {
is_group,
is_bot,
has_unread_mention,
- is_deactivated,
+ includes_deactivated_user,
is_current_user,
};
display_objects.push(display_object);
@@ -138,7 +140,7 @@ export function get_list_info(
} {
const conversations = get_conversations(search_term);
- if (zoomed || conversations.length <= max_conversations_to_show) {
+ if (zoomed) {
return {
conversations_to_be_shown: conversations,
more_conversations_unread_count: 0,
@@ -147,7 +149,10 @@ export function get_list_info(
const conversations_to_be_shown = [];
let more_conversations_unread_count = 0;
- function should_show_conversation(idx: number, conversation: DisplayObject): boolean {
+
+ function should_show_conversation(conversation: DisplayObject): boolean {
+ const current_to_be_shown_count = conversations_to_be_shown.length;
+
// We always show the active conversation; see the similar
// comment in topic_list_data.ts.
if (conversation.is_active) {
@@ -157,10 +162,16 @@ export function get_list_info(
// We don't need to filter muted users here, because
// pm_conversations.js takes care of this for us.
+ // Conversations that include any deactivated users should
+ // only be visible in the unzoomed view.
+ if (conversation.includes_deactivated_user) {
+ return false;
+ }
+
// We include the most recent max_conversations_to_show
// conversations, regardless of whether they have unread
// messages.
- if (idx < max_conversations_to_show) {
+ if (current_to_be_shown_count < max_conversations_to_show) {
return true;
}
@@ -169,7 +180,7 @@ export function get_list_info(
// topics have been included.
if (
conversation.unread > 0 &&
- conversations_to_be_shown.length < max_conversations_to_show_with_unreads
+ current_to_be_shown_count < max_conversations_to_show_with_unreads
) {
return true;
}
@@ -178,8 +189,9 @@ export function get_list_info(
// the unzoomed view.
return false;
}
- for (const [idx, conversation] of conversations.entries()) {
- if (should_show_conversation(idx, conversation)) {
+
+ for (const conversation of conversations) {
+ if (should_show_conversation(conversation)) {
conversations_to_be_shown.push(conversation);
} else {
more_conversations_unread_count += conversation.unread;
diff --git a/web/tests/pm_list_data.test.cjs b/web/tests/pm_list_data.test.cjs
index ebbfec65a6f..8472d9225da 100644
--- a/web/tests/pm_list_data.test.cjs
+++ b/web/tests/pm_list_data.test.cjs
@@ -117,7 +117,7 @@ test("get_conversations", ({override}) => {
is_bot: false,
is_current_user: true,
is_active: false,
- is_deactivated: false,
+ includes_deactivated_user: false,
is_group: false,
is_zero: false,
recipients: "Me Myself",
@@ -137,7 +137,7 @@ test("get_conversations", ({override}) => {
unread: 1,
is_zero: false,
is_active: false,
- is_deactivated: false,
+ includes_deactivated_user: false,
url: "#narrow/dm/101,102-group",
user_circle_class: undefined,
is_group: true,
@@ -168,7 +168,7 @@ test("get_conversations", ({override}) => {
unread: 0,
is_zero: true,
is_active: true,
- is_deactivated: false,
+ includes_deactivated_user: false,
is_current_user: false,
url: "#narrow/dm/106-Iago",
status_emoji_info: {emoji_code: "20"},
@@ -211,7 +211,7 @@ test("get_conversations bot", ({override}) => {
unread: 1,
is_zero: false,
is_active: false,
- is_deactivated: false,
+ includes_deactivated_user: false,
url: "#narrow/dm/314-Outgoing-webhook",
status_emoji_info: undefined,
user_circle_class: "user-circle-offline",
@@ -226,7 +226,7 @@ test("get_conversations bot", ({override}) => {
unread: 1,
is_zero: false,
is_active: false,
- is_deactivated: false,
+ includes_deactivated_user: false,
url: "#narrow/dm/101,102-group",
user_circle_class: undefined,
status_emoji_info: undefined,
@@ -424,3 +424,96 @@ test("get_list_info_no_unread_messages", ({override}) => {
"Alice",
]);
});
+
+test("get_list_info_deactivated_users", ({override}) => {
+ override(unread, "num_unread_for_user_ids_string", () => 0);
+
+ // Set up recent direct message conversations.
+ pm_conversations.recent.insert([alice.user_id], 1);
+ pm_conversations.recent.insert([me.user_id], 2);
+ pm_conversations.recent.insert([bob.user_id], 3);
+ pm_conversations.recent.insert([zoe.user_id], 4);
+ pm_conversations.recent.insert([cardelio.user_id], 5);
+
+ // Deactivate Bob.
+ const bob_from_people = people.get_by_user_id(bob.user_id);
+ people.deactivate(bob_from_people);
+
+ // When only 5 direct message conversations are present
+ // and Bob is deactivated, we should show only 4.
+ let list_info = pm_list_data.get_list_info(false);
+ // Verify that Bob (deactivated) is not included.
+ check_list_info(list_info, 4, 0, ["Cardelio", "Zoe", "Me Myself", "Alice"]);
+
+ // Set up more conversations than max_conversations_to_show
+ // (which is 8), including one recent group conversation that
+ // involves Bob who has been deactivated.
+ pm_conversations.recent.insert([zoe.user_id, cardelio.user_id], 6);
+ pm_conversations.recent.insert([bob.user_id, cardelio.user_id], 7);
+ pm_conversations.recent.insert([alice.user_id, iago.user_id], 8);
+ pm_conversations.recent.insert([alice.user_id, cardelio.user_id], 9);
+ pm_conversations.recent.insert([zoe.user_id, iago.user_id], 10);
+ pm_conversations.recent.insert([iago.user_id], 11);
+ pm_conversations.recent.insert([alice.user_id, zoe.user_id], 12);
+ pm_conversations.recent.insert([cardelio.user_id, iago.user_id], 13);
+
+ // There are 13 total conversations, 2 involve Bob and are excluded.
+ // From the remaining 11 conversantions latest 8 are included.
+ list_info = pm_list_data.get_list_info(false);
+ // Verify that Bob (deactivated) is not included.
+ check_list_info(list_info, 8, 0, [
+ "Cardelio, Iago",
+ "Alice, Zoe",
+ "Iago",
+ "Iago, Zoe",
+ "Alice, Cardelio",
+ "Alice, Iago",
+ "Cardelio, Zoe",
+ "Cardelio",
+ ]);
+
+ // Zooming in should reveal all direct message conversations including
+ // the conversations with Bob.
+ list_info = pm_list_data.get_list_info(true);
+ check_list_info(list_info, 13, 0, [
+ "Cardelio, Iago",
+ "Alice, Zoe",
+ "Iago",
+ "Iago, Zoe",
+ "Alice, Cardelio",
+ "Alice, Iago",
+ "Bob, Cardelio",
+ "Cardelio, Zoe",
+ "Cardelio",
+ "Zoe",
+ "Bob",
+ "Me Myself",
+ "Alice",
+ ]);
+
+ override(unread, "num_unread_for_user_ids_string", () => 1);
+
+ // Verify with unread messages that conversations with Bob are still
+ // not shown in the unzoomed case, and the unread count for more
+ // conversations is updated for those 2 conversations.
+ list_info = pm_list_data.get_list_info(false);
+ assert.deepEqual(list_info.conversations_to_be_shown.length, 11);
+ assert.deepEqual(list_info.more_conversations_unread_count, 2);
+ // Verify that Bob (deactivated) is not included.
+ check_list_info(list_info, 11, 2, [
+ "Cardelio, Iago",
+ "Alice, Zoe",
+ "Iago",
+ "Iago, Zoe",
+ "Alice, Cardelio",
+ "Alice, Iago",
+ "Cardelio, Zoe",
+ "Cardelio",
+ "Zoe",
+ "Me Myself",
+ "Alice",
+ ]);
+
+ // Reactivate Bob to not affect other tests.
+ people.add_active_user(bob);
+});