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.

state_data: Rename Term type to NarrowTerm.

Anders Kaseorga5c055ae82da
diff --git a/web/src/base_page_params.ts b/web/src/base_page_params.ts
index 250e427efb8..de77f12fab9 100644
--- a/web/src/base_page_params.ts
+++ b/web/src/base_page_params.ts
@@ -1,7 +1,7 @@
import $ from "jquery";
import {z} from "zod";
-import {state_data_schema, term_schema} from "./state_data";
+import {narrow_term_schema, state_data_schema} from "./state_data";
const t1 = performance.now();
@@ -43,7 +43,7 @@ const home_params_schema = default_params_schema
}),
),
login_page: z.string(),
- narrow: z.optional(z.array(term_schema)),
+ narrow: z.optional(z.array(narrow_term_schema)),
narrow_stream: z.optional(z.string()),
needs_tutorial: z.boolean(),
promote_sponsoring_zulip: z.boolean(),
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 908cee28566..dbd1d5fe28b 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -12,7 +12,7 @@ import type {Message} from "./message_store";
import {page_params} from "./page_params";
import * as people from "./people";
import {realm} from "./state_data";
-import type {Term} from "./state_data";
+import type {NarrowTerm} from "./state_data";
import * as stream_data from "./stream_data";
import type {StreamSubscription} from "./sub_store";
import * as unread from "./unread";
@@ -236,13 +236,13 @@ function message_matches_search_term(message: Message, operator: string, operand
}
export class Filter {
- _terms: Term[];
+ _terms: NarrowTerm[];
_sub?: StreamSubscription;
_sorted_term_types?: string[] = undefined;
_predicate?: (message: Message) => boolean;
_can_mark_messages_read?: boolean;
- constructor(terms: Term[]) {
+ constructor(terms: NarrowTerm[]) {
this._terms = this.fix_terms(terms);
if (this.has_operator("stream")) {
this._sub = stream_data.get_sub_by_name(this.operands("stream")[0]);
@@ -272,7 +272,7 @@ export class Filter {
return operator;
}
- static canonicalize_term({negated = false, operator, operand}: Term): Term {
+ static canonicalize_term({negated = false, operator, operand}: NarrowTerm): NarrowTerm {
// Make negated explicitly default to false for both clarity and
// simplifying deepEqual checks in the tests.
operator = Filter.canonicalize_operator(operator);
@@ -353,8 +353,8 @@ export class Filter {
}
// Parse a string into a list of terms (see below).
- static parse(str: string): Term[] {
- const terms: Term[] = [];
+ static parse(str: string): NarrowTerm[] {
+ const terms: NarrowTerm[] = [];
let search_term: string[] = [];
let negated;
let operator;
@@ -430,7 +430,7 @@ export class Filter {
These are not keys in a JavaScript object, because we
might need to support multiple terms of the same type.
*/
- static unparse(search_terms: Term[]): string {
+ static unparse(search_terms: NarrowTerm[]): string {
const term_strings = search_terms.map((term) => {
if (term.operator === "search") {
// Search terms are the catch-all case.
@@ -447,7 +447,7 @@ export class Filter {
return term_strings.join(" ");
}
- static term_type(term: Term): string {
+ static term_type(term: NarrowTerm): string {
const operator = term.operator;
const operand = term.operand;
const negated = term.negated;
@@ -552,7 +552,7 @@ export class Filter {
}
// Convert a list of terms to a human-readable description.
- static parts_for_describe(terms: Term[]): Part[] {
+ static parts_for_describe(terms: NarrowTerm[]): Part[] {
const parts: Part[] = [];
if (terms.length === 0) {
@@ -561,7 +561,7 @@ export class Filter {
}
if (terms.length >= 2) {
- const is = (term: Term, expected: string): boolean =>
+ const is = (term: NarrowTerm, expected: string): boolean =>
term.operator === expected && !term.negated;
if (is(terms[0], "stream") && is(terms[1], "topic")) {
@@ -624,13 +624,13 @@ export class Filter {
return [...parts, ...more_parts];
}
- static search_description_as_html(terms: Term[]): string {
+ static search_description_as_html(terms: NarrowTerm[]): string {
return render_search_description({
parts: Filter.parts_for_describe(terms),
});
}
- static is_spectator_compatible(terms: Term[]): boolean {
+ static is_spectator_compatible(terms: NarrowTerm[]): boolean {
for (const term of terms) {
if (term.operand === undefined) {
return false;
@@ -649,11 +649,11 @@ export class Filter {
return this._predicate;
}
- terms(): Term[] {
+ terms(): NarrowTerm[] {
return this._terms;
}
- public_terms(): Term[] {
+ public_terms(): NarrowTerm[] {
const safe_to_return = this._terms.filter(
// Filter out the embedded narrow (if any).
(term) =>
@@ -1081,13 +1081,13 @@ export class Filter {
return true;
}
- fix_terms(terms: Term[]): Term[] {
+ fix_terms(terms: NarrowTerm[]): NarrowTerm[] {
terms = this._canonicalize_terms(terms);
terms = this._fix_redundant_is_private(terms);
return terms;
}
- _fix_redundant_is_private(terms: Term[]): Term[] {
+ _fix_redundant_is_private(terms: NarrowTerm[]): NarrowTerm[] {
if (!terms.some((term) => Filter.term_type(term) === "dm")) {
return terms;
}
@@ -1095,11 +1095,11 @@ export class Filter {
return terms.filter((term) => Filter.term_type(term) !== "is-dm");
}
- _canonicalize_terms(terms_mixed_case: Term[]): Term[] {
- return terms_mixed_case.map((term: Term) => Filter.canonicalize_term(term));
+ _canonicalize_terms(terms_mixed_case: NarrowTerm[]): NarrowTerm[] {
+ return terms_mixed_case.map((term: NarrowTerm) => Filter.canonicalize_term(term));
}
- filter_with_new_params(params: Term): Filter {
+ filter_with_new_params(params: NarrowTerm): Filter {
const terms = this._terms.map((term) => {
const new_term = {...term};
if (new_term.operator === params.operator && !new_term.negated) {
diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.ts
index 983f29f731c..77c052cddc7 100644
--- a/web/src/narrow_state.ts
+++ b/web/src/narrow_state.ts
@@ -4,7 +4,7 @@ import * as inbox_util from "./inbox_util";
import {page_params} from "./page_params";
import * as people from "./people";
import * as recent_view_util from "./recent_view_util";
-import type {Term} from "./state_data";
+import type {NarrowTerm} from "./state_data";
import * as stream_data from "./stream_data";
import type {StreamSubscription} from "./sub_store";
import * as unread from "./unread";
@@ -31,7 +31,7 @@ export function filter(): Filter | undefined {
return current_filter;
}
-export function search_terms(): Term[] {
+export function search_terms(): NarrowTerm[] {
if (current_filter === undefined) {
if (page_params.narrow !== undefined) {
return new Filter(page_params.narrow).terms();
@@ -52,7 +52,7 @@ export function update_email(user_id: number, new_email: string): void {
}
/* Search terms we should send to the server. */
-export function public_search_terms(): Term[] | undefined {
+export function public_search_terms(): NarrowTerm[] | undefined {
if (current_filter === undefined) {
return undefined;
}
@@ -65,7 +65,7 @@ export function search_string(): string {
// Collect terms which appear only once into an object,
// and discard those which appear more than once.
-function collect_single(terms: Term[]): Map<string, string> {
+function collect_single(terms: NarrowTerm[]): Map<string, string> {
const seen = new Map();
const result = new Map();
diff --git a/web/src/state_data.ts b/web/src/state_data.ts
index 84b46fa7d42..5421efb2629 100644
--- a/web/src/state_data.ts
+++ b/web/src/state_data.ts
@@ -13,12 +13,12 @@ const group_permission_setting_schema = z.object({
});
export type GroupPermissionSetting = z.output<typeof group_permission_setting_schema>;
-export const term_schema = z.object({
+export const narrow_term_schema = z.object({
negated: z.optional(z.boolean()),
operator: z.string(),
operand: z.string(),
});
-export type Term = z.output<typeof term_schema>;
+export type NarrowTerm = z.output<typeof narrow_term_schema>;
// Sync this with zerver.lib.events.do_events_register.
export const current_user_schema = z.object({