narrow: Add setter for narrow_title.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-28 11:21:01 -08:00 committed by Tim Abbott
parent 1ec97070e8
commit 4a2f937732
3 changed files with 18 additions and 19 deletions

View File

@ -20,10 +20,7 @@ set_global("compose_actions", {
cancel: noop,
});
set_global("narrow", {
narrow_title: "",
});
rewiremock("../../static/js/notifications").with({
redraw_title: noop,
set_narrow_title: noop,
});
rewiremock("../../static/js/message_view_header").with({
render_title_area: noop,

View File

@ -100,42 +100,46 @@ exports.save_pre_narrow_offset_for_reload = function () {
}
};
exports.narrow_title = "home";
exports.set_narrow_title = function (title) {
exports.narrow_title = title;
notifications.redraw_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")) {
if (filter.has_operator("topic")) {
exports.narrow_title = filter.operands("topic")[0];
exports.set_narrow_title(filter.operands("topic")[0]);
} else {
exports.narrow_title = filter.operands("stream")[0];
exports.set_narrow_title(filter.operands("stream")[0]);
}
} else if (filter.has_operator("is")) {
let title = filter.operands("is")[0];
title = title.charAt(0).toUpperCase() + title.slice(1) + " messages";
exports.narrow_title = title;
const title = filter.operands("is")[0];
exports.set_narrow_title(title.charAt(0).toUpperCase() + title.slice(1) + " messages");
} else if (filter.has_operator("pm-with") || filter.has_operator("group-pm-with")) {
const emails = filter.public_operators()[0].operand;
const user_ids = people.emails_strings_to_user_ids_string(emails);
if (user_ids !== undefined) {
const names = people.get_recipients(user_ids);
if (filter.has_operator("pm-with")) {
exports.narrow_title = names;
exports.set_narrow_title(names);
} else {
exports.narrow_title = names + " and others";
exports.set_narrow_title(names + " and others");
}
} else {
if (emails.includes(",")) {
exports.narrow_title = "Invalid users";
exports.set_narrow_title("Invalid users");
} else {
exports.narrow_title = "Invalid user";
exports.set_narrow_title("Invalid user");
}
}
}
notifications.redraw_title();
}
exports.narrow_title = "home";
exports.activate = function (raw_operators, opts) {
/* Main entrypoint for switching to a new view / message list.
Note that for historical reasons related to the current

View File

@ -12,7 +12,6 @@ import * as message_view_header from "./message_view_header";
import * as muting from "./muting";
import * as narrow_state from "./narrow_state";
import * as navigate from "./navigate";
import * as notifications from "./notifications";
import * as panels from "./panels";
import * as people from "./people";
import * as recent_senders from "./recent_senders";
@ -496,9 +495,8 @@ export function show() {
// with no compose box.
compose_actions.cancel();
narrow.narrow_title = "Recent topics";
narrow_state.set_current_filter(undefined);
notifications.redraw_title();
narrow_state.reset_current_filter();
narrow.set_narrow_title("Recent topics");
message_view_header.render_title_area();
complete_rerender();