From bd1d0e6b46793e0dcb84c4b0cfd3a55e75aa5bb9 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 1 Dec 2023 23:24:39 +0530 Subject: [PATCH] settings: Handle inaccessible users in muted users list. Inaccessible users are shown as "Unknown user" in muted users list. --- web/src/settings_muted_users.ts | 16 ++++++++++------ web/templates/muted_user_ui_row.hbs | 2 ++ web/tests/settings_muted_users.test.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/web/src/settings_muted_users.ts b/web/src/settings_muted_users.ts index d9821efdec..a43a6e8c64 100644 --- a/web/src/settings_muted_users.ts +++ b/web/src/settings_muted_users.ts @@ -17,12 +17,16 @@ type MutedUserItem = { }; export function populate_list(): void { - const all_muted_users = muted_users.get_muted_users().map((user) => ({ - user_id: user.id, - user_name: people.get_full_name(user.id), - date_muted: user.date_muted, - date_muted_str: user.date_muted_str, - })); + const all_muted_users = muted_users.get_muted_users().map((user) => { + const muted_user = people.get_user_by_id_assert_valid(user.id); + return { + user_id: user.id, + user_name: muted_user.full_name, + date_muted: user.date_muted, + date_muted_str: user.date_muted_str, + can_unmute: !muted_user.is_inaccessible_user, + }; + }); const $muted_users_table = $("#muted_users_table"); const $search_input = $("input#muted_users_search"); diff --git a/web/templates/muted_user_ui_row.hbs b/web/templates/muted_user_ui_row.hbs index b159d78a0c..7a590b8619 100644 --- a/web/templates/muted_user_ui_row.hbs +++ b/web/templates/muted_user_ui_row.hbs @@ -3,7 +3,9 @@ {{user_name}} {{date_muted_str}} + {{#if can_unmute}} {{t "Unmute" }} + {{/if}} {{/with}} diff --git a/web/tests/settings_muted_users.test.js b/web/tests/settings_muted_users.test.js index ec78937e02..273da800f7 100644 --- a/web/tests/settings_muted_users.test.js +++ b/web/tests/settings_muted_users.test.js @@ -12,6 +12,9 @@ const channel = mock_esm("../src/channel"); const list_widget = mock_esm("../src/list_widget", { generic_sort_functions: noop, }); +mock_esm("../src/settings_data", { + user_can_access_all_other_users: () => false, +}); const settings_muted_users = zrequire("settings_muted_users"); const muted_users = zrequire("muted_users"); @@ -20,6 +23,7 @@ const people = zrequire("people"); run_test("settings", ({override}) => { people.add_active_user({user_id: 5, email: "five@zulip.com", full_name: "Feivel Fiverson"}); muted_users.add_muted_user(5, 1577836800); + muted_users.add_muted_user(10, 1577836900); let populate_list_called = false; override(list_widget, "create", (_$container, list) => { assert.deepEqual(list, [ @@ -28,6 +32,14 @@ run_test("settings", ({override}) => { date_muted_str: "Jan 1, 2020", user_id: 5, user_name: "Feivel Fiverson", + can_unmute: true, + }, + { + date_muted: 1577836900000, + date_muted_str: "Jan 1, 2020", + user_id: 10, + user_name: "translated: Unknown user", + can_unmute: false, }, ]); populate_list_called = true;