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.

filter: Return `NarrowTerm` instead of just `operand`.

Aman Agrawalf7c0d4a356c2
diff --git a/web/src/compose_tooltips.ts b/web/src/compose_tooltips.ts
index ebb6c5adc85..2000f22249d 100644
--- a/web/src/compose_tooltips.ts
+++ b/web/src/compose_tooltips.ts
@@ -313,7 +313,8 @@ export function initialize(): void {
} else if (
_.isEqual(narrow_filter.sorted_term_types(), ["channel"]) &&
compose_state.get_message_type() === "stream" &&
- narrow_filter.operands("channel")[0] === compose_state.stream_name()
+ narrow_filter.terms_with_operator("channel")[0]!.operand ===
+ compose_state.stream_name()
) {
display_current_view = $t({
defaultMessage: "Currently viewing the entire channel.",
diff --git a/web/src/filter.ts b/web/src/filter.ts
index f8888ac91bd..aac06f143b7 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -1022,10 +1022,8 @@ export class Filter {
return safe_to_return;
}
- operands(operator: string): string[] {
- return this._terms
- .filter((term) => !term.negated && term.operator === operator)
- .map((term) => term.operand);
+ terms_with_operator(operator: NarrowCanonicalOperator): NarrowTerm[] {
+ return this._terms.filter((term) => !term.negated && term.operator === operator);
}
has_negated_operand(operator: string, operand: string): boolean {
@@ -1240,7 +1238,7 @@ export class Filter {
}
if (
_.isEqual(term_types, ["sender", "has-reaction"]) &&
- this.operands("sender")[0] === people.my_current_email()
+ this.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
return true;
}
@@ -1260,12 +1258,14 @@ export class Filter {
// this comes first because it has 3 term_types but is not a "complex filter"
if (
_.isEqual(term_types, ["sender", "search", "has-reaction"]) &&
- this.operands("sender")[0] === people.my_current_email()
+ this.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
return "/#narrow/has/reaction/sender/me";
}
if (_.isEqual(term_types, ["channel", "topic", "search"])) {
- const sub = stream_data.get_sub_by_id_string(this.operands("channel")[0]!);
+ const sub = stream_data.get_sub_by_id_string(
+ this.terms_with_operator("channel")[0]!.operand,
+ );
// if channel does not exist, redirect to home view
if (!sub) {
return "#";
@@ -1273,7 +1273,7 @@ export class Filter {
return `/${internal_url.by_stream_topic_url(
sub.stream_id,
- this.operands("topic")[0]!,
+ this.terms_with_operator("topic")[0]!.operand,
sub_store.maybe_get_stream_name,
)}`;
}
@@ -1286,7 +1286,9 @@ export class Filter {
if (term_types[1] === "search") {
switch (term_types[0]) {
case "channel": {
- const sub = stream_data.get_sub_by_id_string(this.operands("channel")[0]!);
+ const sub = stream_data.get_sub_by_id_string(
+ this.terms_with_operator("channel")[0]!.operand,
+ );
// if channel does not exist, redirect to home view
if (!sub) {
return "#";
@@ -1307,7 +1309,14 @@ export class Filter {
case "channels-web-public":
return "/#narrow/channels/web-public";
case "dm":
- return "/#narrow/dm/" + people.emails_to_slug(this.operands("dm").join(","));
+ return (
+ "/#narrow/dm/" +
+ people.emails_to_slug(
+ this.terms_with_operator("dm")
+ .map((term) => term.operand)
+ .join(","),
+ )
+ );
case "is-resolved":
return "/#narrow/topics/is/resolved";
case "is-followed":
@@ -1315,7 +1324,10 @@ export class Filter {
// TODO: It is ambiguous how we want to handle the 'sender' case,
// we may remove it in the future based on design decisions
case "sender":
- return "/#narrow/sender/" + people.emails_to_slug(this.operands("sender")[0]!);
+ return (
+ "/#narrow/sender/" +
+ people.emails_to_slug(this.terms_with_operator("sender")[0]!.operand)
+ );
}
}
@@ -1336,7 +1348,7 @@ export class Filter {
if (
_.isEqual(term_types, ["sender", "has-reaction"]) &&
- this.operands("sender")[0] === people.my_current_email()
+ this.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
zulip_icon = "smile";
return {...context, zulip_icon};
@@ -1348,7 +1360,9 @@ export class Filter {
icon = "home";
break;
case "channel": {
- const sub = stream_data.get_sub_by_id_string(this.operands("channel")[0]!);
+ const sub = stream_data.get_sub_by_id_string(
+ this.terms_with_operator("channel")[0]!.operand,
+ );
if (!sub) {
icon = "question-circle-o";
break;
@@ -1405,7 +1419,9 @@ export class Filter {
(term_types.length === 2 && _.isEqual(term_types, ["channel", "topic"])) ||
(term_types.length === 1 && _.isEqual(term_types, ["channel"]))
) {
- const sub = stream_data.get_sub_by_id_string(this.operands("channel")[0]!);
+ const sub = stream_data.get_sub_by_id_string(
+ this.terms_with_operator("channel")[0]!.operand,
+ );
if (!sub) {
return $t({defaultMessage: "Unknown channel"});
}
@@ -1416,7 +1432,7 @@ export class Filter {
(term_types.length === 2 && _.isEqual(term_types, ["dm", "with"])) ||
(term_types.length === 1 && _.isEqual(term_types, ["dm"]))
) {
- const emails = this.operands("dm")[0]!.split(",");
+ const emails = this.terms_with_operator("dm")[0]!.operand.split(",");
if (emails.length === 1) {
const user = people.get_by_email(emails[0]!);
if (user && people.is_direct_message_conversation_with_self([user.user_id])) {
@@ -1444,7 +1460,7 @@ export class Filter {
return util.format_array_as_list(names, "long", "conjunction");
}
if (term_types.length === 1 && _.isEqual(term_types, ["sender"])) {
- const email = this.operands("sender")[0]!;
+ const email = this.terms_with_operator("sender")[0]!.operand;
const user = people.get_by_email(email);
if (user === undefined) {
return $t({defaultMessage: "Messages sent by unknown user"});
@@ -1501,7 +1517,7 @@ export class Filter {
}
if (
_.isEqual(term_types, ["sender", "has-reaction"]) &&
- this.operands("sender")[0] === people.my_current_email()
+ this.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
return $t({defaultMessage: "Reactions"});
}
@@ -1534,7 +1550,7 @@ export class Filter {
}
if (
_.isEqual(term_types, ["sender", "has-reaction"]) &&
- this.operands("sender")[0] === people.my_current_email()
+ this.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
return {
description: $t({
@@ -1555,7 +1571,7 @@ export class Filter {
contains_only_private_messages(): boolean {
return (
- (this.has_operator("is") && this.operands("is")[0] === "dm") ||
+ (this.has_operator("is") && this.terms_with_operator("is")[0]!.operand === "dm") ||
this.has_operator("dm") ||
this.has_operator("dm-including")
);
@@ -1826,7 +1842,7 @@ export class Filter {
}
if (!message) {
- const message_id = Number.parseInt(this.operands("with")[0]!, 10);
+ const message_id = Number.parseInt(this.terms_with_operator("with")[0]!.operand, 10);
message = message_store.get(message_id);
}
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts
index 727898fd1c3..46ac953dec2 100644
--- a/web/src/inbox_ui.ts
+++ b/web/src/inbox_ui.ts
@@ -318,8 +318,7 @@ export function show(filter?: Filter): void {
const is_new_filter_channel_view = filter?.is_channel_view();
if (was_inbox_channel_view && is_new_filter_channel_view) {
assert(filter !== undefined);
- const filter_channel_id_string = filter.operands("channel")[0];
- assert(filter_channel_id_string !== undefined);
+ const filter_channel_id_string = filter.terms_with_operator("channel")[0]!.operator;
const filter_channel_id = Number.parseInt(filter_channel_id_string, 10);
if (inbox_util.get_channel_id() === filter_channel_id) {
diff --git a/web/src/inbox_util.ts b/web/src/inbox_util.ts
index b31262bd40a..d2d8152c432 100644
--- a/web/src/inbox_util.ts
+++ b/web/src/inbox_util.ts
@@ -27,8 +27,7 @@ export function current_filter(): Filter | undefined {
export function get_channel_id(): number {
assert(filter !== undefined);
- const narrow_channel_stream_id_string = filter.operands("channel")[0];
- assert(narrow_channel_stream_id_string !== undefined);
+ const narrow_channel_stream_id_string = filter.terms_with_operator("channel")[0]!.operator;
return Number.parseInt(narrow_channel_stream_id_string, 10);
}
diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.ts
index eabe1b6ba12..4638b40ce70 100644
--- a/web/src/left_sidebar_navigation_area.ts
+++ b/web/src/left_sidebar_navigation_area.ts
@@ -11,6 +11,7 @@ import * as people from "./people.ts";
import * as resize from "./resize.ts";
import * as scheduled_messages from "./scheduled_messages.ts";
import * as settings_config from "./settings_config.ts";
+import type {NarrowTerm} from "./state_data.ts";
import * as ui_util from "./ui_util.ts";
import * as unread from "./unread.ts";
@@ -107,21 +108,21 @@ export function rewire_select_top_left_corner_item(
}
export function handle_narrow_activated(filter: Filter): void {
- let ops: string[];
+ let terms: NarrowTerm[];
let filter_name: string;
// TODO: handle confused filters like "in:all stream:foo"
- ops = filter.operands("in");
- if (ops[0] !== undefined) {
- filter_name = ops[0];
+ terms = filter.terms_with_operator("in");
+ if (terms[0] !== undefined) {
+ filter_name = terms[0].operand;
if (filter_name === "home") {
highlight_all_messages_view();
return;
}
}
- ops = filter.operands("is");
- if (ops[0] !== undefined) {
- filter_name = ops[0];
+ terms = filter.terms_with_operator("is");
+ if (terms[0] !== undefined) {
+ filter_name = terms[0].operand;
if (filter_name === "starred") {
select_top_left_corner_item(".top_left_starred_messages");
return;
@@ -133,7 +134,7 @@ export function handle_narrow_activated(filter: Filter): void {
const term_types = filter.sorted_term_types();
if (
_.isEqual(term_types, ["sender", "has-reaction"]) &&
- filter.operands("sender")[0] === people.my_current_email()
+ filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
select_top_left_corner_item(".top_left_my_reactions");
return;
diff --git a/web/src/message_feed_top_notices.ts b/web/src/message_feed_top_notices.ts
index c8f8bfa342a..68f2b6daef2 100644
--- a/web/src/message_feed_top_notices.ts
+++ b/web/src/message_feed_top_notices.ts
@@ -59,7 +59,7 @@ export function update_top_of_narrow_notices(msg_list: MessageList): void {
!filter.is_personal_filter() &&
!(
_.isEqual(filter._sorted_term_types, ["sender", "has-reaction"]) &&
- filter.operands("sender")[0] === people.my_current_email()
+ filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()
)
) {
show_end_of_results_notice();
diff --git a/web/src/message_util.ts b/web/src/message_util.ts
index c6ad2b33f2a..2b57235dd5e 100644
--- a/web/src/message_util.ts
+++ b/web/src/message_util.ts
@@ -91,7 +91,8 @@ export function get_direct_message_permission_hints(
// If not, we need to check if the current filter matches the DM view we
// are composing to.
- const dm_conversation = message_lists.current?.data?.filter.operands("dm")[0];
+ const dm_conversation =
+ message_lists.current?.data?.filter.terms_with_operator("dm")[0]?.operand;
if (dm_conversation) {
const current_user_ids_string = people.emails_strings_to_user_ids_string(dm_conversation);
assert(current_user_ids_string !== undefined);
diff --git a/web/src/message_view.ts b/web/src/message_view.ts
index 3535c6bf0ef..5fc1f1dfcb6 100644
--- a/web/src/message_view.ts
+++ b/web/src/message_view.ts
@@ -313,7 +313,7 @@ export function try_rendering_locally_for_same_narrow(
target_id = opts.then_select_id;
target_scroll_offset = opts.then_select_offset;
} else if (filter.has_operator("near")) {
- target_id = Number.parseInt(filter.operands("near")[0]!, 10);
+ target_id = Number.parseInt(filter.terms_with_operator("near")[0]!.operand, 10);
} else if (filter.equals(current_filter)) {
// The caller doesn't want to force rerender and the filter is the same.
// Also, we don't have a specific message id we want to select, so we
@@ -485,10 +485,10 @@ export let show = (raw_terms: NarrowTerm[], show_opts: ShowMessageViewOpts): voi
// These two narrowing operators specify what message should be
// selected and should be the center of the narrow.
if (filter.has_operator("near")) {
- id_info.target_id = Number.parseInt(filter.operands("near")[0]!, 10);
+ id_info.target_id = Number.parseInt(filter.terms_with_operator("near")[0]!.operand, 10);
}
if (filter.has_operator("id")) {
- id_info.target_id = Number.parseInt(filter.operands("id")[0]!, 10);
+ id_info.target_id = Number.parseInt(filter.terms_with_operator("near")[0]!.operand, 10);
}
if (
@@ -502,7 +502,7 @@ export let show = (raw_terms: NarrowTerm[], show_opts: ShowMessageViewOpts): voi
// from server first and then try to select `then_select_id` message.
// There is no risk of this hack causing any issues since the `id_info`
// will be reset after we fetch the `with` operator message.
- id_info.target_id = Number.parseInt(filter.operands("with")[0]!, 10);
+ id_info.target_id = Number.parseInt(filter.terms_with_operator("with")[0]!.operand, 10);
}
// Narrow with near / id operator. There are two possibilities:
@@ -524,9 +524,9 @@ export let show = (raw_terms: NarrowTerm[], show_opts: ShowMessageViewOpts): voi
// the stream/topic pair that was requested to some other
// location, then we should retarget this narrow operation
// to where the message is located now.
- const narrow_topic = filter.operands("topic")[0]!;
+ const narrow_topic = filter.terms_with_operator("topic")[0]!.operand;
const narrow_stream_data = stream_data.get_sub_by_id_string(
- filter.operands("channel")[0]!,
+ filter.terms_with_operator("channel")[0]!.operand,
);
if (!narrow_stream_data) {
// The stream id is invalid or incorrect in the URL.
diff --git a/web/src/message_view_header.ts b/web/src/message_view_header.ts
index 85ba6bf5648..2b2e77546a7 100644
--- a/web/src/message_view_header.ts
+++ b/web/src/message_view_header.ts
@@ -102,7 +102,9 @@ function get_message_view_header_context(filter: Filter | undefined): MessageVie
});
if (filter.has_operator("channel")) {
- const current_stream = stream_data.get_sub_by_id_string(filter.operands("channel")[0]!);
+ const current_stream = stream_data.get_sub_by_id_string(
+ filter.terms_with_operator("channel")[0]!.operand,
+ );
if (!current_stream) {
return {
...context,
diff --git a/web/src/narrow_banner.ts b/web/src/narrow_banner.ts
index 88ba97bf2fe..e32bfc637ef 100644
--- a/web/src/narrow_banner.ts
+++ b/web/src/narrow_banner.ts
@@ -82,8 +82,8 @@ const MUTED_TOPICS_IN_CHANNEL_EMPTY_BANNER = {
const NO_SEARCH_RESULTS_TITLE = $t({defaultMessage: "No search results."});
function empty_search_query_banner(current_filter: Filter): NarrowBannerData {
- const search_query = current_filter.operands("search")[0];
- const query_words = search_query!.split(" ");
+ const search_query = current_filter.terms_with_operator("search")[0]!.operand;
+ const query_words = search_query.split(" ");
const search_string_result: SearchData = {
query_words: [],
@@ -163,8 +163,8 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
if (num_terms !== 1) {
// For invalid-multi-operator narrows, we display an invalid narrow message
- const streams = current_filter.operands("channel");
- const topics = current_filter.operands("topic");
+ const streams = current_filter.terms_with_operator("channel");
+ const topics = current_filter.terms_with_operator("topic");
// No message can have multiple streams
if (streams.length > 1) {
@@ -187,7 +187,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
};
}
// No message can have multiple senders
- if (current_filter.operands("sender").length > 1) {
+ if (current_filter.terms_with_operator("sender").length > 1) {
return {
title: NO_SEARCH_RESULTS_TITLE,
html: $t_html({
@@ -198,7 +198,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
}
// For empty search queries, we display excluded stop words
- if (current_filter.operands("search").length > 0) {
+ if (current_filter.terms_with_operator("search").length > 0) {
return empty_search_query_banner(current_filter);
}
@@ -214,7 +214,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
if (streams.length === 1) {
const stream_sub = stream_data.get_sub_by_id_string(
- util.the(current_filter.operands("channel")),
+ util.the(current_filter.terms_with_operator("channel")).operand,
);
if (!stream_sub) {
return {
@@ -233,7 +233,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
if (
_.isEqual(current_terms_types, ["sender", "has-reaction"]) &&
- current_filter.operands("sender")[0] === people.my_current_email()
+ current_filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()
) {
return {
title: $t({defaultMessage: "None of your messages have emoji reactions yet."}),
diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.ts
index a44f9b363f1..e0770897a75 100644
--- a/web/src/narrow_state.ts
+++ b/web/src/narrow_state.ts
@@ -147,11 +147,14 @@ export let stream_id = (
if (current_filter === undefined) {
return undefined;
}
- const stream_operands = current_filter.operands("channel");
- if (stream_operands.length === 1 && stream_operands[0] !== undefined) {
- const id = Number.parseInt(stream_operands[0], 10);
- if (!Number.isNaN(id)) {
- return only_valid_id ? stream_data.get_sub_by_id(id)?.stream_id : id;
+ const channel_terms = current_filter.terms_with_operator("channel");
+ if (channel_terms.length === 1) {
+ const channel_operand = channel_terms[0]?.operand;
+ if (channel_operand !== undefined) {
+ const id = Number.parseInt(channel_operand, 10);
+ if (!Number.isNaN(id)) {
+ return only_valid_id ? stream_data.get_sub_by_id(id)?.stream_id : id;
+ }
}
}
return undefined;
@@ -183,9 +186,9 @@ export function topic(current_filter: Filter | undefined = filter()): string | u
if (current_filter === undefined) {
return undefined;
}
- const operands = current_filter.operands("topic");
- if (operands.length === 1) {
- return operands[0];
+ const terms = current_filter.terms_with_operator("topic");
+ if (terms.length === 1) {
+ return terms[0]!.operand;
}
return undefined;
}
@@ -195,8 +198,8 @@ export function pm_ids_string(current_filter: Filter | undefined = filter()): st
return undefined;
}
- const operands = current_filter.operands("dm");
- if (operands.length !== 1) {
+ const terms = current_filter.terms_with_operator("dm");
+ if (terms.length !== 1) {
return undefined;
}
@@ -204,7 +207,7 @@ export function pm_ids_string(current_filter: Filter | undefined = filter()): st
// this will return "4,5,99". Will return undefined when the value of the
// operand string does not translate to a comma-separated list of valid
// user emails.
- const emails_string = util.the(operands);
+ const emails_string = util.the(terms).operand;
return people.reply_to_to_user_ids_string(emails_string);
}
@@ -364,8 +367,8 @@ export function narrowed_by_topic_reply(current_filter: Filter | undefined = fil
const terms = current_filter.terms().filter((term) => term.operator !== "with");
return (
terms.length === 2 &&
- current_filter.operands("channel").length === 1 &&
- current_filter.operands("topic").length === 1
+ current_filter.terms_with_operator("channel").length === 1 &&
+ current_filter.terms_with_operator("topic").length === 1
);
}
@@ -381,7 +384,7 @@ export function narrowed_by_stream_reply(current_filter: Filter | undefined = fi
return false;
}
const terms = current_filter.terms();
- return terms.length === 1 && current_filter.operands("channel").length === 1;
+ return terms.length === 1 && current_filter.terms_with_operator("channel").length === 1;
}
export function narrowed_to_stream_id(stream_id_to_check: number, filter?: Filter): boolean {
diff --git a/web/src/narrow_title.ts b/web/src/narrow_title.ts
index 74a0e39fcf0..d1bd494711b 100644
--- a/web/src/narrow_title.ts
+++ b/web/src/narrow_title.ts
@@ -35,7 +35,9 @@ export function compute_narrow_title(filter?: Filter): string {
}
if (filter.has_operator("channel")) {
- const sub = stream_data.get_sub_by_id_string(filter.operands("channel")[0]!);
+ const sub = stream_data.get_sub_by_id_string(
+ filter.terms_with_operator("channel")[0]!.operand,
+ );
if (!sub) {
// The stream is not set because it does not currently
// exist, or it is a private stream and the user is not
@@ -43,14 +45,14 @@ export function compute_narrow_title(filter?: Filter): string {
return filter_title;
}
if (filter.has_operator("topic")) {
- const topic_name = filter.operands("topic")[0];
+ const topic_name = filter.terms_with_operator("topic")[0]!.operand;
return "#" + filter_title + " > " + topic_name;
}
return "#" + filter_title;
}
if (filter.has_operator("dm")) {
- const emails = filter.operands("dm")[0]!;
+ const emails = filter.terms_with_operator("dm")[0]!.operand;
const user_ids = people.emails_strings_to_user_ids_string(emails);
if (user_ids !== undefined) {
diff --git a/web/src/pm_list.ts b/web/src/pm_list.ts
index 6b9bd025c55..60805c96ba5 100644
--- a/web/src/pm_list.ts
+++ b/web/src/pm_list.ts
@@ -204,7 +204,7 @@ function scroll_all_private_into_view(): void {
export function handle_narrow_activated(filter: Filter): void {
const active_filter = filter;
const is_all_private_message_view = _.isEqual(active_filter.sorted_term_types(), ["is-dm"]);
- const narrow_to_private_messages_section = active_filter.operands("dm").length > 0;
+ const narrow_to_private_messages_section = active_filter.terms_with_operator("dm").length > 0;
const is_private_messages_in_view = active_filter.has_operator("dm");
if (is_all_private_message_view) {
diff --git a/web/src/pm_list_data.ts b/web/src/pm_list_data.ts
index 53bb15106c9..2eb50d63e3f 100644
--- a/web/src/pm_list_data.ts
+++ b/web/src/pm_list_data.ts
@@ -20,7 +20,7 @@ export function get_active_user_ids_string(): string | undefined {
return undefined;
}
- const emails = filter.operands("dm")[0];
+ const emails = filter.terms_with_operator("dm")[0]?.operand;
if (!emails) {
return undefined;
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 920180170d0..676bb7610ca 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -522,7 +522,7 @@ function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestio
case "search":
guess = operand;
if (filter.has_operator("channel")) {
- channel_id = filter.operands("channel")[0];
+ channel_id = filter.terms_with_operator("channel")[0]!.operand;
} else {
channel_id = narrow_state.stream_id()?.toString();
if (channel_id) {
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 9876ebb958a..2cc3c7c8e4d 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -1044,12 +1044,12 @@ export function get_sidebar_stream_topic_info(filter: Filter): {
topic_selected: false,
};
- const op_stream = filter.operands("channel");
- if (op_stream[0] === undefined) {
+ const channel_terms = filter.terms_with_operator("channel");
+ if (channel_terms.length === 0) {
return result;
}
- const stream_id = Number.parseInt(op_stream[0], 10);
+ const stream_id = Number.parseInt(channel_terms[0]!.operand, 10);
if (!stream_id) {
return result;
@@ -1061,8 +1061,8 @@ export function get_sidebar_stream_topic_info(filter: Filter): {
result.stream_id = stream_id;
- const op_topic = filter.operands("topic");
- result.topic_selected = op_topic.length === 1;
+ const topic_terms = filter.terms_with_operator("topic");
+ result.topic_selected = topic_terms.length === 1;
return result;
}
diff --git a/web/src/typing_events.ts b/web/src/typing_events.ts
index 976188d29da..65f2358fe01 100644
--- a/web/src/typing_events.ts
+++ b/web/src/typing_events.ts
@@ -94,7 +94,7 @@ function get_users_typing_for_narrow(): number[] {
const current_filter = narrow_state.filter()!;
if (current_filter.has_operator("dm")) {
// Get list of users typing in this conversation
- const narrow_emails_string = current_filter.operands("dm")[0]!;
+ const narrow_emails_string = current_filter.terms_with_operator("dm")[0]!.operand;
if (!people.is_valid_bulk_emails_for_compose(narrow_emails_string.split(","))) {
// Narrowed to an invalid direct message recipient.
return [];
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 1c81bf14410..5884b1a865c 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -138,7 +138,10 @@ test("basics", () => {
let filter = new Filter(terms);
assert_same_terms(filter.terms(), terms);
- assert.deepEqual(filter.operands("channel"), [foo_stream_id.toString()]);
+ let channel_terms = filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: foo_stream_id.toString(), negated: false},
+ ]);
assert.ok(filter.has_operator("channel"));
assert.ok(!filter.has_operator("search"));
@@ -168,7 +171,10 @@ test("basics", () => {
terms = [{operator: "stream", operand: foo_stream_id.toString()}];
filter = new Filter(terms);
assert.ok(filter.has_operator("channel"));
- assert.deepEqual(filter.operands("channel"), [foo_stream_id.toString()]);
+ channel_terms = filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: foo_stream_id.toString(), negated: false},
+ ]);
assert.ok(filter.includes_full_stream_history());
assert.ok(filter.can_apply_locally());
assert.ok(filter.can_show_next_unread_topic_conversation_button());
@@ -182,7 +188,10 @@ test("basics", () => {
];
filter = new Filter(terms);
- assert.deepEqual(filter.operands("channel"), [foo_stream_id.toString()]);
+ channel_terms = filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: foo_stream_id.toString(), negated: false},
+ ]);
assert.ok(filter.has_operator("channel"));
assert.ok(!filter.has_operator("search"));
@@ -884,8 +893,12 @@ test("filter_with_new_params_topic", () => {
operand: "new topic",
});
- assert.deepEqual(new_filter.operands("channel"), [foo_stream_id.toString()]);
- assert.deepEqual(new_filter.operands("topic"), ["new topic"]);
+ const channel_terms = new_filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: foo_stream_id.toString(), negated: false},
+ ]);
+ const topic_terms = new_filter.terms_with_operator("topic");
+ assert.deepEqual(topic_terms, [{operator: "topic", operand: "new topic", negated: false}]);
});
test("filter_with_new_params_channel", () => {
@@ -904,8 +917,12 @@ test("filter_with_new_params_channel", () => {
operand: "new channel",
});
- assert.deepEqual(new_filter.operands("channel"), ["new channel"]);
- assert.deepEqual(new_filter.operands("topic"), ["old topic"]);
+ const channel_terms = new_filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: "new channel", negated: false},
+ ]);
+ const topic_terms = new_filter.terms_with_operator("topic");
+ assert.deepEqual(topic_terms, [{operator: "topic", operand: "old topic", negated: false}]);
});
test("new_style_terms", () => {
@@ -916,7 +933,10 @@ test("new_style_terms", () => {
const terms = [term];
const filter = new Filter(terms);
- assert.deepEqual(filter.operands("channel"), [foo_stream_id.toString()]);
+ const channel_terms = filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: foo_stream_id.toString(), negated: false},
+ ]);
assert.ok(filter.can_bucket_by("channel"));
});
@@ -2102,9 +2122,17 @@ test("update_email", () => {
];
const filter = new Filter(terms);
filter.update_email(steve.user_id, "[email protected]");
- assert.deepEqual(filter.operands("dm"), ["[email protected]"]);
- assert.deepEqual(filter.operands("sender"), ["[email protected]"]);
- assert.deepEqual(filter.operands("channel"), ["[email protected]"]);
+
+ const dm_terms = filter.terms_with_operator("dm");
+ assert.deepEqual(dm_terms, [{operator: "dm", operand: "[email protected]", negated: false}]);
+ const sender_terms = filter.terms_with_operator("sender");
+ assert.deepEqual(sender_terms, [
+ {operator: "sender", operand: "[email protected]", negated: false},
+ ]);
+ const channel_terms = filter.terms_with_operator("channel");
+ assert.deepEqual(channel_terms, [
+ {operator: "channel", operand: "[email protected]", negated: false},
+ ]);
});
test("try_adjusting_for_moved_with_target", ({override}) => {
diff --git a/web/tests/narrow_state.test.cjs b/web/tests/narrow_state.test.cjs
index 9f53c49a411..753bc882c48 100644
--- a/web/tests/narrow_state.test.cjs
+++ b/web/tests/narrow_state.test.cjs
@@ -274,9 +274,9 @@ test("update_email", () => {
]);
narrow_state.update_email(steve.user_id, "[email protected]");
const filter = narrow_state.filter();
- assert.deepEqual(filter.operands("dm"), ["[email protected]"]);
- assert.deepEqual(filter.operands("sender"), ["[email protected]"]);
- assert.deepEqual(filter.operands("channel"), ["[email protected]"]);
+ assert.deepEqual(filter.terms_with_operator("dm")[0].operand, "[email protected]");
+ assert.deepEqual(filter.terms_with_operator("sender")[0].operand, "[email protected]");
+ assert.deepEqual(filter.terms_with_operator("channel")[0].operand, "[email protected]");
});
test("topic", () => {