Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

narrow: Update browser title when in a narrow search view.

Lauryn Menard8089910dcb67
diff --git a/frontend_tests/puppeteer_tests/drafts.ts b/frontend_tests/puppeteer_tests/drafts.ts
index e0640b79582..91dc3b58d6c 100644
--- a/frontend_tests/puppeteer_tests/drafts.ts
+++ b/frontend_tests/puppeteer_tests/drafts.ts
@@ -36,7 +36,7 @@ async function create_stream_message_draft(page: Page): Promise<void> {
await page.keyboard.press("KeyC");
await page.waitForSelector("#stream-message", {visible: true});
await common.fill_form(page, "form#send_message_form", {
- stream_message_recipient_stream: "all",
+ stream_message_recipient_stream: "Denmark",
stream_message_recipient_topic: "tests",
content: "Test stream message.",
});
@@ -78,7 +78,7 @@ async function test_previously_created_drafts_rendered(page: Page): Promise<void
page,
".draft-row .message_header_stream .stream_label",
),
- "all",
+ "Denmark",
);
assert.strictEqual(
await common.get_text_from_selector(
@@ -117,20 +117,20 @@ async function test_restore_message_draft(page: Page): Promise<void> {
await page.waitForSelector("#stream-message", {visible: true});
await page.waitForSelector("#preview_message_area", {hidden: true});
await common.check_form_contents(page, "form#send_message_form", {
- stream_message_recipient_stream: "all",
+ stream_message_recipient_stream: "Denmark",
stream_message_recipient_topic: "tests",
content: "Test stream message.",
});
assert.strictEqual(
await common.get_text_from_selector(page, "title"),
- "#all > tests - Zulip Dev - Zulip",
+ "#Denmark > tests - Zulip Dev - Zulip",
"Didn't narrow to the right topic.",
);
}
async function edit_stream_message_draft(page: Page): Promise<void> {
await common.fill_form(page, "form#send_message_form", {
- stream_message_recipient_stream: "all",
+ stream_message_recipient_stream: "Denmark",
stream_message_recipient_topic: "tests",
content: "Updated stream message",
});
@@ -147,7 +147,7 @@ async function test_edited_draft_message(page: Page): Promise<void> {
page,
".draft-row .message_header_stream .stream_label",
),
- "all",
+ "Denmark",
);
assert.strictEqual(
await common.get_text_from_selector(
@@ -159,7 +159,7 @@ async function test_edited_draft_message(page: Page): Promise<void> {
assert.strictEqual(
await common.get_text_from_selector(
page,
- ".draft-row:nth-last-child(2) .rendered_markdown.restore-draft",
+ ".draft-row .message_row:not(.private-message) .rendered_markdown.restore-draft",
),
"Updated stream message",
);
diff --git a/frontend_tests/puppeteer_tests/message-basics.ts b/frontend_tests/puppeteer_tests/message-basics.ts
index 97bd46ff5f4..48c14e4e1e2 100644
--- a/frontend_tests/puppeteer_tests/message-basics.ts
+++ b/frontend_tests/puppeteer_tests/message-basics.ts
@@ -232,7 +232,7 @@ async function search_tests(page: Page): Promise<void> {
"topic:test",
"",
expect_test_topic,
- "All messages - Zulip Dev - Zulip",
+ "Search results - Zulip Dev - Zulip",
);
await search_silent_user(page, "sender:[email protected]", "");
diff --git a/static/js/narrow.js b/static/js/narrow.js
index 1306f0cab2d..e83baad9fcc 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -126,32 +126,37 @@ export function set_narrow_title(title) {
}
function update_narrow_title(filter) {
- // Take the most detailed part of the narrow to use as the title.
- // If the operator is something other than "stream", "topic", or
- // "is", we shouldn't update the narrow title
- if (filter.has_operator("stream")) {
- const stream_name = filter.operands("stream")[0];
- if (filter.has_operator("topic")) {
- const topic_name = filter.operands("topic")[0];
- set_narrow_title("#" + stream_name + " > " + topic_name);
- } else {
- set_narrow_title("#" + stream_name);
- }
- } else if (filter.has_operator("is")) {
- const title = filter.operands("is")[0];
- set_narrow_title(title.charAt(0).toUpperCase() + title.slice(1) + " messages");
- } else if (filter.has_operator("pm-with")) {
- const emails = filter.operands("pm-with")[0];
- const user_ids = people.emails_strings_to_user_ids_string(emails);
- if (user_ids !== undefined) {
- const names = people.get_recipients(user_ids);
- set_narrow_title(names);
- } else {
- if (emails.includes(",")) {
- set_narrow_title("Invalid users");
+ const filter_title = filter.get_title();
+ const search_default = $t({defaultMessage: "Search results"});
+
+ if (filter_title !== undefined) {
+ if (filter.has_operator("stream")) {
+ if (!filter._sub) {
+ // The stream is not set because it does not currently
+ // exist (possibly due to a stream name change), or it
+ // is a private stream and the user is not subscribed.
+ set_narrow_title(filter_title);
+ } else if (filter.has_operator("topic")) {
+ const topic_name = filter.operands("topic")[0];
+ set_narrow_title("#" + filter_title + " > " + topic_name);
} else {
- set_narrow_title("Invalid user");
+ set_narrow_title("#" + filter_title);
}
+ } else if (filter.has_operator("pm-with")) {
+ const emails = filter.operands("pm-with")[0];
+ const user_ids = people.emails_strings_to_user_ids_string(emails);
+ if (user_ids !== undefined) {
+ const names = people.get_recipients(user_ids);
+ set_narrow_title(names);
+ } else {
+ if (emails.includes(",")) {
+ set_narrow_title("Invalid users");
+ } else {
+ set_narrow_title("Invalid user");
+ }
+ }
+ } else {
+ set_narrow_title(filter_title);
}
} else if (filter.has_operator("group-pm-with")) {
const emails = filter.operands("group-pm-with")[0];
@@ -166,6 +171,8 @@ function update_narrow_title(filter) {
set_narrow_title("Invalid user");
}
}
+ } else {
+ set_narrow_title(search_default);
}
}