mirror of https://github.com/zulip/zulip.git
narrow: Add "(guest)" to user names in narrow title.
This commit adds "(guest)" to user names in the narrow title when enable_guest_user_indicator setting is enabled in the organization. The indicator, based on the setting, is added for DM narrows and for "sender:" narrows.
This commit is contained in:
parent
70c9d0765f
commit
268aab3cda
|
@ -706,10 +706,15 @@ export class Filter {
|
||||||
) {
|
) {
|
||||||
const emails = this.operands("dm")[0].split(",");
|
const emails = this.operands("dm")[0].split(",");
|
||||||
const names = emails.map((email) => {
|
const names = emails.map((email) => {
|
||||||
if (!people.get_by_email(email)) {
|
const person = people.get_by_email(email);
|
||||||
|
if (!person) {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
return people.get_by_email(email).full_name;
|
|
||||||
|
if (people.should_add_guest_user_indicator(person.user_id)) {
|
||||||
|
return $t({defaultMessage: "{name} (guest)"}, {name: person.full_name});
|
||||||
|
}
|
||||||
|
return person.full_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
// We use join to handle the addition of a comma and space after every name
|
// We use join to handle the addition of a comma and space after every name
|
||||||
|
@ -725,8 +730,14 @@ export class Filter {
|
||||||
if (people.is_my_user_id(user.user_id)) {
|
if (people.is_my_user_id(user.user_id)) {
|
||||||
return $t({defaultMessage: "Messages sent by you"});
|
return $t({defaultMessage: "Messages sent by you"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (people.should_add_guest_user_indicator(user.user_id)) {
|
||||||
|
sender = $t({defaultMessage: "{name} (guest)"}, {name: user.full_name});
|
||||||
|
} else {
|
||||||
sender = user.full_name;
|
sender = user.full_name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $t(
|
return $t(
|
||||||
{defaultMessage: "Messages sent by {sender}"},
|
{defaultMessage: "Messages sent by {sender}"},
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,9 +35,17 @@ const steve = {
|
||||||
full_name: "steve",
|
full_name: "steve",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const alice = {
|
||||||
|
email: "alice@example.com",
|
||||||
|
user_id: 33,
|
||||||
|
full_name: "alice",
|
||||||
|
is_guest: true,
|
||||||
|
};
|
||||||
|
|
||||||
people.add_active_user(me);
|
people.add_active_user(me);
|
||||||
people.add_active_user(joe);
|
people.add_active_user(joe);
|
||||||
people.add_active_user(steve);
|
people.add_active_user(steve);
|
||||||
|
people.add_active_user(alice);
|
||||||
people.initialize_current_user(me.user_id);
|
people.initialize_current_user(me.user_id);
|
||||||
|
|
||||||
function assert_same_operators(result, terms) {
|
function assert_same_operators(result, terms) {
|
||||||
|
@ -1523,6 +1531,7 @@ test("navbar_helpers", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const sender = [{operator: "sender", operand: joe.email}];
|
const sender = [{operator: "sender", operand: joe.email}];
|
||||||
|
const guest_sender = [{operator: "sender", operand: alice.email}];
|
||||||
const in_home = [{operator: "in", operand: "home"}];
|
const in_home = [{operator: "in", operand: "home"}];
|
||||||
const in_all = [{operator: "in", operand: "all"}];
|
const in_all = [{operator: "in", operand: "all"}];
|
||||||
const is_starred = [{operator: "is", operand: "starred"}];
|
const is_starred = [{operator: "is", operand: "starred"}];
|
||||||
|
@ -1547,6 +1556,10 @@ test("navbar_helpers", () => {
|
||||||
];
|
];
|
||||||
const dm = [{operator: "dm", operand: "joe@example.com"}];
|
const dm = [{operator: "dm", operand: "joe@example.com"}];
|
||||||
const dm_group = [{operator: "dm", operand: "joe@example.com,STEVE@foo.com"}];
|
const dm_group = [{operator: "dm", operand: "joe@example.com,STEVE@foo.com"}];
|
||||||
|
const dm_with_guest = [{operator: "dm", operand: "alice@example.com"}];
|
||||||
|
const dm_group_including_guest = [
|
||||||
|
{operator: "dm", operand: "alice@example.com,joe@example.com"},
|
||||||
|
];
|
||||||
const dm_group_including_missing_person = [
|
const dm_group_including_missing_person = [
|
||||||
{operator: "dm", operand: "joe@example.com,STEVE@foo.com,sally@doesnotexist.com"},
|
{operator: "dm", operand: "joe@example.com,STEVE@foo.com,sally@doesnotexist.com"},
|
||||||
];
|
];
|
||||||
|
@ -1571,6 +1584,13 @@ test("navbar_helpers", () => {
|
||||||
title: "translated: Messages sent by " + joe.full_name,
|
title: "translated: Messages sent by " + joe.full_name,
|
||||||
redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe",
|
redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
operator: guest_sender,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: undefined,
|
||||||
|
title: "translated: Messages sent by translated: alice (guest)",
|
||||||
|
redirect_url_with_search: "/#narrow/sender/" + alice.user_id + "-alice",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
operator: is_starred,
|
operator: is_starred,
|
||||||
is_common_narrow: true,
|
is_common_narrow: true,
|
||||||
|
@ -1677,6 +1697,21 @@ test("navbar_helpers", () => {
|
||||||
title: properly_separated_names([joe.full_name, steve.full_name]),
|
title: properly_separated_names([joe.full_name, steve.full_name]),
|
||||||
redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + steve.user_id + "-group",
|
redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + steve.user_id + "-group",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
operator: dm_with_guest,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: "envelope",
|
||||||
|
title: "translated: alice (guest)",
|
||||||
|
redirect_url_with_search:
|
||||||
|
"/#narrow/dm/" + alice.user_id + "-" + parseOneAddress(alice.email).local,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
operator: dm_group_including_guest,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: "envelope",
|
||||||
|
title: "translated: alice (guest), joe",
|
||||||
|
redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + alice.user_id + "-group",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
operator: dm_group_including_missing_person,
|
operator: dm_group_including_missing_person,
|
||||||
is_common_narrow: true,
|
is_common_narrow: true,
|
||||||
|
@ -1718,6 +1753,8 @@ test("navbar_helpers", () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
page_params.realm_enable_guest_user_indicator = true;
|
||||||
|
|
||||||
for (const test_case of test_cases) {
|
for (const test_case of test_cases) {
|
||||||
test_helpers(test_case);
|
test_helpers(test_case);
|
||||||
}
|
}
|
||||||
|
@ -1774,6 +1811,35 @@ test("navbar_helpers", () => {
|
||||||
|
|
||||||
test_get_title(stream_topic_search_operator_test_case);
|
test_get_title(stream_topic_search_operator_test_case);
|
||||||
|
|
||||||
|
page_params.realm_enable_guest_user_indicator = false;
|
||||||
|
const guest_user_test_cases_without_indicator = [
|
||||||
|
{
|
||||||
|
operator: guest_sender,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: undefined,
|
||||||
|
title: "translated: Messages sent by alice",
|
||||||
|
redirect_url_with_search: "/#narrow/sender/" + alice.user_id + "-alice",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
operator: dm_with_guest,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: "envelope",
|
||||||
|
title: properly_separated_names([alice.full_name]),
|
||||||
|
redirect_url_with_search:
|
||||||
|
"/#narrow/dm/" + alice.user_id + "-" + parseOneAddress(alice.email).local,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
operator: dm_group_including_guest,
|
||||||
|
is_common_narrow: true,
|
||||||
|
icon: "envelope",
|
||||||
|
title: properly_separated_names([alice.full_name, joe.full_name]),
|
||||||
|
redirect_url_with_search:
|
||||||
|
"/#narrow/dm/" + Number(alice.user_id) + "," + joe.user_id + "-group",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
test_get_title(guest_user_test_cases_without_indicator);
|
||||||
|
|
||||||
// this is actually wrong, but the code is currently not robust enough to throw an error here
|
// this is actually wrong, but the code is currently not robust enough to throw an error here
|
||||||
// also, used as an example of triggering last return statement.
|
// also, used as an example of triggering last return statement.
|
||||||
const default_redirect = {
|
const default_redirect = {
|
||||||
|
|
Loading…
Reference in New Issue