narrow_state: Rename stream() to stream_name() which is more accurate.

This commit is contained in:
evykassirer 2023-06-26 09:52:26 -07:00 committed by Tim Abbott
parent ba9cfc2cd8
commit d9edcba724
14 changed files with 28 additions and 28 deletions

View File

@ -403,7 +403,7 @@ export function on_topic_narrow() {
return;
}
if (compose_state.stream_name() !== narrow_state.stream()) {
if (compose_state.stream_name() !== narrow_state.stream_name()) {
// If we changed streams, then we only leave the
// compose box open if there is content or if the recipient was edited.
if (compose_state.has_message_content() || compose_state.is_recipient_edited_manually()) {

View File

@ -20,7 +20,7 @@ export function get_recipient_label(message) {
// we label the button as replying to the thread.
if (narrow_state.narrowed_to_topic()) {
message = {
stream: narrow_state.stream(),
stream: narrow_state.stream_name(),
topic: narrow_state.topic(),
};
} else if (narrow_state.pm_ids_string()) {

View File

@ -36,7 +36,7 @@ export function set_selected_recipient_id(recipient_id) {
function composing_to_current_topic_narrow() {
return (
util.lower_same(compose_state.stream_name(), narrow_state.stream() || "") &&
util.lower_same(compose_state.stream_name(), narrow_state.stream_name() || "") &&
util.lower_same(compose_state.topic(), narrow_state.topic() || "")
);
}

View File

@ -451,7 +451,7 @@ function current_recipient_data() {
// Prioritize recipients from the compose box first. If the compose
// box isn't open, just return data from the current narrow.
if (!compose_state.composing()) {
const stream_name = narrow_state.stream();
const stream_name = narrow_state.stream_name();
return {
stream_name,
topic: narrow_state.topic(),

View File

@ -326,7 +326,7 @@ export class MessageList {
if (!this.narrowed) {
return;
}
const stream_name = narrow_state.stream();
const stream_name = narrow_state.stream_name();
if (stream_name === undefined) {
return;
}

View File

@ -927,7 +927,7 @@ export class MessageListView {
last_message_group.message_containers.at(-1).msg.historical;
}
const stream_name = narrow_state.stream();
const stream_name = narrow_state.stream_name();
if (stream_name !== undefined) {
// If user narrows to a stream, doesn't update
// trailing bookend if user is subscribed.

View File

@ -801,7 +801,7 @@ export function activate_stream_for_cycle_hotkey(stream_name) {
}
export function stream_cycle_backward() {
const curr_stream = narrow_state.stream();
const curr_stream = narrow_state.stream_name();
if (!curr_stream) {
return;
@ -817,7 +817,7 @@ export function stream_cycle_backward() {
}
export function stream_cycle_forward() {
const curr_stream = narrow_state.stream();
const curr_stream = narrow_state.stream_name();
if (!curr_stream) {
return;
@ -834,7 +834,7 @@ export function stream_cycle_forward() {
export function narrow_to_next_topic(opts = {}) {
const curr_info = {
stream: narrow_state.stream(),
stream: narrow_state.stream_name(),
topic: narrow_state.topic(),
};

View File

@ -243,7 +243,7 @@ function pick_empty_narrow_banner() {
}
function can_toggle_narrowed_stream() {
const stream_name = narrow_state.stream();
const stream_name = narrow_state.stream_name();
if (!stream_name) {
return false;

View File

@ -110,7 +110,7 @@ export function set_compose_defaults() {
return opts;
}
export function stream() {
export function stream_name() {
if (current_filter === undefined) {
return undefined;
}

View File

@ -401,7 +401,7 @@ function get_topic_suggestions(last, operators) {
if (filter.has_operator("stream")) {
stream = filter.operands("stream")[0];
} else {
stream = narrow_state.stream();
stream = narrow_state.stream_name();
suggest_operators.push({operator: "stream", operand: stream});
}
break;

View File

@ -79,7 +79,7 @@ run_test("narrow_state", () => {
// As we often do, first make assertions about the starting
// state:
assert.equal(narrow_state.stream(), undefined);
assert.equal(narrow_state.stream_name(), undefined);
// Now set up a Filter object.
const filter_terms = [
@ -92,6 +92,6 @@ run_test("narrow_state", () => {
// And here is where we actually change state.
narrow_state.set_current_filter(filter);
assert.equal(narrow_state.stream(), "Denmark");
assert.equal(narrow_state.stream_name(), "Denmark");
assert.equal(narrow_state.topic(), "copenhagen");
});

View File

@ -332,7 +332,7 @@ run_test("bookend", ({override}) => {
list.view.clear_trailing_bookend = noop;
list.narrowed = true;
override(narrow_state, "stream", () => "IceCream");
override(narrow_state, "stream_name", () => "IceCream");
let is_subscribed = true;
let invite_only = false;

View File

@ -42,7 +42,7 @@ test("stream", () => {
]);
assert.ok(narrow_state.active());
assert.equal(narrow_state.stream(), "Test");
assert.equal(narrow_state.stream_name(), "Test");
assert.equal(narrow_state.stream_sub().stream_id, test_stream.stream_id);
assert.equal(narrow_state.topic(), "Bar");
assert.ok(narrow_state.is_for_stream_id(test_stream.stream_id));
@ -268,14 +268,14 @@ test("topic", () => {
test("stream_sub", () => {
set_filter([]);
assert.equal(narrow_state.stream(), undefined);
assert.equal(narrow_state.stream_name(), undefined);
assert.equal(narrow_state.stream_sub(), undefined);
set_filter([
["stream", "Foo"],
["topic", "Bar"],
]);
assert.equal(narrow_state.stream(), "Foo");
assert.equal(narrow_state.stream_name(), "Foo");
assert.equal(narrow_state.stream_sub(), undefined);
const sub = {name: "Foo", stream_id: 55};
@ -286,7 +286,7 @@ test("stream_sub", () => {
["sender", "someone"],
["topic", "random"],
]);
assert.equal(narrow_state.stream(), undefined);
assert.equal(narrow_state.stream_name(), undefined);
});
test("pm_ids_string", () => {

View File

@ -82,7 +82,7 @@ function test(label, f) {
test("basic_get_suggestions", ({override}) => {
const query = "fred";
override(narrow_state, "stream", () => "office");
override(narrow_state, "stream_name", () => "office");
const suggestions = get_suggestions(query);
@ -240,7 +240,7 @@ test("dm_suggestions", ({override, mock_template}) => {
// "pm-with" operator returns search result
// and "dm" operator as a suggestions
override(narrow_state, "stream", () => undefined);
override(narrow_state, "stream_name", () => undefined);
query = "pm-with";
suggestions = get_suggestions(query);
expected = ["pm-with", "dm:"];
@ -460,7 +460,7 @@ test("has_suggestions", ({override, mock_template}) => {
let query = "h";
stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
override(narrow_state, "stream", () => {});
override(narrow_state, "stream_name", () => {});
let suggestions = get_suggestions(query);
let expected = ["h", "has:link", "has:image", "has:attachment"];
@ -519,7 +519,7 @@ test("check_is_suggestions", ({override, mock_template}) => {
stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
override(narrow_state, "stream", () => {});
override(narrow_state, "stream_name", () => {});
let query = "i";
let suggestions = get_suggestions(query);
@ -600,7 +600,7 @@ test("check_is_suggestions", ({override, mock_template}) => {
test("sent_by_me_suggestions", ({override, mock_template}) => {
mock_template("search_description.hbs", true, (_data, html) => html);
override(narrow_state, "stream", () => {});
override(narrow_state, "stream_name", () => {});
let query = "";
let suggestions = get_suggestions(query);
@ -678,7 +678,7 @@ test("topic_suggestions", ({override, mock_template}) => {
override(stream_topic_history_util, "get_server_history", () => {});
stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
override(narrow_state, "stream", () => "office");
override(narrow_state, "stream_name", () => "office");
const devel_id = 44;
const office_id = 77;
@ -817,7 +817,7 @@ test("stream_completion", ({override, mock_template}) => {
stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
stream_data.add_sub({stream_id: 88, name: "dev help", subscribed: true});
override(narrow_state, "stream", () => {});
override(narrow_state, "stream_name", () => {});
let query = "stream:of";
let suggestions = get_suggestions(query);
@ -840,7 +840,7 @@ test("people_suggestions", ({override, mock_template}) => {
let query = "te";
override(narrow_state, "stream", () => {});
override(narrow_state, "stream_name", () => {});
const ted = {
email: "ted@zulip.com",
@ -942,7 +942,7 @@ test("people_suggestions", ({override, mock_template}) => {
test("operator_suggestions", ({override, mock_template}) => {
mock_template("search_description.hbs", true, (_data, html) => html);
override(narrow_state, "stream", () => undefined);
override(narrow_state, "stream_name", () => undefined);
// Completed operator should return nothing
let query = "stream:";