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: Use terms instead of operands.

evykassirera87b1d5ad873
diff --git a/web/src/compose_reply.js b/web/src/compose_reply.js
index b3fb94041ed..87fe7b051c1 100644
--- a/web/src/compose_reply.js
+++ b/web/src/compose_reply.js
@@ -56,7 +56,7 @@ export function respond_to_message(opts) {
return;
}
const current_filter = narrow_state.filter();
- const first_term = current_filter.operators()[0];
+ const first_term = current_filter.terms()[0];
const first_operator = first_term.operator;
const first_operand = first_term.operand;
diff --git a/web/src/filter.ts b/web/src/filter.ts
index e6ed35bba63..369491beea7 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -240,18 +240,18 @@ export type Term = {
};
export class Filter {
- _operators: Term[];
+ _terms: Term[];
_sub?: StreamSubscription;
_sorted_term_types?: string[] = undefined;
_predicate?: (message: Message) => boolean;
_can_mark_messages_read?: boolean;
- constructor(operators?: Term[]) {
- if (operators === undefined) {
- this._operators = [];
+ constructor(terms?: Term[]) {
+ if (terms === undefined) {
+ this._terms = [];
this._sub = undefined;
} else {
- this._operators = this.fix_operators(operators);
+ this._terms = this.fix_terms(terms);
if (this.has_operator("stream")) {
this._sub = stream_data.get_sub_by_name(this.operands("stream")[0]);
}
@@ -361,9 +361,9 @@ export class Filter {
return util.robust_url_decode(encoded).trim();
}
- // Parse a string into a list of operators (see below).
+ // Parse a string into a list of terms (see below).
static parse(str: string): Term[] {
- const operators: Term[] = [];
+ const terms: Term[] = [];
let search_term: string[] = [];
let negated;
let operator;
@@ -375,7 +375,7 @@ export class Filter {
operator = "search";
const _operand = search_term.join(" ");
term = {operator, operand: _operand, negated: false};
- operators.push(term);
+ terms.push(term);
search_term = [];
}
}
@@ -387,7 +387,7 @@ export class Filter {
// parser with `.split`.
const matches = str.match(/([^\s:]+: ?)?("[^"]+"?|\S+)/g);
if (matches === null) {
- return operators;
+ return terms;
}
for (const token of matches) {
@@ -419,16 +419,16 @@ export class Filter {
}
// If any search query was present and it is followed by some other filters
// then we must add that search filter in its current position in the
- // operators list. This is done so that the last active filter is correctly
+ // terms list. This is done so that the last active filter is correctly
// detected by the `get_search_result` function (in search_suggestions.js).
maybe_add_search_terms();
term = {negated, operator, operand};
- operators.push(term);
+ terms.push(term);
}
}
maybe_add_search_terms();
- return operators;
+ return terms;
}
/* Convert a list of search terms to a string.
@@ -440,20 +440,20 @@ export class Filter {
might need to support multiple terms of the same type.
*/
static unparse(search_terms: Term[]): string {
- const parts = search_terms.map((elem) => {
- if (elem.operator === "search") {
+ const term_strings = search_terms.map((term) => {
+ if (term.operator === "search") {
// Search terms are the catch-all case.
// All tokens that don't start with a known operator and
// a colon are glued together to form a search term.
- return elem.operand;
+ return term.operand;
}
- const sign = elem.negated ? "-" : "";
- if (elem.operator === "") {
- return elem.operand;
+ const sign = term.negated ? "-" : "";
+ if (term.operator === "") {
+ return term.operand;
}
- return sign + elem.operator + ":" + Filter.encodeOperand(elem.operand.toString());
+ return sign + term.operator + ":" + Filter.encodeOperand(term.operand.toString());
});
- return parts.join(" ");
+ return term_strings.join(" ");
}
static term_type(term: Term): string {
@@ -560,36 +560,36 @@ export class Filter {
return "";
}
- // Convert a list of operators to a human-readable description.
- static parts_for_describe(operators: Term[]): Part[] {
+ // Convert a list of terms to a human-readable description.
+ static parts_for_describe(terms: Term[]): Part[] {
const parts: Part[] = [];
- if (operators.length === 0) {
+ if (terms.length === 0) {
parts.push({type: "plain_text", content: "all messages"});
return parts;
}
- if (operators.length >= 2) {
+ if (terms.length >= 2) {
const is = (term: Term, expected: string): boolean =>
term.operator === expected && !term.negated;
- if (is(operators[0], "stream") && is(operators[1], "topic")) {
- const stream = operators[0].operand;
- const topic = operators[1].operand;
+ if (is(terms[0], "stream") && is(terms[1], "topic")) {
+ const stream = terms[0].operand;
+ const topic = terms[1].operand;
parts.push({
type: "stream_topic",
stream,
topic,
});
- operators = operators.slice(2);
+ terms = terms.slice(2);
}
}
- const more_parts = operators.map((elem): Part => {
- const operand = elem.operand;
- const canonicalized_operator = Filter.canonicalize_operator(elem.operator);
+ const more_parts = terms.map((term): Part => {
+ const operand = term.operand;
+ const canonicalized_operator = Filter.canonicalize_operator(term.operator);
if (canonicalized_operator === "is") {
- const verb = elem.negated ? "exclude " : "";
+ const verb = term.negated ? "exclude " : "";
return {
type: "is_operator",
verb,
@@ -616,7 +616,7 @@ export class Filter {
}
const prefix_for_operator = Filter.operator_to_prefix(
canonicalized_operator,
- elem.negated,
+ term.negated,
);
if (prefix_for_operator !== "") {
return {
@@ -633,18 +633,18 @@ export class Filter {
return [...parts, ...more_parts];
}
- static search_description_as_html(operators: Term[]): string {
+ static search_description_as_html(terms: Term[]): string {
return render_search_description({
- parts: Filter.parts_for_describe(operators),
+ parts: Filter.parts_for_describe(terms),
});
}
- static is_spectator_compatible(ops: Term[]): boolean {
- for (const op of ops) {
- if (op.operand === undefined) {
+ static is_spectator_compatible(terms: Term[]): boolean {
+ for (const term of terms) {
+ if (term.operand === undefined) {
return false;
}
- if (!hash_parser.allowed_web_public_narrows.includes(op.operator)) {
+ if (!hash_parser.allowed_web_public_narrows.includes(term.operator)) {
return false;
}
}
@@ -658,47 +658,47 @@ export class Filter {
return this._predicate;
}
- operators(): Term[] {
- return this._operators;
+ terms(): Term[] {
+ return this._terms;
}
- public_operators(): Term[] {
- const safe_to_return = this._operators.filter(
+ public_terms(): Term[] {
+ const safe_to_return = this._terms.filter(
// Filter out the embedded narrow (if any).
- (value) =>
+ (term) =>
!(
page_params.narrow_stream !== undefined &&
- value.operator === "stream" &&
- value.operand.toLowerCase() === page_params.narrow_stream.toLowerCase()
+ term.operator === "stream" &&
+ term.operand.toLowerCase() === page_params.narrow_stream.toLowerCase()
),
);
return safe_to_return;
}
operands(operator: string): string[] {
- return this._operators
- .filter((elem) => !elem.negated && elem.operator === operator)
- .map((elem) => elem.operand);
+ return this._terms
+ .filter((term) => !term.negated && term.operator === operator)
+ .map((term) => term.operand);
}
has_negated_operand(operator: string, operand: string): boolean {
- return this._operators.some(
- (elem) => elem.negated && elem.operator === operator && elem.operand === operand,
+ return this._terms.some(
+ (term) => term.negated && term.operator === operator && term.operand === operand,
);
}
has_operand(operator: string, operand: string): boolean {
- return this._operators.some(
- (elem) => !elem.negated && elem.operator === operator && elem.operand === operand,
+ return this._terms.some(
+ (term) => !term.negated && term.operator === operator && term.operand === operand,
);
}
has_operator(operator: string): boolean {
- return this._operators.some((elem) => {
- if (elem.negated && !["search", "has"].includes(elem.operator)) {
+ return this._terms.some((term) => {
+ if (term.negated && !["search", "has"].includes(term.operator)) {
return false;
}
- return elem.operator === operator;
+ return term.operator === operator;
});
}
@@ -1089,10 +1089,10 @@ export class Filter {
return true;
}
- fix_operators(operators: Term[]): Term[] {
- operators = this._canonicalize_operators(operators);
- operators = this._fix_redundant_is_private(operators);
- return operators;
+ fix_terms(terms: Term[]): Term[] {
+ terms = this._canonicalize_terms(terms);
+ terms = this._fix_redundant_is_private(terms);
+ return terms;
}
_fix_redundant_is_private(terms: Term[]): Term[] {
@@ -1103,12 +1103,12 @@ export class Filter {
return terms.filter((term) => Filter.term_type(term) !== "is-dm");
}
- _canonicalize_operators(operators_mixed_case: Term[]): Term[] {
- return operators_mixed_case.map((tuple: Term) => Filter.canonicalize_term(tuple));
+ _canonicalize_terms(terms_mixed_case: Term[]): Term[] {
+ return terms_mixed_case.map((term: Term) => Filter.canonicalize_term(term));
}
filter_with_new_params(params: Term): Filter {
- const terms = this._operators.map((term) => {
+ const terms = this._terms.map((term) => {
const new_term = {...term};
if (new_term.operator === params.operator && !new_term.negated) {
new_term.operand = params.operand;
@@ -1130,7 +1130,7 @@ export class Filter {
}
_build_sorted_term_types(): string[] {
- const terms = this._operators;
+ const terms = this._terms;
const term_types = terms.map((term) => Filter.term_type(term));
const sorted_terms = Filter.sorted_term_types(term_types);
return sorted_terms;
@@ -1170,7 +1170,7 @@ export class Filter {
}
update_email(user_id: number, new_email: string): void {
- for (const term of this._operators) {
+ for (const term of this._terms) {
switch (term.operator) {
case "dm-including":
case "group-pm-with":
@@ -1189,7 +1189,7 @@ export class Filter {
// Build a filter function from a list of operators.
_build_predicate(): (message: Message) => boolean {
- const operators = this._operators;
+ const terms = this._terms;
if (!this.can_apply_locally()) {
return () => true;
@@ -1200,7 +1200,7 @@ export class Filter {
// build JavaScript code in a string and then eval() it.
return (message: Message) =>
- operators.every((term) => {
+ terms.every((term) => {
let ok = message_matches_search_term(message, term.operator, term.operand);
if (term.negated) {
ok = !ok;
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index da753a1f877..90a52730565 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -7,7 +7,8 @@ import * as sub_store from "./sub_store";
import type {StreamSubscription} from "./sub_store";
import type {UserGroup} from "./user_groups";
-type Operator = {operator: string; operand: string; negated?: boolean};
+// TODO(typescript): Move to filter.js when it's converted to typescript.
+type Term = {operator: string; operand: string; negated?: boolean};
export function build_reload_url(): string {
let hash = window.location.hash;
@@ -79,21 +80,21 @@ export function by_stream_topic_url(stream_id: number, topic: string): string {
return internal_url.by_stream_topic_url(stream_id, topic, sub_store.maybe_get_stream_name);
}
-// Encodes an operator list into the
+// Encodes a term list into the
// corresponding hash: the # component
// of the narrow URL
-export function operators_to_hash(operators?: Operator[]): string {
+export function search_terms_to_hash(terms?: Term[]): string {
let hash = "#";
- if (operators !== undefined) {
+ if (terms !== undefined) {
hash = "#narrow";
- for (const elem of operators) {
+ for (const term of terms) {
// Support legacy tuples.
- const operator = elem.operator;
- const operand = elem.operand;
+ const operator = term.operator;
+ const operand = term.operand;
- const sign = elem.negated ? "-" : "";
+ const sign = term.negated ? "-" : "";
hash +=
"/" +
sign +
@@ -107,7 +108,7 @@ export function operators_to_hash(operators?: Operator[]): string {
}
export function by_sender_url(reply_to: string): string {
- return operators_to_hash([{operator: "sender", operand: reply_to}]);
+ return search_terms_to_hash([{operator: "sender", operand: reply_to}]);
}
export function pm_with_url(reply_to: string): string {
@@ -151,16 +152,16 @@ export function group_edit_url(group: UserGroup): string {
return hash;
}
-export function search_public_streams_notice_url(operators: Operator[]): string {
+export function search_public_streams_notice_url(terms: Term[]): string {
const public_operator = {operator: "streams", operand: "public"};
- return operators_to_hash([public_operator, ...operators]);
+ return search_terms_to_hash([public_operator, ...terms]);
}
-export function parse_narrow(hash: string): Operator[] | undefined {
+export function parse_narrow(hash: string): Term[] | undefined {
// This will throw an exception when passed an invalid hash
// at the decodeHashComponent call, handle appropriately.
let i;
- const operators = [];
+ const terms = [];
for (i = 1; i < hash.length; i += 2) {
// We don't construct URLs with an odd number of components,
// but the user might write one.
@@ -183,7 +184,7 @@ export function parse_narrow(hash: string): Operator[] | undefined {
}
const operand = decode_operand(operator, raw_operand);
- operators.push({negated, operator, operand});
+ terms.push({negated, operator, operand});
}
- return operators;
+ return terms;
}
diff --git a/web/src/hashchange.js b/web/src/hashchange.js
index 7428b083747..791a3e640ed 100644
--- a/web/src/hashchange.js
+++ b/web/src/hashchange.js
@@ -117,10 +117,10 @@ function do_hashchange_normal(from_reload) {
switch (hash[0]) {
case "#narrow": {
- let operators;
+ let terms;
try {
// TODO: Show possible valid URLs to the user.
- operators = hash_util.parse_narrow(hash);
+ terms = hash_util.parse_narrow(hash);
} catch {
ui_report.error(
$t_html({defaultMessage: "Invalid URL"}),
@@ -129,7 +129,7 @@ function do_hashchange_normal(from_reload) {
2000,
);
}
- if (operators === undefined) {
+ if (terms === undefined) {
// If the narrow URL didn't parse,
// send them to web_home_view.
// We cannot clear hash here since
@@ -156,7 +156,7 @@ function do_hashchange_normal(from_reload) {
narrow_opts.then_select_id = location_data_for_hash.narrow_pointer;
narrow_opts.then_select_offset = location_data_for_hash.narrow_offset;
}
- narrow.activate(operators, narrow_opts);
+ narrow.activate(terms, narrow_opts);
return true;
}
case "":
diff --git a/web/src/message_events.js b/web/src/message_events.js
index 5567f1659e6..48b0a85029c 100644
--- a/web/src/message_events.js
+++ b/web/src/message_events.js
@@ -45,7 +45,7 @@ function maybe_add_narrowed_messages(messages, msg_list, callback, attempt = 1)
url: "/json/messages/matches_narrow",
data: {
msg_ids: JSON.stringify(ids),
- narrow: JSON.stringify(narrow_state.public_operators()),
+ narrow: JSON.stringify(narrow_state.public_search_terms()),
},
timeout: 5000,
success(data) {
@@ -421,12 +421,12 @@ export function update_messages(events) {
// with data fetched from the server (which is already updated)
// when we move to new narrow and what data is locally available.
if (changed_narrow) {
- const operators = new_filter.operators();
+ const terms = new_filter.terms();
const opts = {
trigger: "stream/topic change",
then_select_id: current_selected_id,
};
- narrow.activate(operators, opts);
+ narrow.activate(terms, opts);
}
}
diff --git a/web/src/message_feed_top_notices.js b/web/src/message_feed_top_notices.js
index 907428935bc..a3722e14853 100644
--- a/web/src/message_feed_top_notices.js
+++ b/web/src/message_feed_top_notices.js
@@ -25,8 +25,8 @@ function show_end_of_results_notice() {
// Set the link to point to this search with streams:public added.
// Note that element we adjust is not visible to spectators.
- const operators = narrow_state.filter().operators();
- const update_hash = hash_util.search_public_streams_notice_url(operators);
+ const terms = narrow_state.filter().terms();
+ const update_hash = hash_util.search_public_streams_notice_url(terms);
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
}
diff --git a/web/src/message_fetch.js b/web/src/message_fetch.js
index 80ffac10998..9eb6b23317c 100644
--- a/web/src/message_fetch.js
+++ b/web/src/message_fetch.js
@@ -241,7 +241,7 @@ export function load_messages(opts, attempt = 1) {
}
// This block is a hack; structurally, we want to set
- // data.narrow = opts.msg_list.data.filter.public_operators()
+ // data.narrow = opts.msg_list.data.filter.public_terms()
//
// But support for the all_messages_data sharing of data with
// message_lists.home and the (hacky) page_params.narrow feature
@@ -256,11 +256,11 @@ export function load_messages(opts, attempt = 1) {
// streams and topics even though message_lists.home's in:home
// operators will filter those.
} else {
- let operators = msg_list_data.filter.public_operators();
+ let terms = msg_list_data.filter.public_terms();
if (page_params.narrow !== undefined) {
- operators = [...operators, ...page_params.narrow];
+ terms = [...terms, ...page_params.narrow];
}
- data.narrow = JSON.stringify(operators);
+ data.narrow = JSON.stringify(terms);
}
let update_loading_indicator = opts.msg_list === message_lists.current;
diff --git a/web/src/narrow.js b/web/src/narrow.js
index 2afe283850f..74a945ece89 100644
--- a/web/src/narrow.js
+++ b/web/src/narrow.js
@@ -78,15 +78,15 @@ export function changehash(newhash) {
browser_history.set_hash(newhash);
}
-export function save_narrow(operators) {
+export function save_narrow(terms) {
if (browser_history.state.changing_hash) {
return;
}
- const new_hash = hash_util.operators_to_hash(operators);
+ const new_hash = hash_util.search_terms_to_hash(terms);
changehash(new_hash);
}
-export function activate(raw_operators, opts) {
+export function activate(raw_terms, opts) {
/* Main entry point for switching to a new view / message list.
Note that for historical reasons related to the current
client-side caching structure, the "All messages"/message_lists.home
@@ -95,7 +95,7 @@ export function activate(raw_operators, opts) {
The name is based on "narrowing to a subset of the user's
messages.". Supported parameters:
- raw_operators: Narrowing/search operators; used to construct
+ raw_terms: Narrowing/search terms; used to construct
a Filter object that decides which messages belong in the
view. Required (See the above note on how `message_lists.home` works)
@@ -129,10 +129,9 @@ export function activate(raw_operators, opts) {
// we need to check if the narrow is allowed for spectator here too.
if (
page_params.is_spectator &&
- raw_operators.length &&
- raw_operators.some(
- (raw_operator) =>
- !hash_parser.allowed_web_public_narrows.includes(raw_operator.operator),
+ raw_terms.length &&
+ raw_terms.some(
+ (raw_term) => !hash_parser.allowed_web_public_narrows.includes(raw_term.operator),
)
) {
spectators.login_to_access();
@@ -143,9 +142,9 @@ export function activate(raw_operators, opts) {
const coming_from_inbox = inbox_util.is_visible();
// The empty narrow is the home view; so deactivate any narrow if
- // no operators were specified. Take us to all messages when this
+ // no terms were specified. Take us to all messages when this
// happens from Recent Conversations view.
- if (raw_operators.length === 0) {
+ if (raw_terms.length === 0) {
browser_history.go_to_location("#all_messages");
return;
}
@@ -162,7 +161,7 @@ export function activate(raw_operators, opts) {
const span_data = {
op: "function",
description: "narrow",
- data: {was_narrowed_already, raw_operators, trigger: opts.trigger},
+ data: {was_narrowed_already, raw_terms, trigger: opts.trigger},
};
let span;
if (!existing_span) {
@@ -181,8 +180,8 @@ export function activate(raw_operators, opts) {
final_select_id: undefined,
};
- const filter = new Filter(raw_operators);
- const operators = filter.operators();
+ const filter = new Filter(raw_terms);
+ const terms = filter.terms();
// These two narrowing operators specify what message should be
// selected and should be the center of the narrow.
@@ -206,36 +205,36 @@ export function activate(raw_operators, opts) {
if (id_info.target_id && filter.has_operator("stream") && filter.has_operator("topic")) {
const target_message = message_store.get(id_info.target_id);
- function adjusted_operators_if_moved(operators, message) {
- const adjusted_operators = [];
- let operators_changed = false;
+ function adjusted_terms_if_moved(terms, message) {
+ const adjusted_terms = [];
+ let terms_changed = false;
- for (const operator of operators) {
- const adjusted_operator = {...operator};
+ for (const term of terms) {
+ const adjusted_term = {...term};
if (
- operator.operator === "stream" &&
- !util.lower_same(operator.operand, message.display_recipient)
+ term.operator === "stream" &&
+ !util.lower_same(term.operand, message.display_recipient)
) {
- adjusted_operator.operand = message.display_recipient;
- operators_changed = true;
+ adjusted_term.operand = message.display_recipient;
+ terms_changed = true;
}
if (
- operator.operator === "topic" &&
- !util.lower_same(operator.operand, message.topic)
+ term.operator === "topic" &&
+ !util.lower_same(term.operand, message.topic)
) {
- adjusted_operator.operand = message.topic;
- operators_changed = true;
+ adjusted_term.operand = message.topic;
+ terms_changed = true;
}
- adjusted_operators.push(adjusted_operator);
+ adjusted_terms.push(adjusted_term);
}
- if (!operators_changed) {
+ if (!terms_changed) {
return null;
}
- return adjusted_operators;
+ return adjusted_terms;
}
if (target_message) {
@@ -251,17 +250,14 @@ export function activate(raw_operators, opts) {
// The id of the target message is correct but the stream name is
// incorrect in the URL. We reconstruct the narrow with the correct
// stream name and narrow.
- const adjusted_operators = adjusted_operators_if_moved(
- raw_operators,
- target_message,
- );
+ const adjusted_terms = adjusted_terms_if_moved(raw_terms, target_message);
- if (adjusted_operators === null) {
- blueslip.error("adjusted_operators impossibly null");
+ if (adjusted_terms === null) {
+ blueslip.error("adjusted_terms impossibly null");
return;
}
- activate(adjusted_operators, {
+ activate(adjusted_terms, {
...opts,
// Update the URL fragment to reflect the redirect.
change_hash: true,
@@ -291,12 +287,9 @@ export function activate(raw_operators, opts) {
!narrow_matches_target_message &&
(narrow_exists_in_edit_history || !page_params.realm_allow_edit_history)
) {
- const adjusted_operators = adjusted_operators_if_moved(
- raw_operators,
- target_message,
- );
- if (adjusted_operators !== null) {
- activate(adjusted_operators, {
+ const adjusted_terms = adjusted_terms_if_moved(raw_terms, target_message);
+ if (adjusted_terms !== null) {
+ activate(adjusted_terms, {
...opts,
// Update the URL fragment to reflect the redirect.
change_hash: true,
@@ -316,7 +309,7 @@ export function activate(raw_operators, opts) {
// narrow.activate recursively, setting a flag to
// indicate we've already done this.
message_helper.process_new_message(data.message);
- activate(raw_operators, {
+ activate(raw_terms, {
...opts,
fetched_target_message: true,
});
@@ -328,7 +321,7 @@ export function activate(raw_operators, opts) {
// `stream:foo topic:bar near:1` into the search
// box. No special rewriting is required, so call
// narrow.activate recursively.
- activate(raw_operators, {
+ activate(raw_terms, {
fetched_target_message: true,
...opts,
});
@@ -368,7 +361,7 @@ export function activate(raw_operators, opts) {
$(".tooltip").hide();
blueslip.debug("Narrowed", {
- operators: operators.map((e) => e.operator),
+ operators: terms.map((e) => e.operator),
trigger: opts ? opts.trigger : undefined,
previous_id: message_lists.current.selected_id(),
});
@@ -493,11 +486,11 @@ export function activate(raw_operators, opts) {
});
}
- // Put the narrow operators in the URL fragment.
+ // Put the narrow terms in the URL fragment.
// Disabled when the URL fragment was the source
// of this narrow.
if (opts.change_hash) {
- save_narrow(operators);
+ save_narrow(terms);
}
handle_post_view_change(msg_list);
@@ -956,12 +949,12 @@ export function to_compose_target() {
const stream_name = stream_data.get_sub_by_id(stream_id).name;
// If we are composing to a new topic, we narrow to the stream but
// grey-out the message view instead of narrowing to an empty view.
- const operators = [{operator: "stream", operand: stream_name}];
+ const terms = [{operator: "stream", operand: stream_name}];
const topic = compose_state.topic();
if (topic !== "") {
- operators.push({operator: "topic", operand: topic});
+ terms.push({operator: "topic", operand: topic});
}
- activate(operators, opts);
+ activate(terms, opts);
return;
}
diff --git a/web/src/narrow_banner.js b/web/src/narrow_banner.js
index 05104a9f350..50acf5934bb 100644
--- a/web/src/narrow_banner.js
+++ b/web/src/narrow_banner.js
@@ -92,12 +92,12 @@ function pick_empty_narrow_banner() {
return default_banner;
}
- const first_term = current_filter.operators()[0];
+ const first_term = current_filter.terms()[0];
const first_operator = first_term.operator;
const first_operand = first_term.operand;
- const num_operators = current_filter.operators().length;
+ const num_terms = current_filter.terms().length;
- if (num_operators !== 1) {
+ if (num_terms !== 1) {
// For invalid-multi-operator narrows, we display an invalid narrow message
const streams = current_filter.operands("stream");
const topics = current_filter.operands("topic");
@@ -152,7 +152,7 @@ function pick_empty_narrow_banner() {
}
// A stream > topic that doesn't exist yet.
- if (num_operators === 2 && streams.length === 1 && topics.length === 1) {
+ if (num_terms === 2 && streams.length === 1 && topics.length === 1) {
return default_banner;
}
diff --git a/web/src/narrow_history.ts b/web/src/narrow_history.ts
index d40c93780ee..118f7380339 100644
--- a/web/src/narrow_history.ts
+++ b/web/src/narrow_history.ts
@@ -15,7 +15,7 @@ function _save_narrow_state(): void {
// We don't want to save state in the middle of a narrow change
// to the wrong hash.
const current_filter = message_lists.current.data.filter;
- if (hash_util.operators_to_hash(current_filter.operators()) !== window.location.hash) {
+ if (hash_util.search_terms_to_hash(current_filter.terms()) !== window.location.hash) {
return;
}
diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.ts
index a6803354669..283598018ae 100644
--- a/web/src/narrow_state.ts
+++ b/web/src/narrow_state.ts
@@ -31,11 +31,11 @@ export function filter(): Filter | undefined {
return current_filter;
}
-export function operators(): Term[] {
+export function search_terms(): Term[] {
if (current_filter === undefined) {
- return new Filter(page_params.narrow).operators();
+ return new Filter(page_params.narrow).terms();
}
- return current_filter.operators();
+ return current_filter.terms();
}
export function is_message_feed_visible(): boolean {
@@ -48,30 +48,30 @@ export function update_email(user_id: number, new_email: string): void {
}
}
-/* Operators we should send to the server. */
-export function public_operators(): Term[] | undefined {
+/* Search terms we should send to the server. */
+export function public_search_terms(): Term[] | undefined {
if (current_filter === undefined) {
return undefined;
}
- return current_filter.public_operators();
+ return current_filter.public_terms();
}
export function search_string(): string {
- return Filter.unparse(operators());
+ return Filter.unparse(search_terms());
}
-// Collect operators which appear only once into an object,
+// Collect terms which appear only once into an object,
// and discard those which appear more than once.
-function collect_single(operators: Term[]): Map<string, string> {
+function collect_single(terms: Term[]): Map<string, string> {
const seen = new Map();
const result = new Map();
- for (const elem of operators) {
- const key = elem.operator;
+ for (const term of terms) {
+ const key = term.operator;
if (seen.has(key)) {
result.delete(key);
} else {
- result.set(key, elem.operand);
+ result.set(key, term.operand);
seen.set(key, true);
}
}
@@ -84,14 +84,14 @@ function collect_single(operators: Term[]): Map<string, string> {
//
// This logic is here and not in the 'compose' module because
// it will get more complicated as we add things to the narrow
-// operator language.
+// search term language.
export function set_compose_defaults(): {
stream_id?: number;
topic?: string;
private_message_recipient?: string;
} {
const opts: {stream_id?: number; topic?: string; private_message_recipient?: string} = {};
- const single = collect_single(operators());
+ const single = collect_single(search_terms());
// Set the stream, topic, and/or direct message recipient
// if they are uniquely specified in the narrow view.
@@ -318,17 +318,17 @@ export function narrowed_by_pm_reply(): boolean {
if (current_filter === undefined) {
return false;
}
- const operators = current_filter.operators();
- return operators.length === 1 && current_filter.has_operator("dm");
+ const terms = current_filter.terms();
+ return terms.length === 1 && current_filter.has_operator("dm");
}
export function narrowed_by_topic_reply(): boolean {
if (current_filter === undefined) {
return false;
}
- const operators = current_filter.operators();
+ const terms = current_filter.terms();
return (
- operators.length === 2 &&
+ terms.length === 2 &&
current_filter.operands("stream").length === 1 &&
current_filter.operands("topic").length === 1
);
@@ -345,8 +345,8 @@ export function narrowed_by_stream_reply(): boolean {
if (current_filter === undefined) {
return false;
}
- const operators = current_filter.operators();
- return operators.length === 1 && current_filter.operands("stream").length === 1;
+ const terms = current_filter.terms();
+ return terms.length === 1 && current_filter.operands("stream").length === 1;
}
export function narrowed_to_topic(): boolean {
diff --git a/web/src/search.js b/web/src/search.js
index f817e217f51..242a1a728f4 100644
--- a/web/src/search.js
+++ b/web/src/search.js
@@ -24,14 +24,14 @@ export function narrow_or_search_for_term(search_string, {on_narrow_search}) {
return $search_query_box.val();
}
- const operators = Filter.parse(search_string);
- on_narrow_search(operators, {trigger: "search"});
+ const terms = Filter.parse(search_string);
+ on_narrow_search(terms, {trigger: "search"});
// It's sort of annoying that this is not in a position to
// blur the search box, because it means that Esc won't
// unnarrow, it'll leave the searchbox.
- // Narrowing will have already put some operators in the search box,
+ // Narrowing will have already put some terms in the search box,
// so leave the current text in.
$search_query_box.trigger("blur");
return $search_query_box.val();
@@ -125,7 +125,7 @@ export function initialize({on_narrow_search}) {
// We just pressed Enter and the box had focus, which
// means we didn't use the typeahead at all. In that
// case, we should act as though we're searching by
- // operators. (The reason the other actions don't call
+ // terms. (The reason the other actions don't call
// this codepath is that they first all blur the box to
// indicate that they've done what they need to do)
@@ -231,7 +231,7 @@ function exit_search(opts) {
export function open_search_bar_and_close_narrow_description() {
// Preserve user input if they've already started typing, but
- // otherwise fill the input field with the text operators for
+ // otherwise fill the input field with the text terms for
// the current narrow.
if ($("#search_query").val() === "") {
reset_searchbox_text();
diff --git a/web/src/search_suggestion.js b/web/src/search_suggestion.js
index 43a14d5c433..024ab0ba0ae 100644
--- a/web/src/search_suggestion.js
+++ b/web/src/search_suggestion.js
@@ -38,8 +38,8 @@ function highlight_person(person, highlighter) {
};
}
-function match_criteria(operators, criteria) {
- const filter = new Filter(operators);
+function match_criteria(terms, criteria) {
+ const filter = new Filter(terms);
return criteria.some((cr) => {
if (Object.hasOwn(cr, "operand")) {
return filter.has_operand(cr.operator, cr.operand);
@@ -48,13 +48,13 @@ function match_criteria(operators, criteria) {
});
}
-function check_validity(last, operators, valid, invalid) {
+function check_validity(last, terms, valid, invalid) {
// valid: list of strings valid for the last operator
- // invalid: list of operators invalid for any previous operators except last.
+ // invalid: list of terms invalid for any previous terms except last.
if (!valid.includes(last.operator)) {
return false;
}
- if (match_criteria(operators, invalid)) {
+ if (match_criteria(terms, invalid)) {
return false;
}
return true;
@@ -96,7 +96,7 @@ function compare_by_huddle(huddle) {
};
}
-function get_stream_suggestions(last, operators) {
+function get_stream_suggestions(last, terms) {
const valid = ["stream", "search", ""];
const invalid = [
{operator: "stream"},
@@ -105,7 +105,7 @@ function get_stream_suggestions(last, operators) {
{operator: "dm"},
{operator: "dm-including"},
];
- if (!check_validity(last, operators, valid, invalid)) {
+ if (!check_validity(last, terms, valid, invalid)) {
return [];
}
@@ -136,10 +136,10 @@ function get_stream_suggestions(last, operators) {
return objs;
}
-function get_group_suggestions(last, operators) {
+function get_group_suggestions(last, terms) {
// For users with "pm-with" in their muscle memory, still
// have group direct message suggestions with "dm:" operator.
- if (!check_validity(last, operators, ["dm", "pm-with"], [{operator: "stream"}])) {
+ if (!check_validity(last, terms, ["dm", "pm-with"], [{operator: "stream"}])) {
return [];
}
@@ -240,7 +240,7 @@ function make_people_getter(last) {
}
// Possible args for autocomplete_operator: dm, pm-with, sender, from, dm-including
-function get_person_suggestions(people_getter, last, operators, autocomplete_operator) {
+function get_person_suggestions(people_getter, last, terms, autocomplete_operator) {
if ((last.operator === "is" && last.operand === "dm") || last.operator === "pm-with") {
// Interpret "is:dm" or "pm-with:" operator as equivalent to "dm:".
last = {operator: "dm", operand: "", negated: false};
@@ -275,7 +275,7 @@ function get_person_suggestions(people_getter, last, operators, autocomplete_ope
break;
}
- if (!check_validity(last, operators, valid, invalid)) {
+ if (!check_validity(last, terms, valid, invalid)) {
return [];
}
@@ -315,13 +315,13 @@ function get_person_suggestions(people_getter, last, operators, autocomplete_ope
return objs;
}
-function get_default_suggestion(operators) {
+function get_default_suggestion(terms) {
// Here we return the canonical suggestion for the query that the
- // user typed. (The caller passes us the parsed query as "operators".)
- if (operators.length === 0) {
+ // user typed. (The caller passes us the parsed query as "terms".)
+ if (terms.length === 0) {
return {description_html: "", search_string: ""};
}
- return format_as_suggestion(operators);
+ return format_as_suggestion(terms);
}
export function get_topic_suggestions_from_candidates({candidate_topics, guess}) {
@@ -356,14 +356,14 @@ export function get_topic_suggestions_from_candidates({candidate_topics, guess})
return topics;
}
-function get_topic_suggestions(last, operators) {
+function get_topic_suggestions(last, terms) {
const invalid = [
{operator: "dm"},
{operator: "is", operand: "dm"},
{operator: "dm-including"},
{operator: "topic"},
];
- if (!check_validity(last, operators, ["stream", "topic", "search"], invalid)) {
+ if (!check_validity(last, terms, ["stream", "topic", "search"], invalid)) {
return [];
}
@@ -372,8 +372,8 @@ function get_topic_suggestions(last, operators) {
const negated = operator === "topic" && last.negated;
let stream;
let guess;
- const filter = new Filter(operators);
- const suggest_operators = [];
+ const filter = new Filter(terms);
+ const suggest_terms = [];
// stream:Rome -> show all Rome topics
// stream:Rome topic: -> show all Rome topics
@@ -394,7 +394,7 @@ function get_topic_suggestions(last, operators) {
case "stream":
guess = "";
stream = operand;
- suggest_operators.push(last);
+ suggest_terms.push(last);
break;
case "topic":
case "search":
@@ -403,7 +403,7 @@ function get_topic_suggestions(last, operators) {
stream = filter.operands("stream")[0];
} else {
stream = narrow_state.stream_name();
- suggest_operators.push({operator: "stream", operand: stream});
+ suggest_terms.push({operator: "stream", operand: stream});
}
break;
}
@@ -444,34 +444,34 @@ function get_topic_suggestions(last, operators) {
return topics.map((topic) => {
const topic_term = {operator: "topic", operand: topic, negated};
- const operators = [...suggest_operators, topic_term];
- return format_as_suggestion(operators);
+ const terms = [...suggest_terms, topic_term];
+ return format_as_suggestion(terms);
});
}
-function get_operator_subset_suggestions(operators) {
+function get_term_subset_suggestions(terms) {
// For stream:a topic:b search:c, suggest:
// stream:a topic:b
// stream:a
- if (operators.length < 1) {
+ if (terms.length < 1) {
return [];
}
let i;
const suggestions = [];
- for (i = operators.length - 1; i >= 1; i -= 1) {
- const subset = operators.slice(0, i);
+ for (i = terms.length - 1; i >= 1; i -= 1) {
+ const subset = terms.slice(0, i);
suggestions.push(format_as_suggestion(subset));
}
return suggestions;
}
-function get_special_filter_suggestions(last, operators, suggestions) {
+function get_special_filter_suggestions(last, terms, suggestions) {
const is_search_operand_negated = last.operator === "search" && last.operand[0] === "-";
// Negating suggestions on is_search_operand_negated is required for
- // suggesting negated operators.
+ // suggesting negated terms.
if (last.negated || is_search_operand_negated) {
suggestions = suggestions.map((suggestion) => ({
search_string: "-" + suggestion.search_string,
@@ -482,7 +482,7 @@ function get_special_filter_suggestions(last, operators, suggestions) {
const last_string = Filter.unparse([last]).toLowerCase();
suggestions = suggestions.filter((s) => {
- if (match_criteria(operators, s.invalid)) {
+ if (match_criteria(terms, s.invalid)) {
return false;
}
if (last_string === "") {
@@ -503,7 +503,7 @@ function get_special_filter_suggestions(last, operators, suggestions) {
return suggestions;
}
-function get_streams_filter_suggestions(last, operators) {
+function get_streams_filter_suggestions(last, terms) {
const suggestions = [
{
search_string: "streams:public",
@@ -518,9 +518,9 @@ function get_streams_filter_suggestions(last, operators) {
],
},
];
- return get_special_filter_suggestions(last, operators, suggestions);
+ return get_special_filter_suggestions(last, terms, suggestions);
}
-function get_is_filter_suggestions(last, operators) {
+function get_is_filter_suggestions(last, terms) {
const suggestions = [
{
search_string: "is:dm",
@@ -564,10 +564,10 @@ function get_is_filter_suggestions(last, operators) {
],
},
];
- return get_special_filter_suggestions(last, operators, suggestions);
+ return get_special_filter_suggestions(last, terms, suggestions);
}
-function get_has_filter_suggestions(last, operators) {
+function get_has_filter_suggestions(last, terms) {
const suggestions = [
{
search_string: "has:link",
@@ -585,10 +585,10 @@ function get_has_filter_suggestions(last, operators) {
invalid: [{operator: "has", operand: "attachment"}],
},
];
- return get_special_filter_suggestions(last, operators, suggestions);
+ return get_special_filter_suggestions(last, terms, suggestions);
}
-function get_sent_by_me_suggestions(last, operators) {
+function get_sent_by_me_suggestions(last, terms) {
const last_string = Filter.unparse([last]).toLowerCase();
const negated = last.negated || (last.operator === "search" && last.operand[0] === "-");
const negated_symbol = negated ? "-" : "";
@@ -603,7 +603,7 @@ function get_sent_by_me_suggestions(last, operators) {
const invalid = [{operator: "sender"}, {operator: "from"}];
- if (match_criteria(operators, invalid)) {
+ if (match_criteria(terms, invalid)) {
return [];
}
@@ -704,41 +704,41 @@ class Attacher {
export function get_search_result(query) {
let suggestion;
- // search_operators correspond to the operators for the query in the input.
+ // search_terms correspond to the terms for the query in the input.
// This includes the entire query entered in the searchbox.
- // operators correspond to the operators for the entire query entered in the searchbox.
- const search_operators = Filter.parse(query);
+ // terms correspond to the terms for the entire query entered in the searchbox.
+ const search_terms = Filter.parse(query);
let last = {operator: "", operand: "", negated: false};
- if (search_operators.length > 0) {
- last = search_operators.at(-1);
+ if (search_terms.length > 0) {
+ last = search_terms.at(-1);
}
const person_suggestion_ops = ["sender", "dm", "dm-including", "from", "pm-with"];
// Handle spaces in person name in new suggestions only. Checks if the last operator is 'search'
- // and the second last operator in search_operators is one out of person_suggestion_ops.
+ // and the second last operator in search_terms is one out of person_suggestion_ops.
// e.g for `sender:Ted sm`, initially last = {operator: 'search', operand: 'sm'....}
// and second last is {operator: 'sender', operand: 'sm'....}. If the second last operand
- // is an email of a user, both of these operators remain unchanged. Otherwise search operator
+ // is an email of a user, both of these terms remain unchanged. Otherwise search operator
// will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}.
if (
- search_operators.length > 1 &&
+ search_terms.length > 1 &&
last.operator === "search" &&
- person_suggestion_ops.includes(search_operators.at(-2).operator)
+ person_suggestion_ops.includes(search_terms.at(-2).operator)
) {
- const person_op = search_operators.at(-2);
+ const person_op = search_terms.at(-2);
if (!people.reply_to_to_user_ids_string(person_op.operand)) {
last = {
operator: person_op.operator,
operand: person_op.operand + " " + last.operand,
negated: person_op.negated,
};
- search_operators.splice(-2);
- search_operators.push(last);
+ search_terms.splice(-2);
+ search_terms.push(last);
}
}
- const base = get_default_suggestion(search_operators.slice(0, -1));
+ const base = get_default_suggestion(search_terms.slice(0, -1));
const attacher = new Attacher(base);
// Display the default first
@@ -755,7 +755,7 @@ export function get_search_result(query) {
attacher.prepend_base(suggestion);
attacher.push(suggestion);
} else if (last.operator !== "" && last.operator !== "has" && last.operator !== "is") {
- suggestion = get_default_suggestion(search_operators);
+ suggestion = get_default_suggestion(search_terms);
attacher.push(suggestion);
}
@@ -763,8 +763,8 @@ export function get_search_result(query) {
const people_getter = make_people_getter(last);
function get_people(flavor) {
- return function (last, base_operators) {
- return get_person_suggestions(people_getter, last, base_operators, flavor);
+ return function (last, base_terms) {
+ return get_person_suggestions(people_getter, last, base_terms, flavor);
};
}
@@ -795,18 +795,18 @@ export function get_search_result(query) {
];
}
- const base_operators = search_operators.slice(0, -1);
+ const base_terms = search_terms.slice(0, -1);
const max_items = max_num_of_search_results;
for (const filterer of filterers) {
if (attacher.result.length < max_items) {
- const suggestions = filterer(last, base_operators);
+ const suggestions = filterer(last, base_terms);
attacher.attach_many(suggestions);
}
}
if (attacher.result.length < max_items) {
- const subset_suggestions = get_operator_subset_suggestions(search_operators);
+ const subset_suggestions = get_term_subset_suggestions(search_terms);
attacher.push_many(subset_suggestions);
}
diff --git a/web/src/typing_events.js b/web/src/typing_events.js
index 1f05af4efea..1f32e6977e6 100644
--- a/web/src/typing_events.js
+++ b/web/src/typing_events.js
@@ -33,7 +33,7 @@ function get_users_typing_for_narrow() {
return [];
}
- const first_term = narrow_state.operators()[0];
+ const first_term = narrow_state.search_terms()[0];
if (first_term.operator === "dm") {
// Get list of users typing in this conversation
const narrow_emails_string = first_term.operand;
diff --git a/web/src/unread_ops.js b/web/src/unread_ops.js
index eeee8aa802b..7c9dcf842c2 100644
--- a/web/src/unread_ops.js
+++ b/web/src/unread_ops.js
@@ -178,7 +178,7 @@ export function mark_as_unread_from_here(
narrow,
) {
if (narrow === undefined) {
- narrow = JSON.stringify(message_lists.current.data.filter.operators());
+ narrow = JSON.stringify(message_lists.current.data.filter.terms());
}
message_lists.current.prevent_reading();
const opts = {
diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js
index c5a8273c120..faef795ffc4 100644
--- a/web/tests/filter.test.js
+++ b/web/tests/filter.test.js
@@ -48,19 +48,19 @@ people.add_active_user(steve);
people.add_active_user(alice);
people.initialize_current_user(me.user_id);
-function assert_same_operators(result, terms) {
+function assert_same_terms(result, terms) {
// If negated flag is undefined, we explicitly
// set it to false.
terms = terms.map(({negated = false, operator, operand}) => ({negated, operator, operand}));
assert.deepEqual(result, terms);
}
-function get_predicate(operators) {
- operators = operators.map((op) => ({
+function get_predicate(raw_terms) {
+ const terms = raw_terms.map((op) => ({
operator: op[0],
operand: op[1],
}));
- return new Filter(operators).predicate();
+ return new Filter(terms).predicate();
}
function make_sub(name, stream_id) {
@@ -79,14 +79,14 @@ function test(label, f) {
}
test("basics", () => {
- let operators = [
+ let terms = [
{operator: "stream", operand: "foo"},
{operator: "stream", operand: "exclude_stream", negated: true},
{operator: "topic", operand: "bar"},
];
- let filter = new Filter(operators);
+ let filter = new Filter(terms);
- assert_same_operators(filter.operators(), operators);
+ assert_same_terms(filter.terms(), terms);
assert.deepEqual(filter.operands("stream"), ["foo"]);
assert.ok(filter.has_operator("stream"));
@@ -106,12 +106,12 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [
+ terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
{operator: "search", operand: "pizza"},
];
- filter = new Filter(operators);
+ filter = new Filter(terms);
assert.ok(filter.is_keyword_search());
assert.ok(!filter.can_mark_messages_read());
@@ -124,12 +124,12 @@ test("basics", () => {
assert.ok(filter.can_bucket_by("stream", "topic"));
assert.ok(!filter.is_conversation_view());
- operators = [
+ terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
{operator: "near", operand: 17},
];
- filter = new Filter(operators);
+ filter = new Filter(terms);
assert.ok(!filter.is_keyword_search());
assert.ok(!filter.can_mark_messages_read());
@@ -145,8 +145,8 @@ test("basics", () => {
// If our only stream operator is negated, then for all intents and purposes,
// we don't consider ourselves to have a stream operator, because we don't
// want to have the stream in the tab bar or unsubscribe messaging, etc.
- operators = [{operator: "stream", operand: "exclude", negated: true}];
- filter = new Filter(operators);
+ terms = [{operator: "stream", operand: "exclude", negated: true}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.has_operator("stream"));
assert.ok(!filter.can_mark_messages_read());
@@ -157,8 +157,8 @@ test("basics", () => {
// Negated searches are just like positive searches for our purposes, since
// the search logic happens on the backend and we need to have can_apply_locally()
// be false, and we want "Search results" in the tab bar.
- operators = [{operator: "search", operand: "stop_word", negated: true}];
- filter = new Filter(operators);
+ terms = [{operator: "search", operand: "stop_word", negated: true}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(filter.has_operator("search"));
assert.ok(!filter.can_apply_locally());
@@ -168,8 +168,8 @@ test("basics", () => {
assert.ok(!filter.is_conversation_view());
// Similar logic applies to negated "has" searches.
- operators = [{operator: "has", operand: "images", negated: true}];
- filter = new Filter(operators);
+ terms = [{operator: "has", operand: "images", negated: true}];
+ filter = new Filter(terms);
assert.ok(filter.has_operator("has"));
assert.ok(filter.can_apply_locally());
assert.ok(!filter.can_apply_locally(true));
@@ -179,8 +179,8 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [{operator: "streams", operand: "public", negated: true}];
- filter = new Filter(operators);
+ terms = [{operator: "streams", operand: "public", negated: true}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.has_operator("streams"));
assert.ok(!filter.can_mark_messages_read());
@@ -190,8 +190,8 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [{operator: "streams", operand: "public"}];
- filter = new Filter(operators);
+ terms = [{operator: "streams", operand: "public"}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(filter.has_operator("streams"));
assert.ok(!filter.can_mark_messages_read());
@@ -202,8 +202,8 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [{operator: "is", operand: "dm"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "dm"}];
+ filter = new Filter(terms);
assert.ok(filter.contains_only_private_messages());
assert.ok(filter.can_mark_messages_read());
assert.ok(filter.supports_collapsing_recipients());
@@ -213,13 +213,13 @@ test("basics", () => {
assert.ok(!filter.is_conversation_view());
// "is:private" was renamed to "is:dm"
- operators = [{operator: "is", operand: "private"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "private"}];
+ filter = new Filter(terms);
assert.ok(filter.has_operand("is", "dm"));
assert.ok(!filter.has_operand("is", "private"));
- operators = [{operator: "is", operand: "mentioned"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "mentioned"}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.can_mark_messages_read());
assert.ok(!filter.supports_collapsing_recipients());
@@ -228,8 +228,8 @@ test("basics", () => {
assert.ok(filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [{operator: "is", operand: "starred"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "starred"}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.can_mark_messages_read());
assert.ok(!filter.supports_collapsing_recipients());
@@ -238,8 +238,8 @@ test("basics", () => {
assert.ok(filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [{operator: "dm", operand: "[email protected]"}];
- filter = new Filter(operators);
+ terms = [{operator: "dm", operand: "[email protected]"}];
+ filter = new Filter(terms);
assert.ok(filter.is_non_huddle_pm());
assert.ok(filter.contains_only_private_messages());
assert.ok(filter.can_mark_messages_read());
@@ -249,8 +249,8 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(filter.is_conversation_view());
- operators = [{operator: "dm", operand: "[email protected],[email protected]"}];
- filter = new Filter(operators);
+ terms = [{operator: "dm", operand: "[email protected],[email protected]"}];
+ filter = new Filter(terms);
assert.ok(!filter.is_non_huddle_pm());
assert.ok(filter.contains_only_private_messages());
assert.ok(filter.can_mark_messages_read());
@@ -260,13 +260,13 @@ test("basics", () => {
assert.ok(filter.is_conversation_view());
// "pm-with" was renamed to "dm"
- operators = [{operator: "pm-with", operand: "[email protected]"}];
- filter = new Filter(operators);
+ terms = [{operator: "pm-with", operand: "[email protected]"}];
+ filter = new Filter(terms);
assert.ok(filter.has_operator("dm"));
assert.ok(!filter.has_operator(" pm-with"));
- operators = [{operator: "dm-including", operand: "[email protected]"}];
- filter = new Filter(operators);
+ terms = [{operator: "dm-including", operand: "[email protected]"}];
+ filter = new Filter(terms);
assert.ok(!filter.is_non_huddle_pm());
assert.ok(filter.contains_only_private_messages());
assert.ok(!filter.has_operator("search"));
@@ -277,13 +277,13 @@ test("basics", () => {
assert.ok(!filter.is_conversation_view());
// "group-pm-with" was replaced with "dm-including"
- operators = [{operator: "group-pm-with", operand: "[email protected]"}];
- filter = new Filter(operators);
+ terms = [{operator: "group-pm-with", operand: "[email protected]"}];
+ filter = new Filter(terms);
assert.ok(filter.has_operator("dm-including"));
assert.ok(!filter.has_operator("group-pm-with"));
- operators = [{operator: "is", operand: "resolved"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "resolved"}];
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.has_operator("search"));
assert.ok(filter.can_mark_messages_read());
@@ -294,7 +294,7 @@ test("basics", () => {
// Highly complex query to exercise
// filter.supports_collapsing_recipients loop.
- operators = [
+ terms = [
{operator: "is", operand: "resolved", negated: true},
{operator: "is", operand: "dm", negated: true},
{operator: "stream", operand: "stream_name", negated: true},
@@ -303,7 +303,7 @@ test("basics", () => {
{operator: "topic", operand: "patience", negated: true},
{operator: "in", operand: "all"},
];
- filter = new Filter(operators);
+ filter = new Filter(terms);
assert.ok(!filter.contains_only_private_messages());
assert.ok(!filter.has_operator("search"));
assert.ok(!filter.can_mark_messages_read());
@@ -314,11 +314,11 @@ test("basics", () => {
assert.ok(!filter.is_personal_filter());
assert.ok(!filter.is_conversation_view());
- operators = [
+ terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
];
- filter = new Filter(operators);
+ filter = new Filter(terms);
assert.ok(!filter.is_keyword_search());
assert.ok(filter.can_mark_messages_read());
@@ -331,87 +331,87 @@ test("basics", () => {
assert.ok(filter.is_conversation_view());
});
-function assert_not_mark_read_with_has_operands(additional_operators_to_test) {
- additional_operators_to_test = additional_operators_to_test || [];
- let has_operator = [{operator: "has", operand: "link"}];
- let filter = new Filter([...additional_operators_to_test, ...has_operator]);
+function assert_not_mark_read_with_has_operands(additional_terms_to_test) {
+ additional_terms_to_test = additional_terms_to_test || [];
+ let has_link_term = [{operator: "has", operand: "link"}];
+ let filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
- has_operator = [{operator: "has", operand: "link", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...has_operator]);
+ has_link_term = [{operator: "has", operand: "link", negated: true}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
- has_operator = [{operator: "has", operand: "image"}];
- filter = new Filter([...additional_operators_to_test, ...has_operator]);
+ has_link_term = [{operator: "has", operand: "image"}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
- has_operator = [{operator: "has", operand: "image", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...has_operator]);
+ has_link_term = [{operator: "has", operand: "image", negated: true}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
- has_operator = [{operator: "has", operand: "attachment", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...has_operator]);
+ has_link_term = [{operator: "has", operand: "attachment", negated: true}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
- has_operator = [{operator: "has", operand: "attachment"}];
- filter = new Filter([...additional_operators_to_test, ...has_operator]);
+ has_link_term = [{operator: "has", operand: "attachment"}];
+ filter = new Filter([...additional_terms_to_test, ...has_link_term]);
assert.ok(!filter.can_mark_messages_read());
}
-function assert_not_mark_read_with_is_operands(additional_operators_to_test) {
- additional_operators_to_test = additional_operators_to_test || [];
+function assert_not_mark_read_with_is_operands(additional_terms_to_test) {
+ additional_terms_to_test = additional_terms_to_test || [];
let is_operator = [{operator: "is", operand: "starred"}];
- let filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ let filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "starred", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "mentioned"}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "mentioned", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "alerted"}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "alerted", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "unread"}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "unread", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
is_operator = [{operator: "is", operand: "resolved"}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
- if (additional_operators_to_test.length === 0) {
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
+ if (additional_terms_to_test.length === 0) {
assert.ok(filter.can_mark_messages_read());
} else {
assert.ok(!filter.can_mark_messages_read());
}
is_operator = [{operator: "is", operand: "resolved", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...is_operator]);
+ filter = new Filter([...additional_terms_to_test, ...is_operator]);
assert.ok(!filter.can_mark_messages_read());
}
-function assert_not_mark_read_when_searching(additional_operators_to_test) {
- additional_operators_to_test = additional_operators_to_test || [];
+function assert_not_mark_read_when_searching(additional_terms_to_test) {
+ additional_terms_to_test = additional_terms_to_test || [];
let search_op = [{operator: "search", operand: "keyword"}];
- let filter = new Filter([...additional_operators_to_test, ...search_op]);
+ let filter = new Filter([...additional_terms_to_test, ...search_op]);
assert.ok(!filter.can_mark_messages_read());
search_op = [{operator: "search", operand: "keyword", negated: true}];
- filter = new Filter([...additional_operators_to_test, ...search_op]);
+ filter = new Filter([...additional_terms_to_test, ...search_op]);
assert.ok(!filter.can_mark_messages_read());
}
@@ -420,32 +420,32 @@ test("can_mark_messages_read", () => {
assert_not_mark_read_with_is_operands();
assert_not_mark_read_when_searching();
- const stream_operator = [{operator: "stream", operand: "foo"}];
- let filter = new Filter(stream_operator);
+ const stream_term = [{operator: "stream", operand: "foo"}];
+ let filter = new Filter(stream_term);
assert.ok(filter.can_mark_messages_read());
- assert_not_mark_read_with_has_operands(stream_operator);
- assert_not_mark_read_with_is_operands(stream_operator);
- assert_not_mark_read_when_searching(stream_operator);
+ assert_not_mark_read_with_has_operands(stream_term);
+ assert_not_mark_read_with_is_operands(stream_term);
+ assert_not_mark_read_when_searching(stream_term);
const stream_negated_operator = [{operator: "stream", operand: "foo", negated: true}];
filter = new Filter(stream_negated_operator);
assert.ok(!filter.can_mark_messages_read());
- const stream_topic_operators = [
+ const stream_topic_terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
];
- filter = new Filter(stream_topic_operators);
+ filter = new Filter(stream_topic_terms);
assert.ok(filter.can_mark_messages_read());
- assert_not_mark_read_with_has_operands(stream_topic_operators);
- assert_not_mark_read_with_is_operands(stream_topic_operators);
- assert_not_mark_read_when_searching(stream_topic_operators);
+ assert_not_mark_read_with_has_operands(stream_topic_terms);
+ assert_not_mark_read_with_is_operands(stream_topic_terms);
+ assert_not_mark_read_when_searching(stream_topic_terms);
- const stream_negated_topic_operators = [
+ const stream_negated_topic_terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar", negated: true},
];
- filter = new Filter(stream_negated_topic_operators);
+ filter = new Filter(stream_negated_topic_terms);
assert.ok(!filter.can_mark_messages_read());
const dm = [{operator: "dm", operand: "[email protected],"}];
@@ -519,12 +519,12 @@ test("can_mark_messages_read", () => {
});
test("show_first_unread", () => {
- let operators = [{operator: "is", operand: "any"}];
- let filter = new Filter(operators);
+ let terms = [{operator: "is", operand: "any"}];
+ let filter = new Filter(terms);
assert.ok(filter.allow_use_first_unread_when_narrowing());
- operators = [{operator: "search", operand: "query to search"}];
- filter = new Filter(operators);
+ terms = [{operator: "search", operand: "query to search"}];
+ filter = new Filter(terms);
assert.ok(!filter.allow_use_first_unread_when_narrowing());
filter = new Filter();
@@ -532,18 +532,18 @@ test("show_first_unread", () => {
assert.ok(filter.allow_use_first_unread_when_narrowing());
// Side case
- operators = [{operator: "is", operand: "any"}];
- filter = new Filter(operators);
+ terms = [{operator: "is", operand: "any"}];
+ filter = new Filter(terms);
assert.ok(!filter.can_mark_messages_read());
assert.ok(filter.allow_use_first_unread_when_narrowing());
});
test("filter_with_new_params_topic", () => {
- const operators = [
+ const terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "old topic"},
];
- const filter = new Filter(operators);
+ const filter = new Filter(terms);
assert.ok(filter.has_topic("foo", "old topic"));
assert.ok(!filter.has_topic("wrong", "old topic"));
@@ -559,11 +559,11 @@ test("filter_with_new_params_topic", () => {
});
test("filter_with_new_params_stream", () => {
- const operators = [
+ const terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "old topic"},
];
- const filter = new Filter(operators);
+ const filter = new Filter(terms);
assert.ok(filter.has_topic("foo", "old topic"));
assert.ok(!filter.has_topic("wrong", "old topic"));
@@ -578,35 +578,35 @@ test("filter_with_new_params_stream", () => {
assert.deepEqual(new_filter.operands("topic"), ["old topic"]);
});
-test("new_style_operators", () => {
+test("new_style_terms", () => {
const term = {
operator: "stream",
operand: "foo",
};
- const operators = [term];
- const filter = new Filter(operators);
+ const terms = [term];
+ const filter = new Filter(terms);
assert.deepEqual(filter.operands("stream"), ["foo"]);
assert.ok(filter.can_bucket_by("stream"));
});
-test("public_operators", ({override}) => {
+test("public_terms", ({override}) => {
stream_data.clear_subscriptions();
- let operators = [
+ let terms = [
{operator: "stream", operand: "some_stream"},
{operator: "in", operand: "all"},
{operator: "topic", operand: "bar"},
];
- let filter = new Filter(operators);
+ let filter = new Filter(terms);
override(page_params, "narrow_stream", undefined);
- assert_same_operators(filter.public_operators(), operators);
+ assert_same_terms(filter.public_terms(), terms);
assert.ok(filter.can_bucket_by("stream"));
- operators = [{operator: "stream", operand: "default"}];
- filter = new Filter(operators);
+ terms = [{operator: "stream", operand: "default"}];
+ filter = new Filter(terms);
override(page_params, "narrow_stream", "default");
- assert_same_operators(filter.public_operators(), []);
+ assert_same_terms(filter.public_terms(), []);
});
test("redundancies", () => {
@@ -1017,15 +1017,15 @@ test("predicate_edge_cases", () => {
test("parse", () => {
let string;
- let operators;
+ let terms;
function _test() {
const result = Filter.parse(string);
- assert_same_operators(result, operators);
+ assert_same_terms(result, terms);
}
string = "stream:Foo topic:Bar yo";
- operators = [
+ terms = [
{operator: "stream", operand: "Foo"},
{operator: "topic", operand: "Bar"},
{operator: "search", operand: "yo"},
@@ -1033,19 +1033,19 @@ test("parse", () => {
_test();
string = "dm:[email protected]";
- operators = [{operator: "dm", operand: "[email protected]"}];
+ terms = [{operator: "dm", operand: "[email protected]"}];
_test();
string = "sender:[email protected]";
- operators = [{operator: "sender", operand: "[email protected]"}];
+ terms = [{operator: "sender", operand: "[email protected]"}];
_test();
string = "stream:With+Space";
- operators = [{operator: "stream", operand: "With Space"}];
+ terms = [{operator: "stream", operand: "With Space"}];
_test();
string = 'stream:"with quoted space" topic:and separate';
- operators = [
+ terms = [
{operator: "stream", operand: "with quoted space"},
{operator: "topic", operand: "and"},
{operator: "search", operand: "separate"},
@@ -1053,26 +1053,26 @@ test("parse", () => {
_test();
string = 'stream:"unclosed quote';
- operators = [{operator: "stream", operand: "unclosed quote"}];
+ terms = [{operator: "stream", operand: "unclosed quote"}];
_test();
string = 'stream:""';
- operators = [{operator: "stream", operand: ""}];
+ terms = [{operator: "stream", operand: ""}];
_test();
string = "https://www.google.com";
- operators = [{operator: "search", operand: "https://www.google.com"}];
+ terms = [{operator: "search", operand: "https://www.google.com"}];
_test();
string = "stream:foo -stream:exclude";
- operators = [
+ terms = [
{operator: "stream", operand: "foo"},
{operator: "stream", operand: "exclude", negated: true},
];
_test();
string = "text stream:foo more text";
- operators = [
+ terms = [
{operator: "search", operand: "text"},
{operator: "stream", operand: "foo"},
{operator: "search", operand: "more text"},
@@ -1080,7 +1080,7 @@ test("parse", () => {
_test();
string = "text streams:public more text";
- operators = [
+ terms = [
{operator: "search", operand: "text"},
{operator: "streams", operand: "public"},
{operator: "search", operand: "more text"},
@@ -1088,22 +1088,22 @@ test("parse", () => {
_test();
string = "streams:public";
- operators = [{operator: "streams", operand: "public"}];
+ terms = [{operator: "streams", operand: "public"}];
_test();
string = "-streams:public";
- operators = [{operator: "streams", operand: "public", negated: true}];
+ terms = [{operator: "streams", operand: "public", negated: true}];
_test();
string = "stream:foo :emoji: are cool";
- operators = [
+ terms = [
{operator: "stream", operand: "foo"},
{operator: "search", operand: ":emoji: are cool"},
];
_test();
string = ":stream: stream:foo :emoji: are cool";
- operators = [
+ terms = [
{operator: "search", operand: ":stream:"},
{operator: "stream", operand: "foo"},
{operator: "search", operand: ":emoji: are cool"},
@@ -1111,7 +1111,7 @@ test("parse", () => {
_test();
string = ":stream: stream:foo -:emoji: are cool";
- operators = [
+ terms = [
{operator: "search", operand: ":stream:"},
{operator: "stream", operand: "foo"},
{operator: "search", operand: "-:emoji: are cool"},
@@ -1119,11 +1119,11 @@ test("parse", () => {
_test();
string = "";
- operators = [];
+ terms = [];
_test();
string = 'stream: separated topic: "with space"';
- operators = [
+ terms = [
{operator: "stream", operand: "separated"},
{operator: "topic", operand: "with space"},
];
@@ -1132,43 +1132,43 @@ test("parse", () => {
test("unparse", () => {
let string;
- let operators;
+ let terms;
- operators = [
+ terms = [
{operator: "stream", operand: "Foo"},
{operator: "topic", operand: "Bar", negated: true},
{operator: "search", operand: "yo"},
];
string = "stream:Foo -topic:Bar yo";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [
+ terms = [
{operator: "streams", operand: "public"},
{operator: "search", operand: "text"},
];
string = "streams:public text";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [{operator: "streams", operand: "public"}];
+ terms = [{operator: "streams", operand: "public"}];
string = "streams:public";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [{operator: "streams", operand: "public", negated: true}];
+ terms = [{operator: "streams", operand: "public", negated: true}];
string = "-streams:public";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [{operator: "id", operand: 50}];
+ terms = [{operator: "id", operand: 50}];
string = "id:50";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [{operator: "near", operand: 150}];
+ terms = [{operator: "near", operand: 150}];
string = "near:150";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
- operators = [{operator: "", operand: ""}];
+ terms = [{operator: "", operand: ""}];
string = "";
- assert.deepEqual(Filter.unparse(operators), string);
+ assert.deepEqual(Filter.unparse(terms), string);
});
test("describe", ({mock_template}) => {
@@ -1499,18 +1499,18 @@ test("navbar_helpers", () => {
}
function test_redirect_url_with_search(test_case) {
- test_case.operator.push({operator: "search", operand: "fizzbuzz"});
- const filter = new Filter(test_case.operator);
+ test_case.terms.push({operator: "search", operand: "fizzbuzz"});
+ const filter = new Filter(test_case.terms);
assert.equal(filter.generate_redirect_url(), test_case.redirect_url_with_search);
}
function test_common_narrow(test_case) {
- const filter = new Filter(test_case.operator);
+ const filter = new Filter(test_case.terms);
assert.equal(filter.is_common_narrow(), test_case.is_common_narrow);
}
function test_add_icon_data(test_case) {
- const filter = new Filter(test_case.operator);
+ const filter = new Filter(test_case.terms);
let context = {};
context = filter.add_icon_data(context);
assert.equal(context.icon, test_case.icon);
@@ -1518,7 +1518,7 @@ test("navbar_helpers", () => {
}
function test_get_title(test_case) {
- const filter = new Filter(test_case.operator);
+ const filter = new Filter(test_case.terms);
assert.deepEqual(filter.get_title(), test_case.title);
}
@@ -1539,16 +1539,16 @@ test("navbar_helpers", () => {
const is_mentioned = [{operator: "is", operand: "mentioned"}];
const is_resolved = [{operator: "is", operand: "resolved"}];
const streams_public = [{operator: "streams", operand: "public"}];
- const stream_topic_operators = [
+ const stream_topic_terms = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
];
// foo stream exists
- const stream_operator = [{operator: "stream", operand: "foo"}];
+ const stream_term = [{operator: "stream", operand: "foo"}];
make_private_sub("psub", "22");
- const private_stream_operator = [{operator: "stream", operand: "psub"}];
+ const private_stream_term = [{operator: "stream", operand: "psub"}];
make_web_public_sub("webPublicSub", "12"); // capitalized just to try be tricky and robust.
- const web_public_stream_operator = [{operator: "stream", operand: "webPublicSub"}];
+ const web_public_stream = [{operator: "stream", operand: "webPublicSub"}];
const non_existent_stream = [{operator: "stream", operand: "Elephant"}];
const non_existent_stream_topic = [
{operator: "stream", operand: "Elephant"},
@@ -1578,112 +1578,112 @@ test("navbar_helpers", () => {
const test_cases = [
{
- operator: sender,
+ terms: sender,
is_common_narrow: true,
icon: undefined,
title: "translated: Messages sent by " + joe.full_name,
redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe",
},
{
- operator: guest_sender,
+ terms: guest_sender,
is_common_narrow: true,
icon: undefined,
title: "translated: Messages sent by translated: alice (guest)",
redirect_url_with_search: "/#narrow/sender/" + alice.user_id + "-alice",
},
{
- operator: is_starred,
+ terms: is_starred,
is_common_narrow: true,
zulip_icon: "star-filled",
title: "translated: Starred messages",
redirect_url_with_search: "/#narrow/is/starred",
},
{
- operator: in_home,
+ terms: in_home,
is_common_narrow: true,
icon: "home",
title: "translated: All messages",
redirect_url_with_search: "#",
},
{
- operator: in_all,
+ terms: in_all,
is_common_narrow: true,
icon: "home",
title: "translated: All messages including muted streams",
redirect_url_with_search: "#",
},
{
- operator: is_dm,
+ terms: is_dm,
is_common_narrow: true,
icon: "envelope",
title: "translated: All direct messages",
redirect_url_with_search: "/#narrow/is/dm",
},
{
- operator: is_mentioned,
+ terms: is_mentioned,
is_common_narrow: true,
zulip_icon: "at-sign",
title: "translated: Mentions",
redirect_url_with_search: "/#narrow/is/mentioned",
},
{
- operator: is_resolved,
+ terms: is_resolved,
is_common_narrow: true,
icon: "check",
title: "translated: Topics marked as resolved",
redirect_url_with_search: "/#narrow/topics/is/resolved",
},
{
- operator: stream_topic_operators,
+ terms: stream_topic_terms,
is_common_narrow: true,
zulip_icon: "hashtag",
title: "Foo",
redirect_url_with_search: "/#narrow/stream/43-Foo/topic/bar",
},
{
- operator: streams_public,
+ terms: streams_public,
is_common_narrow: true,
icon: undefined,
title: "translated: Messages in all public streams",
redirect_url_with_search: "/#narrow/streams/public",
},
{
- operator: stream_operator,
+ terms: stream_term,
is_common_narrow: true,
zulip_icon: "hashtag",
title: "Foo",
redirect_url_with_search: "/#narrow/stream/43-Foo",
},
{
- operator: non_existent_stream,
+ terms: non_existent_stream,
is_common_narrow: true,
icon: "question-circle-o",
title: "translated: Unknown stream #Elephant",
redirect_url_with_search: "#",
},
{
- operator: non_existent_stream_topic,
+ terms: non_existent_stream_topic,
is_common_narrow: true,
icon: "question-circle-o",
title: "translated: Unknown stream #Elephant",
redirect_url_with_search: "#",
},
{
- operator: private_stream_operator,
+ terms: private_stream_term,
is_common_narrow: true,
zulip_icon: "lock",
title: "psub",
redirect_url_with_search: "/#narrow/stream/22-psub",
},
{
- operator: web_public_stream_operator,
+ terms: web_public_stream,
is_common_narrow: true,
zulip_icon: "globe",
title: "webPublicSub",
redirect_url_with_search: "/#narrow/stream/12-webPublicSub",
},
{
- operator: dm,
+ terms: dm,
is_common_narrow: true,
icon: "envelope",
title: properly_separated_names([joe.full_name]),
@@ -1691,14 +1691,14 @@ test("navbar_helpers", () => {
"/#narrow/dm/" + joe.user_id + "-" + parseOneAddress(joe.email).local,
},
{
- operator: dm_group,
+ terms: dm_group,
is_common_narrow: true,
icon: "envelope",
title: properly_separated_names([joe.full_name, steve.full_name]),
redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + steve.user_id + "-group",
},
{
- operator: dm_with_guest,
+ terms: dm_with_guest,
is_common_narrow: true,
icon: "envelope",
title: "translated: alice (guest)",
@@ -1706,14 +1706,14 @@ test("navbar_helpers", () => {
"/#narrow/dm/" + alice.user_id + "-" + parseOneAddress(alice.email).local,
},
{
- operator: dm_group_including_guest,
+ terms: dm_group_including_guest,
is_common_narrow: true,
icon: "envelope",
title: "translated: alice (guest), joe",
redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + alice.user_id + "-group",
},
{
- operator: dm_group_including_missing_person,
+ terms: dm_group_including_missing_person,
is_common_narrow: true,
icon: "envelope",
title: properly_separated_names([
@@ -1724,28 +1724,28 @@ test("navbar_helpers", () => {
redirect_url_with_search: "/#narrow/dm/undefined",
},
{
- operator: is_alerted,
+ terms: is_alerted,
is_common_narrow: false,
icon: undefined,
title: "translated: Alerted messages",
redirect_url_with_search: "#",
},
{
- operator: is_unread,
+ terms: is_unread,
is_common_narrow: false,
icon: undefined,
title: "translated: Unread messages",
redirect_url_with_search: "#",
},
{
- operator: stream_topic_near,
+ terms: stream_topic_near,
is_common_narrow: false,
zulip_icon: "hashtag",
title: "Foo",
redirect_url_with_search: "#",
},
{
- operator: dm_near,
+ terms: dm_near,
is_common_narrow: false,
icon: "envelope",
title: properly_separated_names([joe.full_name]),
@@ -1765,12 +1765,12 @@ test("navbar_helpers", () => {
const redirect_edge_cases = [
{
- operator: sender_me,
+ terms: sender_me,
redirect_url_with_search: "/#narrow/sender/" + me.user_id + "-Me-Myself",
is_common_narrow: true,
},
{
- operator: sender_joe,
+ terms: sender_joe,
redirect_url_with_search: "/#narrow/sender/" + joe.user_id + "-joe",
is_common_narrow: true,
},
@@ -1783,33 +1783,30 @@ test("navbar_helpers", () => {
// TODO: test every single one of the "ALL" redirects from the navbar behaviour table
// incomplete and weak test cases just to restore coverage of filter.js
- const complex_operator = [
+ const complex_term = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
{operator: "sender", operand: "me"},
];
- const complex_operators_test_case = {
- operator: complex_operator,
- redirect_url: "#",
- };
+ const redirect_url = "#";
- let filter = new Filter(complex_operators_test_case.operator);
- assert.equal(filter.generate_redirect_url(), complex_operators_test_case.redirect_url);
+ let filter = new Filter(complex_term);
+ assert.equal(filter.generate_redirect_url(), redirect_url);
assert.equal(filter.is_common_narrow(), false);
- const stream_topic_search_operator = [
+ const stream_topic_search_term = [
{operator: "stream", operand: "foo"},
{operator: "topic", operand: "bar"},
{operator: "search", operand: "potato"},
];
- const stream_topic_search_operator_test_case = {
- operator: stream_topic_search_operator,
+ const stream_topic_search_term_test_case = {
+ terms: stream_topic_search_term,
title: undefined,
};
- test_get_title(stream_topic_search_operator_test_case);
+ test_get_title(stream_topic_search_term_test_case);
page_params.realm_enable_guest_user_indicator = false;
const guest_user_test_cases_without_indicator = [
@@ -1843,11 +1840,11 @@ test("navbar_helpers", () => {
// this is actually wrong, but the code is currently not robust enough to throw an error here
// also, used as an example of triggering last return statement.
const default_redirect = {
- operator: [{operator: "stream", operand: "foo"}],
+ terms: [{operator: "stream", operand: "foo"}],
redirect_url: "#",
};
- filter = new Filter(default_redirect.operator);
+ filter = new Filter(default_redirect.terms);
assert.equal(filter.generate_redirect_url(), default_redirect.redirect_url);
});
diff --git a/web/tests/hash_util.test.js b/web/tests/hash_util.test.js
index e6351d9f5c1..21302208fe8 100644
--- a/web/tests/hash_util.test.js
+++ b/web/tests/hash_util.test.js
@@ -184,24 +184,24 @@ run_test("test_by_conversation_and_time_url", () => {
});
run_test("test_search_public_streams_notice_url", () => {
- function get_operators(url) {
+ function get_terms(url) {
return hash_util.parse_narrow(url.split("/"));
}
assert.equal(
- hash_util.search_public_streams_notice_url(get_operators("#narrow/search/abc")),
+ hash_util.search_public_streams_notice_url(get_terms("#narrow/search/abc")),
"#narrow/streams/public/search/abc",
);
assert.equal(
hash_util.search_public_streams_notice_url(
- get_operators("#narrow/has/link/has/image/has/attachment"),
+ get_terms("#narrow/has/link/has/image/has/attachment"),
),
"#narrow/streams/public/has/link/has/image/has/attachment",
);
assert.equal(
- hash_util.search_public_streams_notice_url(get_operators("#narrow/sender/15")),
+ hash_util.search_public_streams_notice_url(get_terms("#narrow/sender/15")),
"#narrow/streams/public/sender/15-Hamlet",
);
});
diff --git a/web/tests/hashchange.test.js b/web/tests/hashchange.test.js
index 71dd23283df..75f18e94049 100644
--- a/web/tests/hashchange.test.js
+++ b/web/tests/hashchange.test.js
@@ -34,16 +34,16 @@ const hashchange = zrequire("hashchange");
const narrow = zrequire("../src/narrow");
const stream_data = zrequire("stream_data");
-run_test("operators_round_trip", () => {
- let operators;
+run_test("terms_round_trip", () => {
+ let terms;
let hash;
let narrow;
- operators = [
+ terms = [
{operator: "stream", operand: "devel"},
{operator: "topic", operand: "algol"},
];
- hash = hash_util.operators_to_hash(operators);
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel/topic/algol");
narrow = hash_util.parse_narrow(hash.split("/"));
@@ -52,11 +52,11 @@ run_test("operators_round_trip", () => {
{operator: "topic", operand: "algol", negated: false},
]);
- operators = [
+ terms = [
{operator: "stream", operand: "devel"},
{operator: "topic", operand: "visual c++", negated: true},
];
- hash = hash_util.operators_to_hash(operators);
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel/-topic/visual.20c.2B.2B");
narrow = hash_util.parse_narrow(hash.split("/"));
@@ -71,14 +71,14 @@ run_test("operators_round_trip", () => {
stream_id: 987,
};
stream_data.add_sub(florida_stream);
- operators = [{operator: "stream", operand: "Florida, USA"}];
- hash = hash_util.operators_to_hash(operators);
+ terms = [{operator: "stream", operand: "Florida, USA"}];
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/987-Florida.2C-USA");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "stream", operand: "Florida, USA", negated: false}]);
});
-run_test("operators_trailing_slash", () => {
+run_test("terms_trailing_slash", () => {
const hash = "#narrow/stream/devel/topic/algol/";
const narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [
@@ -88,7 +88,7 @@ run_test("operators_trailing_slash", () => {
});
run_test("people_slugs", () => {
- let operators;
+ let terms;
let hash;
let narrow;
@@ -99,22 +99,22 @@ run_test("people_slugs", () => {
};
people.add_active_user(alice);
- operators = [{operator: "sender", operand: "[email protected]"}];
- hash = hash_util.operators_to_hash(operators);
+ terms = [{operator: "sender", operand: "[email protected]"}];
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/sender/42-Alice-Smith");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "sender", operand: "[email protected]", negated: false}]);
- operators = [{operator: "dm", operand: "[email protected]"}];
- hash = hash_util.operators_to_hash(operators);
+ terms = [{operator: "dm", operand: "[email protected]"}];
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/dm/42-Alice-Smith");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "dm", operand: "[email protected]", negated: false}]);
// Even though we renamed "pm-with" to "dm", preexisting
// links/URLs with "pm-with" operator are handled correctly.
- operators = [{operator: "pm-with", operand: "[email protected]"}];
- hash = hash_util.operators_to_hash(operators);
+ terms = [{operator: "pm-with", operand: "[email protected]"}];
+ hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/pm-with/42-Alice-Smith");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "pm-with", operand: "[email protected]", negated: false}]);
@@ -334,10 +334,10 @@ run_test("hash_interactions", ({override, override_rewire}) => {
run_test("save_narrow", ({override, override_rewire}) => {
const helper = test_helper({override, override_rewire});
- let operators = [{operator: "is", operand: "dm"}];
+ let terms = [{operator: "is", operand: "dm"}];
blueslip.expect("error", "browser does not support pushState");
- narrow.save_narrow(operators);
+ narrow.save_narrow(terms);
helper.assert_events([[message_viewport, "stop_auto_scrolling"]]);
assert.equal(window.location.hash, "#narrow/is/dm");
@@ -347,10 +347,10 @@ run_test("save_narrow", ({override, override_rewire}) => {
url_pushed = url;
});
- operators = [{operator: "is", operand: "starred"}];
+ terms = [{operator: "is", operand: "starred"}];
helper.clear_events();
- narrow.save_narrow(operators);
+ narrow.save_narrow(terms);
helper.assert_events([[message_viewport, "stop_auto_scrolling"]]);
assert.equal(url_pushed, "http://zulip.zulipdev.com/#narrow/is/starred");
});
diff --git a/web/tests/narrow.test.js b/web/tests/narrow.test.js
index 2e92469f73e..2f96d80da9d 100644
--- a/web/tests/narrow.test.js
+++ b/web/tests/narrow.test.js
@@ -38,12 +38,12 @@ function empty_narrow_html(title, html, search_data) {
return require("../templates/empty_feed_notice.hbs")(opts);
}
-function set_filter(operators) {
- operators = operators.map((op) => ({
+function set_filter(terms) {
+ terms = terms.map((op) => ({
operator: op[0],
operand: op[1],
}));
- narrow_state.set_current_filter(new Filter(operators));
+ narrow_state.set_current_filter(new Filter(terms));
}
const me = {
@@ -671,8 +671,8 @@ run_test("narrow_to_compose_target errors", ({disallow_rewire}) => {
run_test("narrow_to_compose_target streams", ({override_rewire}) => {
const args = {called: false};
- override_rewire(narrow, "activate", (operators, opts) => {
- args.operators = operators;
+ override_rewire(narrow, "activate", (terms, opts) => {
+ args.terms = terms;
args.opts = opts;
args.called = true;
});
@@ -687,7 +687,7 @@ run_test("narrow_to_compose_target streams", ({override_rewire}) => {
narrow.to_compose_target();
assert.equal(args.called, true);
assert.equal(args.opts.trigger, "narrow_to_compose_target");
- assert.deepEqual(args.operators, [
+ assert.deepEqual(args.terms, [
{operator: "stream", operand: "ROME"},
{operator: "topic", operand: "one"},
]);
@@ -697,7 +697,7 @@ run_test("narrow_to_compose_target streams", ({override_rewire}) => {
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [
+ assert.deepEqual(args.terms, [
{operator: "stream", operand: "ROME"},
{operator: "topic", operand: "four"},
]);
@@ -707,20 +707,20 @@ run_test("narrow_to_compose_target streams", ({override_rewire}) => {
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);
+ assert.deepEqual(args.terms, [{operator: "stream", operand: "ROME"}]);
// Test with no topic
compose_state.topic(undefined);
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);
+ assert.deepEqual(args.terms, [{operator: "stream", operand: "ROME"}]);
});
run_test("narrow_to_compose_target direct messages", ({override, override_rewire}) => {
const args = {called: false};
- override_rewire(narrow, "activate", (operators, opts) => {
- args.operators = operators;
+ override_rewire(narrow, "activate", (terms, opts) => {
+ args.terms = terms;
args.opts = opts;
args.called = true;
});
@@ -738,37 +738,35 @@ run_test("narrow_to_compose_target direct messages", ({override, override_rewire
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "dm", operand: "[email protected]"}]);
+ assert.deepEqual(args.terms, [{operator: "dm", operand: "[email protected]"}]);
// Test with valid persons
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [
- {operator: "dm", operand: "[email protected],[email protected]"},
- ]);
+ assert.deepEqual(args.terms, [{operator: "dm", operand: "[email protected],[email protected]"}]);
// Test with some invalid persons
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "is", operand: "dm"}]);
+ assert.deepEqual(args.terms, [{operator: "is", operand: "dm"}]);
// Test with all invalid persons
emails = "alice,random,ray";
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "is", operand: "dm"}]);
+ assert.deepEqual(args.terms, [{operator: "is", operand: "dm"}]);
// Test with no persons
emails = "";
args.called = false;
narrow.to_compose_target();
assert.equal(args.called, true);
- assert.deepEqual(args.operators, [{operator: "is", operand: "dm"}]);
+ assert.deepEqual(args.terms, [{operator: "is", operand: "dm"}]);
});
run_test("narrow_compute_title", () => {
diff --git a/web/tests/narrow_state.test.js b/web/tests/narrow_state.test.js
index a0f5e169d5e..74ecdfd8764 100644
--- a/web/tests/narrow_state.test.js
+++ b/web/tests/narrow_state.test.js
@@ -10,12 +10,12 @@ const {Filter} = zrequire("../src/filter");
const stream_data = zrequire("stream_data");
const narrow_state = zrequire("narrow_state");
-function set_filter(operators) {
- operators = operators.map((op) => ({
+function set_filter(raw_terms) {
+ const terms = raw_terms.map((op) => ({
operator: op[0],
operand: op[1],
}));
- narrow_state.set_current_filter(new Filter(operators));
+ narrow_state.set_current_filter(new Filter(terms));
}
function test(label, f) {
@@ -27,7 +27,7 @@ function test(label, f) {
}
test("stream", () => {
- assert.equal(narrow_state.public_operators(), undefined);
+ assert.equal(narrow_state.public_search_terms(), undefined);
assert.ok(!narrow_state.active());
assert.equal(narrow_state.stream_id(), undefined);
@@ -49,14 +49,14 @@ test("stream", () => {
assert.equal(narrow_state.topic(), "Bar");
assert.ok(narrow_state.is_for_stream_id(test_stream.stream_id));
- const expected_operators = [
+ const expected_terms = [
{negated: false, operator: "stream", operand: "Test"},
{negated: false, operator: "topic", operand: "Bar"},
{negated: false, operator: "search", operand: "yo"},
];
- const public_operators = narrow_state.public_operators();
- assert.deepEqual(public_operators, expected_operators);
+ const public_terms = narrow_state.public_search_terms();
+ assert.deepEqual(public_terms, expected_terms);
assert.equal(narrow_state.search_string(), "stream:Test topic:Bar yo");
});
@@ -125,13 +125,13 @@ test("narrowed", () => {
assert.ok(narrow_state.narrowed_to_starred());
});
-test("operators", () => {
+test("terms", () => {
set_filter([
["stream", "Foo"],
["topic", "Bar"],
["search", "Yo"],
]);
- let result = narrow_state.operators();
+ let result = narrow_state.search_terms();
assert.equal(result.length, 3);
assert.equal(result[0].operator, "stream");
assert.equal(result[0].operand, "Foo");
@@ -143,7 +143,7 @@ test("operators", () => {
assert.equal(result[2].operand, "yo");
narrow_state.reset_current_filter();
- result = narrow_state.operators();
+ result = narrow_state.search_terms();
assert.equal(result.length, 0);
});
diff --git a/web/tests/search.test.js b/web/tests/search.test.js
index 3eb3bfb615f..fb654654207 100644
--- a/web/tests/search.test.js
+++ b/web/tests/search.test.js
@@ -43,7 +43,7 @@ run_test("initialize", ({override_rewire, mock_template}) => {
});
search_suggestion.max_num_of_search_results = 999;
- let operators;
+ let terms;
$search_query_box.typeahead = (opts) => {
assert.equal(opts.items, 999);
@@ -182,11 +182,11 @@ run_test("initialize", ({override_rewire, mock_template}) => {
$search_query_box.val(search_box_val);
Filter.parse = (search_string) => {
assert.equal(search_string, search_box_val);
- return operators;
+ return terms;
};
};
- operators = [
+ terms = [
{
negated: false,
operator: "search",
@@ -197,7 +197,7 @@ run_test("initialize", ({override_rewire, mock_template}) => {
assert.equal(opts.updater("ver"), "ver");
assert.ok(is_blurred);
- operators = [
+ terms = [
{
negated: false,
operator: "stream",
@@ -219,8 +219,8 @@ run_test("initialize", ({override_rewire, mock_template}) => {
};
search.initialize({
- on_narrow_search(raw_operators, options) {
- assert.deepEqual(raw_operators, operators);
+ on_narrow_search(raw_terms, options) {
+ assert.deepEqual(raw_terms, terms);
assert.deepEqual(options, {trigger: "search"});
},
});
@@ -268,11 +268,11 @@ run_test("initialize", ({override_rewire, mock_template}) => {
$search_query_box.val(search_box_val);
Filter.parse = (search_string) => {
assert.equal(search_string, search_box_val);
- return operators;
+ return terms;
};
};
- operators = [
+ terms = [
{
negated: false,
operator: "search",
diff --git a/web/tests/search_suggestion.test.js b/web/tests/search_suggestion.test.js
index 3c6daba4ac7..354890d1bc2 100644
--- a/web/tests/search_suggestion.test.js
+++ b/web/tests/search_suggestion.test.js
@@ -333,7 +333,7 @@ test("group_suggestions", ({mock_template}) => {
];
assert.deepEqual(suggestions.strings, expected);
- // Test multiple operators
+ // Test multiple terms
query = "is:starred has:link dm:[email protected],Smit";
suggestions = get_suggestions(query);
expected = [