diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js
index a60a68f2b1..f39c6ec9fa 100644
--- a/frontend_tests/node_tests/narrow.js
+++ b/frontend_tests/node_tests/narrow.js
@@ -57,6 +57,13 @@ const ray = {
full_name: "Raymond",
};
+const bot = {
+ email: "bot@example.com",
+ user_id: 25,
+ full_name: "Example Bot",
+ is_bot: true,
+};
+
function hide_all_empty_narrow_messages() {
const all_empty_narrow_messages = [
".empty_feed_notice",
@@ -372,6 +379,32 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
),
);
+ // private messages with a bot are possible even though
+ // the organization has disabled sending private messages
+ people.add_active_user(bot);
+ set_filter([["pm-with", "bot@example.com"]]);
+ hide_all_empty_narrow_messages();
+ narrow_banner.show_empty_narrow_message();
+ assert.equal(
+ $(".empty_feed_notice_main").html(),
+ empty_narrow_html(
+ "translated HTML: You have no private messages with Example Bot yet.",
+ 'translated HTML: Why not start the conversation?',
+ ),
+ );
+
+ // group private messages with bots are not possible when
+ // sending private messages is disabled
+ set_filter([["pm-with", bot.email + "," + alice.email]]);
+ hide_all_empty_narrow_messages();
+ narrow_banner.show_empty_narrow_message();
+ assert.equal(
+ $(".empty_feed_notice_main").html(),
+ empty_narrow_html(
+ "translated: You are not allowed to send private messages in this organization.",
+ ),
+ );
+
// sending private messages enabled
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.by_anyone.code;
@@ -381,7 +414,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
- "translated: You have no private messages with this person yet!",
+ "translated HTML: You have no private messages with Alice Smith yet.",
'translated HTML: Why not start the conversation?',
),
);
@@ -405,7 +438,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
- "translated: You have no private messages with these people yet!",
+ "translated: You have no private messages with these people yet.",
'translated HTML: Why not start the conversation?',
),
);
@@ -433,6 +466,18 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
),
);
+ // group private messages with bots are not possible when
+ // sending private messages is disabled
+ set_filter([["group-pm-with", "bot@example.com"]]);
+ hide_all_empty_narrow_messages();
+ narrow_banner.show_empty_narrow_message();
+ assert.equal(
+ $(".empty_feed_notice_main").html(),
+ empty_narrow_html(
+ "translated: You are not allowed to send group private messages in this organization.",
+ ),
+ );
+
// sending private messages enabled
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.by_anyone.code;
@@ -442,7 +487,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
- "translated: You have no group private messages with this person yet!",
+ "translated HTML: You have no group private messages with Alice Smith yet.",
'translated HTML: Why not start the conversation?',
),
);
@@ -452,7 +497,9 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
- empty_narrow_html("translated: You haven't received any messages sent by this user yet!"),
+ empty_narrow_html(
+ "translated HTML: You haven't received any messages sent by Raymond yet.",
+ ),
);
set_filter([["sender", "sinwar@example.com"]]);
diff --git a/frontend_tests/puppeteer_tests/message-basics.ts b/frontend_tests/puppeteer_tests/message-basics.ts
index 685002cd7d..e9f4dc063f 100644
--- a/frontend_tests/puppeteer_tests/message-basics.ts
+++ b/frontend_tests/puppeteer_tests/message-basics.ts
@@ -152,7 +152,7 @@ async function search_silent_user(page: Page, str: string, item: string): Promis
await page.waitForSelector("#search_query", {visible: true});
await common.select_item_via_typeahead(page, "#search_query", str, item);
await page.waitForSelector(".empty_feed_notice", {visible: true});
- const expect_message = "You haven't received any messages sent by this user yet!";
+ const expect_message = "You haven't received any messages sent by Email Gateway yet.";
assert.strictEqual(
await common.get_text_from_selector(page, ".empty_feed_notice"),
expect_message,
diff --git a/static/js/narrow_banner.js b/static/js/narrow_banner.js
index ad38bd4261..974efd2917 100644
--- a/static/js/narrow_banner.js
+++ b/static/js/narrow_banner.js
@@ -281,7 +281,7 @@ function pick_empty_narrow_banner() {
search_data: retrieve_search_query_data(),
};
}
- case "pm-with":
+ case "pm-with": {
if (!people.is_valid_bulk_emails_for_compose(first_operand.split(","))) {
if (!first_operand.includes(",")) {
return {
@@ -292,9 +292,11 @@ function pick_empty_narrow_banner() {
title: $t({defaultMessage: "One or more of these users do not exist!"}),
};
}
+ const user_ids = people.emails_strings_to_user_ids_array(first_operand);
if (
page_params.realm_private_message_policy ===
- settings_config.private_message_policy_values.disabled.code
+ settings_config.private_message_policy_values.disabled.code &&
+ (user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot)
) {
return {
title: $t({
@@ -326,9 +328,12 @@ function pick_empty_narrow_banner() {
};
}
return {
- title: $t({
- defaultMessage: "You have no private messages with this person yet!",
- }),
+ title: $t_html(
+ {
+ defaultMessage: "You have no private messages with {person} yet.",
+ },
+ {person: people.get_by_user_id(user_ids[0]).full_name},
+ ),
html: $t_html(
{
defaultMessage: "Why not start the conversation?",
@@ -343,7 +348,7 @@ function pick_empty_narrow_banner() {
};
}
return {
- title: $t({defaultMessage: "You have no private messages with these people yet!"}),
+ title: $t({defaultMessage: "You have no private messages with these people yet."}),
html: $t_html(
{
defaultMessage: "Why not start the conversation?",
@@ -356,19 +361,27 @@ function pick_empty_narrow_banner() {
},
),
};
- case "sender":
- if (people.get_by_email(first_operand)) {
+ }
+ case "sender": {
+ const sender = people.get_by_email(first_operand);
+ if (sender) {
return {
- title: $t({
- defaultMessage: "You haven't received any messages sent by this user yet!",
- }),
+ title: $t_html(
+ {
+ defaultMessage:
+ "You haven't received any messages sent by {person} yet.",
+ },
+ {person: sender.full_name},
+ ),
};
}
return {
title: $t({defaultMessage: "This user does not exist!"}),
};
- case "group-pm-with":
- if (!people.get_by_email(first_operand)) {
+ }
+ case "group-pm-with": {
+ const person_in_group_pm = people.get_by_email(first_operand);
+ if (!person_in_group_pm) {
return {
title: $t({defaultMessage: "This user does not exist!"}),
};
@@ -385,9 +398,12 @@ function pick_empty_narrow_banner() {
};
}
return {
- title: $t({
- defaultMessage: "You have no group private messages with this person yet!",
- }),
+ title: $t_html(
+ {
+ defaultMessage: "You have no group private messages with {person} yet.",
+ },
+ {person: person_in_group_pm.full_name},
+ ),
html: $t_html(
{
defaultMessage: "Why not start the conversation?",
@@ -398,6 +414,7 @@ function pick_empty_narrow_banner() {
},
),
};
+ }
}
return default_banner;
}