settings: Handle inaccessible users in muted users list.

Inaccessible users are shown as "Unknown user" in muted
users list.
This commit is contained in:
Sahil Batra 2023-12-01 23:24:39 +05:30 committed by Tim Abbott
parent a3495d4103
commit bd1d0e6b46
3 changed files with 24 additions and 6 deletions

View File

@ -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 = $<HTMLInputElement>("input#muted_users_search");

View File

@ -3,7 +3,9 @@
<td>{{user_name}}</td>
<td>{{date_muted_str}}</td>
<td class="actions">
{{#if can_unmute}}
<span><a class="settings-unmute-user">{{t "Unmute" }}</a></span>
{{/if}}
</td>
</tr>
{{/with}}

View File

@ -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;