users: Add "(guest)" to user name at various places.

This commit adds code to get_display_full_name function
to add "(guest)" indicator to guest user names if
enable_guest_user_indicator setting is enabled in the
organization.

The get_display_full_name function is used in many parts
of the code and thus this commit adds the indicator in
following places -
- Message recipient row for DMs including the messages
shown in scheduled messages overlay.
- DMs list in left sidebar and its tooltips.
- DMs info recent conversations view.
- "other senders" tooltip in recent conversations view.
- Compose button text.
- User names shown on reaction element and its tooltip.
- Desktop notifications and the browser title.
- Results for a poll.
This commit is contained in:
Sahil Batra 2023-09-15 23:30:56 +05:30 committed by Tim Abbott
parent 268aab3cda
commit 127378f0ec
2 changed files with 23 additions and 3 deletions

View File

@ -424,6 +424,10 @@ export function get_display_full_name(user_id: number): string {
return $t({defaultMessage: "Muted user"});
}
if (should_add_guest_user_indicator(user_id)) {
return $t({defaultMessage: "{name} (guest)"}, {name: person.full_name});
}
return person.full_name;
}

View File

@ -470,16 +470,32 @@ test_people("get_display_full_names", () => {
people.add_active_user(steven);
people.add_active_user(bob);
people.add_active_user(charles);
const user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id];
people.add_active_user(guest);
page_params.realm_enable_guest_user_indicator = true;
const user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id, guest.user_id];
let names = people.get_display_full_names(user_ids);
// This doesn't do anything special for the current user. The caller has
// to take care of such cases and do the appropriate.
assert.deepEqual(names, ["Me Myself", "Steven", "Bob van Roberts", "Charles Dickens"]);
assert.deepEqual(names, [
"Me Myself",
"Steven",
"Bob van Roberts",
"Charles Dickens",
"translated: Guest User (guest)",
]);
muted_users.add_muted_user(charles.user_id);
page_params.realm_enable_guest_user_indicator = false;
names = people.get_display_full_names(user_ids);
assert.deepEqual(names, ["Me Myself", "Steven", "Bob van Roberts", "translated: Muted user"]);
assert.deepEqual(names, [
"Me Myself",
"Steven",
"Bob van Roberts",
"translated: Muted user",
"Guest User",
]);
});
test_people("my_custom_profile_data", () => {