Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Use user_id instead email for user type operators.
Aman Agrawal0570e016c01b
diff --git a/web/src/activity_ui.ts b/web/src/activity_ui.tsindex d7298714a31..079309ccf0f 100644--- a/web/src/activity_ui.ts+++ b/web/src/activity_ui.ts@@ -28,10 +28,10 @@ export let user_cursor: ListCursor<number> | undefined;export let user_filter: UserSearch | undefined;// Function initialized from `ui_init` to avoid importing narrow.js and causing circular imports.-let narrow_by_email: (email: string) => void;+let narrow_by_user_id: (user_id: number) => void;-export function get_narrow_by_email_function_for_test_code(): (email: string) => void {- return narrow_by_email;+export function get_narrow_by_user_id_function_for_test_code(): (user_id: number) => void {+ return narrow_by_user_id;}function get_pm_list_item(user_id: string): JQuery | undefined {@@ -187,8 +187,8 @@ function do_update_users_for_search(): void {const update_users_for_search = _.throttle(do_update_users_for_search, 50);-export function initialize(opts: {narrow_by_email: (email: string) => void}): void {- narrow_by_email = opts.narrow_by_email;+export function initialize(opts: {narrow_by_user_id: (user_id: number) => void}): void {+ narrow_by_user_id = opts.narrow_by_user_id;set_cursor_and_filter();@@ -250,11 +250,8 @@ export function narrow_for_user(opts: {$li: JQuery}): void {}export function narrow_for_user_id(opts: {user_id: number}): void {- const person = people.get_by_user_id(opts.user_id);- const email = person.email;-- assert(narrow_by_email);- narrow_by_email(email);+ assert(narrow_by_user_id);+ narrow_by_user_id(opts.user_id);assert(user_filter !== undefined);user_filter.clear_search();}diff --git a/web/src/drafts_overlay_ui.ts b/web/src/drafts_overlay_ui.tsindex 406f2b59262..849421dad12 100644--- a/web/src/drafts_overlay_ui.ts+++ b/web/src/drafts_overlay_ui.ts@@ -98,11 +98,12 @@ function restore_draft(draft_id: string): void {}} else {if (compose_args.private_message_recipient_ids.length > 0) {- const private_message_recipient_emails =- people.user_ids_to_emails_string(compose_args.private_message_recipient_ids) ?? "";- message_view.show([{operator: "dm", operand: private_message_recipient_emails}], {- trigger: "restore draft",- });+ message_view.show(+ [{operator: "dm", operand: compose_args.private_message_recipient_ids}],+ {+ trigger: "restore draft",+ },+ );}}diff --git a/web/src/filter.ts b/web/src/filter.tsindex 47ebe03ccc2..33d6d7b03e7 100644--- a/web/src/filter.ts+++ b/web/src/filter.ts@@ -172,17 +172,14 @@ function message_matches_search_term(message: Message, term: NarrowTerm): booleareturn message.topic.toLowerCase() === term.operand.toLowerCase();case "sender":- return people.id_matches_email_operand(message.sender_id, term.operand);+ return message.sender_id === term.operand;case "dm": {- // TODO: use user_ids, not emails hereif (message.type !== "private") {return false;}- const operand_ids = people.pm_with_operand_ids(term.operand);- if (!operand_ids) {- return false;- }++ const operand_ids: number[] = people.sorted_other_user_ids(term.operand);const user_ids = people.pm_with_user_ids(message);if (!user_ids) {return false;@@ -192,10 +189,7 @@ function message_matches_search_term(message: Message, term: NarrowTerm): boolea}case "dm-including": {- const operand_ids = people.pm_with_operand_ids(term.operand);- if (!operand_ids) {- return false;- }+ const operand_ids = people.sorted_other_user_ids(term.operand);const user_ids = people.all_user_ids_in_pm(message);if (!user_ids) {return false;@@ -240,6 +234,9 @@ export class Filter {operator,operand,}: NarrowTerm): NarrowCanonicalTerm {+ // NOTE: For conversion of NarrowTermSuggestion to NarrowCanonicalTerm,+ // use `Filter.convert_suggestion_to_term` instead.+ //// Make negated explicitly default to false for both clarity and// simplifying deepEqual checks in the tests.const canonical_operator = filter_util.canonicalize_operator(operator);@@ -267,13 +264,7 @@ export class Filter {break;case "sender":case "dm":- narrow_term.operand = narrow_term.operand.toLowerCase();- if (narrow_term.operand === "me") {- narrow_term.operand = people.my_current_email();- }- break;case "dm-including":- narrow_term.operand = narrow_term.operand.toLowerCase();break;case "search":// The mac app automatically substitutes regular quotes with curly@@ -354,10 +345,14 @@ export class Filter {This is just for the search bar, not for saving thenarrow in the URL fragment. There we do use fullURI encoding to avoid problematic characters. */- static encodeOperand(operand: string, operator: string): string {- if (USER_OPERATORS.has(operator)) {- return operand.replaceAll(/[\s"%]/g, (c) => encodeURIComponent(c));+ static encodeOperand(operand: NarrowTerm["operand"]): string {+ if (typeof operand !== "string") {+ return String(operand);}++ // We assume this will never be used for user operators since they have+ // number or array operands.+ assert(typeof operand === "string");return operand.replaceAll(/[\s"%+]/g, (c) => (c === " " ? "+" : encodeURIComponent(c)));}@@ -427,7 +422,7 @@ export class Filter {}if (for_pills && operator === "sender" && operand.toLowerCase() === "me") {- operand = people.my_current_email();+ operand = String(people.my_current_user_id());}// Check if the operator is known, if not then we treat@@ -460,7 +455,7 @@ export class Filter {static convert_term_to_suggestion(term: NarrowCanonicalTerm): NarrowTermSuggestion {return {operator: term.operator,- operand: term.operand,+ operand: String(term.operand),negated: term.negated,};}@@ -468,34 +463,71 @@ export class Filter {static convert_suggestion_to_term(suggestion: NarrowTermSuggestion,): NarrowCanonicalTerm | undefined {+ // NOTE: For user operators, we assume that operand is+ // user_ids or `me`. They return `undefined` otherwise.+ //// We don't want to raise exceptions in this function; just// return undefined for invalid terms.- //- // NOTE: We will add more logic here once `NarrowTerm`- // operand has different type based on operator.+ let potential_narrow_term: NarrowCanonicalTerm;try {- switch (suggestion.operator) {+ const canonical_operator = filter_util.canonicalize_operator(suggestion.operator);+ switch (canonical_operator) {case "dm":- case "dm-including":- case "sender":- // Empty operand is invalid for these operators.- // Added here instead of `is_valid_canonical_term`- // to create better diffs for future refactoring.+ case "dm-including": {+ let operand: number[];+ if (suggestion.operand.toLowerCase() === "me") {+ operand = [people.my_current_user_id()];+ } else {+ operand = people.user_ids_string_to_ids_array(suggestion.operand);+ }+ // An empty operand is invalid for dm and dm-including.if (suggestion.operand === "") {return undefined;}- }+ potential_narrow_term = {+ operator: canonical_operator,+ operand,+ negated: suggestion.negated,+ };+ break;+ }+ case "sender": {+ let operand: number;+ if (suggestion.operand.toLowerCase() === "me") {+ operand = people.my_current_user_id();+ } else {+ operand = Number(suggestion.operand);+ }- const potential_narrow_term: NarrowCanonicalTerm = Filter.canonicalize_term(suggestion);+ if (Number.isNaN(operand)) {+ return undefined;+ }- if (!Filter.is_valid_canonical_term(potential_narrow_term)) {- return undefined;+ potential_narrow_term = {+ operator: canonical_operator,+ operand,+ negated: suggestion.negated,+ };+ break;+ }+ default:+ potential_narrow_term = {+ operator: canonical_operator,+ operand: suggestion.operand,+ negated: suggestion.negated,+ };}- return potential_narrow_term;+ potential_narrow_term = Filter.canonicalize_term(potential_narrow_term);} catch {return undefined;}++ if (!Filter.is_valid_canonical_term(potential_narrow_term)) {+ return undefined;+ }++ return potential_narrow_term;}static is_valid_canonical_term(term: NarrowCanonicalTerm): boolean {@@ -527,11 +559,10 @@ export class Filter {case "topic":return true;case "sender":+ return people.is_valid_user_id(term.operand);case "dm":case "dm-including":- return term.operand- .split(",")- .every((email) => people.get_by_email(email) !== undefined);+ return people.is_valid_user_ids(term.operand);case "search":case "":return true;@@ -569,9 +600,7 @@ export class Filter {return term.operand;}const operator = filter_util.canonicalize_operator(term.operator);- const operand = is_operator_suggestion- ? ""- : Filter.encodeOperand(term.operand, term.operator);+ const operand = is_operator_suggestion ? "" : Filter.encodeOperand(term.operand);return sign + operator + ":" + operand;});return term_strings.join(" ");@@ -689,7 +718,13 @@ export class Filter {}// Convert a list of terms to a human-readable description.- static parts_for_describe(terms: NarrowTerm[], is_operator_suggestion: boolean): Part[] {+ static parts_for_describe(+ terms: NarrowTermSuggestion[],+ is_operator_suggestion: boolean,+ ): Part[] {+ // Calling canonicalize_term on the terms is not easy here,+ // and so it's expected that callers already do those conversions,+ // and the current only callpath (generate_pills_html) does.const parts: Part[] = [];if (terms.length === 0) {@@ -698,9 +733,8 @@ export class Filter {}if (terms[0] !== undefined && terms[1] !== undefined) {- const term_0 = Filter.canonicalize_term(terms[0]);- const term_1 = Filter.canonicalize_term(terms[1]);-+ const term_0 = terms[0];+ const term_1 = terms[1];if (term_0.operator === "channel" &&!term_0.negated &&@@ -723,7 +757,6 @@ export class Filter {}const more_parts = terms.map((term): Part => {- term = Filter.canonicalize_term(term);if (term.operator === "is") {// Some operands have their own negative words, like// unresolved, rather than the default "exclude " prefix.@@ -824,7 +857,7 @@ export class Filter {}static search_description_as_html(- terms: NarrowTerm[],+ terms: NarrowTermSuggestion[],is_operator_suggestion: boolean,): string {return render_search_description({@@ -865,18 +898,16 @@ export class Filter {// We should make sure the current user is not included for// the `dm` operand for the narrow.const dm_participants = message.display_recipient- .map((user) => user.email)- .filter((user_email) => user_email !== current_user.email);+ .map((user) => user.id)+ .filter((user_id) => user_id !== current_user.user_id);// However, if the current user is the only recipient of the// message, we should include the user in the operand.if (dm_participants.length === 0) {- dm_participants.push(current_user.email);+ dm_participants.push(current_user.user_id);}- const dm_operand = dm_participants.join(",");-- return [{operator: "dm", operand: dm_operand, negated: false}, ...filtered_terms];+ return [{operator: "dm", operand: dm_participants, negated: false}, ...filtered_terms];}assert(typeof message.display_recipient === "string");@@ -951,7 +982,7 @@ export class Filter {term.operand = term.operand.toLowerCase();}- return `${term.negated ? "0" : "1"}-${term.operator}-${term.operand}`;+ return `${term.negated ? "0" : "1"}-${term.operator}-${String(term.operand)}`;});sorted_simplified_terms.sort(util.strcmp);@@ -1002,10 +1033,7 @@ export class Filter {);}- has_operand_case_insensitive(- operator: NarrowTerm["operator"],- operand: NarrowTerm["operand"],- ): boolean {+ has_operand_case_insensitive(operator: "channel" | "topic", operand: string): boolean {return this._terms.some((term) =>!term.negated &&@@ -1213,7 +1241,7 @@ export class Filter {}if (_.isEqual(term_types, ["sender", "has-reaction"]) &&- this.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ this.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {return true;}@@ -1233,7 +1261,7 @@ export class Filter {// this comes first because it has 3 term_types but is not a "complex filter"if (_.isEqual(term_types, ["sender", "search", "has-reaction"]) &&- this.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ this.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {return "/#narrow/has/reaction/sender/me";}@@ -1288,10 +1316,8 @@ export class Filter {case "dm":return ("/#narrow/dm/" +- people.emails_to_slug(- this.terms_with_operator("dm")- .map((term) => term.operand)- .join(","),+ people.user_ids_to_slug(+ this.terms_with_operator("dm").flatMap((term) => term.operand),));case "is-resolved":@@ -1303,7 +1329,7 @@ export class Filter {case "sender":return ("/#narrow/sender/" +- people.emails_to_slug(this.terms_with_operator("sender")[0]!.operand)+ people.user_ids_to_slug([this.terms_with_operator("sender")[0]!.operand]));}}@@ -1325,7 +1351,7 @@ export class Filter {if (_.isEqual(term_types, ["sender", "has-reaction"]) &&- this.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ this.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {zulip_icon = "smile";return {...context, zulip_icon};@@ -1407,22 +1433,23 @@ export class Filter {}return sub.name;}+ const ignore_missing = true;if ((term_types.length === 2 && _.isEqual(term_types, ["dm", "near"])) ||(term_types.length === 2 && _.isEqual(term_types, ["dm", "with"])) ||(term_types.length === 1 && _.isEqual(term_types, ["dm"]))) {- const emails = this.terms_with_operator("dm")[0]!.operand.split(",");- if (emails.length === 1) {- const user = people.get_by_email(emails[0]!);+ const user_ids = this.terms_with_operator("dm")[0]!.operand;+ if (user_ids.length === 1) {+ const user = people.maybe_get_user_by_id(user_ids[0]!, ignore_missing);if (user && people.is_direct_message_conversation_with_self([user.user_id])) {return $t({defaultMessage: "Messages with yourself"});}}- const names = emails.map((email) => {- const person = people.get_by_email(email);+ const names = user_ids.map((user_id) => {+ const person = people.maybe_get_user_by_id(user_id, ignore_missing);if (!person) {- return email;+ return $t({defaultMessage: "Unknown user ({user_id})"}, {user_id});}if (muted_users.is_user_muted(person.user_id)) {if (people.should_add_guest_user_indicator(person.user_id)) {@@ -1440,8 +1467,8 @@ export class Filter {return util.format_array_as_list(names, "long", "conjunction");}if (term_types.length === 1 && _.isEqual(term_types, ["sender"])) {- const email = this.terms_with_operator("sender")[0]!.operand;- const user = people.get_by_email(email);+ const user_id = this.terms_with_operator("sender")[0]!.operand;+ const user = people.maybe_get_user_by_id(user_id, ignore_missing);if (user === undefined) {return $t({defaultMessage: "Messages sent by unknown user"});}@@ -1499,7 +1526,7 @@ export class Filter {}if (_.isEqual(term_types, ["sender", "has-reaction"]) &&- this.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ this.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {return $t({defaultMessage: "Reactions"});}@@ -1532,7 +1559,7 @@ export class Filter {}if (_.isEqual(term_types, ["sender", "has-reaction"]) &&- this.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ this.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {return {description: $t({@@ -1694,21 +1721,6 @@ export class Filter {return first_id;}- update_email(user_id: number, new_email: string): void {- for (const term of this._terms) {- switch (term.operator) {- case "dm-including":- case "dm":- case "sender":- term.operand = people.update_email_in_reply_to(- term.operand,- user_id,- new_email,- );- }- }- }-// Build a filter function from a list of operators._build_predicate(): (message: Message) => boolean {const terms = this._terms;diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex 1b1495ce23b..399a86b99b0 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -17,13 +17,14 @@ import {narrow_operator_schema,realm,} from "./state_data.ts";-import type {NarrowCanonicalTerm} from "./state_data.ts";+import type {NarrowCanonicalOperator, NarrowCanonicalTerm, NarrowTerm} from "./state_data.ts";import * as stream_data from "./stream_data.ts";import * as sub_store from "./sub_store.ts";import type {StreamSubscription} from "./sub_store.ts";import * as user_groups from "./user_groups.ts";import type {UserGroup} from "./user_groups.ts";import {user_settings} from "./user_settings.ts";+import * as util from "./util.ts";export function get_reload_hash(): string {let hash = window.location.hash;@@ -38,16 +39,16 @@ export function encode_operand(term: NarrowCanonicalTerm): string {switch (term.operator) {case "dm-including":case "dm":+ slug = people.user_ids_to_slug(term.operand);+ break;case "sender":- slug = people.emails_to_slug(term.operand);+ slug = people.user_ids_to_slug([term.operand]);break;- case "channel": {- const stream_id = Number.parseInt(term.operand, 10);- slug = encode_stream_id(stream_id);- }+ case "channel":+ return encode_stream_id(Number.parseInt(term.operand, 10));}- return slug ?? internal_url.encodeHashComponent(term.operand);+ return slug ?? internal_url.encodeHashComponent(String(term.operand));}export function encode_stream_id(stream_id: number): string {@@ -59,23 +60,31 @@ export function encode_stream_id(stream_id: number): string {}export function decode_operand(- operator: NarrowCanonicalTerm["operator"],- operand: NarrowCanonicalTerm["operand"],-): string {- if (operand === "me" && (operator === "dm" || operator === "sender")) {- return people.my_current_email();+ operator: NarrowCanonicalOperator,+ operand: string,+): NarrowTerm["operand"] {+ if (operand === "me") {+ switch (operator) {+ case "sender":+ return people.my_current_user_id();+ case "dm":+ return [people.my_current_user_id()];+ }}- if (operator === "dm-including" || operator === "dm" || operator === "sender") {- const emails = people.slug_to_emails(operand);- if (emails) {- if (operator === "sender") {- assert(!emails.includes(","), "Sender operand should not be a group");- }- return emails;+ if (operator === "dm-including" || operator === "dm") {+ const user_ids = people.slug_to_user_ids(operand);+ if (user_ids) {+ return user_ids;}}+ if (operator === "sender") {+ const user_ids = people.slug_to_user_ids(operand);+ assert(user_ids?.length === 1, "Sender operand should not be a group");+ return util.the(user_ids);+ }+operand = internal_url.decodeHashComponent(operand);if (operator === "channel") {@@ -135,8 +144,8 @@ export function search_terms_to_hash(terms?: NarrowCanonicalTerm[]): string {return hash;}-export function by_sender_url(reply_to: string): string {- return search_terms_to_hash([{operator: "sender", operand: reply_to}]);+export function by_sender_url(user_id: number): string {+ return search_terms_to_hash([{operator: "sender", operand: user_id}]);}export function pm_with_url(user_ids_string: string): string {@@ -376,11 +385,8 @@ export function decode_dm_recipient_user_ids_from_narrow_url(narrow_url: string)return null;}- if (people.is_valid_bulk_emails_for_compose(first_term.operand.split(","))) {- const user_ids = people.emails_strings_to_user_ids_array(first_term.operand);- if (!user_ids) {- return null;- }+ const user_ids = first_term.operand;+ if (people.is_valid_bulk_user_ids_for_compose(user_ids, true)) {return user_ids;}return null;diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.tsindex ac619a02a8a..81827d32081 100644--- a/web/src/left_sidebar_navigation_area.ts+++ b/web/src/left_sidebar_navigation_area.ts@@ -111,7 +111,7 @@ export function rewire_select_top_left_corner_item(export function handle_narrow_activated(filter: Filter): void {let terms: NarrowTerm[];- let filter_name: string;+ let filter_name: NarrowTerm["operand"];// TODO: handle confused filters like "in:all stream:foo"terms = filter.terms_with_operator("in");@@ -136,7 +136,7 @@ export function handle_narrow_activated(filter: Filter): void {const term_types = filter.sorted_term_types();if (_.isEqual(term_types, ["sender", "has-reaction"]) &&- filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ filter.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {select_top_left_corner_item(".top_left_my_reactions");return;diff --git a/web/src/message_feed_top_notices.ts b/web/src/message_feed_top_notices.tsindex 68f2b6daef2..b46ed4f01ff 100644--- a/web/src/message_feed_top_notices.ts+++ b/web/src/message_feed_top_notices.ts@@ -59,7 +59,7 @@ export function update_top_of_narrow_notices(msg_list: MessageList): void {!filter.is_personal_filter() &&!(_.isEqual(filter._sorted_term_types, ["sender", "has-reaction"]) &&- filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ filter.terms_with_operator("sender")[0]!.operand === people.my_current_user_id())) {show_end_of_results_notice();diff --git a/web/src/message_fetch.ts b/web/src/message_fetch.tsindex a7d5b7c44ba..601e24b9826 100644--- a/web/src/message_fetch.ts+++ b/web/src/message_fetch.ts@@ -22,7 +22,6 @@ import * as message_util from "./message_util.ts";import * as message_viewport from "./message_viewport.ts";import * as narrow_banner from "./narrow_banner.ts";import {page_params} from "./page_params.ts";-import * as people from "./people.ts";import * as popup_banners from "./popup_banners.ts";import * as recent_view_ui from "./recent_view_ui.ts";import {narrow_operator_schema} from "./state_data.ts";@@ -254,20 +253,13 @@ function get_messages_success(data: MessageFetchResponse, opts: MessageFetchOpti}// This function modifies the narrow data to use integer IDs instead of-// strings if it is supported for that operator. We currently don't set-// or convert user emails to IDs directly in the Filter code because-// doing so breaks the app in various modules that expect a string of-// user emails.+// strings if it is supported for that operator.function handle_operators_supporting_id_based_api(narrow_parameter: string): string {- // We use the canonical operator when checking these sets, so legacy- // operators, such as "pm-with" and "stream", are not included here.- const operators_supporting_ids = new Set(["dm"]);- const operators_supporting_id = new Set(["id", "channel", "sender", "dm-including"]);const raw_narrow_term_array_schema = z.array(z.object({negated: z.optional(z.boolean()),operator: z.string(),- operand: z.string(),+ operand: z.union([z.number(), z.string(), z.array(z.number())]),}),);const parsed_narrow_data = raw_narrow_term_array_schema.parse(JSON.parse(narrow_parameter));@@ -292,40 +284,16 @@ function handle_operators_supporting_id_based_api(narrow_parameter: string): strraw_term.operator.toLowerCase(),);const canonical_operator = filter_util.canonicalize_operator(parsed_narrow_operator);-- if (operators_supporting_ids.has(canonical_operator)) {- const user_ids_array = people.emails_strings_to_user_ids_array(raw_term.operand);- assert(user_ids_array !== undefined);- narrow_term.operand = user_ids_array;- }-- if (operators_supporting_id.has(canonical_operator)) {- if (canonical_operator === "id") {- // The message ID may not exist locally,- // so send the term to the server as is.- narrow_terms.push(narrow_term);- continue;- }-- if (canonical_operator === "channel") {- // An unknown channel will have an empty string set for- // the operand. And the page_params.narrow may have a- // channel name as the operand. But all other cases- // should have the channel ID set as the string value- // for the operand.- const stream = stream_data.get_sub_by_id_string(raw_term.operand);- if (stream !== undefined) {- narrow_term.operand = stream.stream_id;- }- narrow_terms.push(narrow_term);- continue;- }-- // The other operands supporting integer IDs all work with- // a single user object.- const person = people.get_by_email(raw_term.operand);- if (person !== undefined) {- narrow_term.operand = person.user_id;+ // TODO: Migrate `channel` to use `number` operand so that we can avoid this conversion.+ if (canonical_operator === "channel" && typeof raw_term.operand === "string") {+ // An unknown channel will have an empty string set for+ // the operand. And the page_params.narrow may have a+ // channel name as the operand. But all other cases+ // should have the channel ID set as the string value+ // for the operand.+ const stream = stream_data.get_sub_by_id_string(raw_term.operand);+ if (stream !== undefined) {+ narrow_term.operand = stream.stream_id;}}narrow_terms.push(narrow_term);@@ -335,10 +303,16 @@ function handle_operators_supporting_id_based_api(narrow_parameter: string): str}export function get_narrow_for_message_fetch(filter: Filter): string {- let narrow_data: NarrowTerm[] = [];+ // narrow_data is different from `NarrowTerm[]` because we+ // expand `dm-including` operators into multiple terms here.+ let narrow_data: {+ operator: NarrowTerm["operator"];+ operand: NarrowTerm["operand"];+ negated?: boolean | undefined;+ }[] = [];for (const term of filter.public_terms()) {if (term.operator === "dm-including") {- for (const operand of term.operand.split(",")) {+ for (const operand of term.operand) {narrow_data.push({...term,operand,diff --git a/web/src/message_util.ts b/web/src/message_util.tsindex 8c7e20aaaf4..a4fb4722587 100644--- a/web/src/message_util.ts+++ b/web/src/message_util.ts@@ -94,7 +94,7 @@ export function get_direct_message_permission_hints(const dm_conversation =message_lists.current?.data?.filter.terms_with_operator("dm")[0]?.operand;if (dm_conversation) {- const current_user_ids_string = people.emails_strings_to_user_ids_string(dm_conversation);+ const current_user_ids_string = dm_conversation.join(",");assert(current_user_ids_string !== undefined);// If it matches and the messages for the current filter are fetched,// then there are certainly no messages in the conversation.diff --git a/web/src/message_view.ts b/web/src/message_view.tsindex 3f8ff9df855..9982fae81d8 100644--- a/web/src/message_view.ts+++ b/web/src/message_view.ts@@ -1407,9 +1407,7 @@ export function narrow_to_next_pm_string(opts = {}): void {return;}- // Hopefully someday we can narrow by user_ids_string instead of- // mapping back to emails.- const direct_message = people.user_ids_string_to_emails_string(next_direct_message);+ const direct_message = people.user_ids_string_to_ids_array(next_direct_message);assert(direct_message !== undefined);const filter_expr: NarrowTerm[] = [{operator: "dm", operand: direct_message}];@@ -1467,8 +1465,6 @@ export function narrow_by_recipient(// don't use message_lists.current as it won't work for muted messages or for out-of-narrow linksconst message = message_store.get(target_id);assert(message !== undefined);- const emails = message.reply_to.split(",");- const reply_to = people.sort_emails_by_username(emails);switch (message.type) {case "private":@@ -1482,7 +1478,16 @@ export function narrow_by_recipient(// in the new view.unread_ops.notify_server_message_read(message);}- show([{operator: "dm", operand: reply_to.join(",")}], show_opts);++ show(+ [+ {+ operator: "dm",+ operand: people.user_ids_string_to_ids_array(message.to_user_ids),+ },+ ],+ show_opts,+ );break;case "stream":@@ -1537,16 +1542,14 @@ export function to_compose_target(): void {}if (compose_state.get_message_type() === "private") {- const recipient_string = compose_state.private_message_recipient_emails();- const emails = util.extract_pm_recipients(recipient_string);- const invalid = emails.filter((email) => !people.is_valid_email_for_compose(email));+ const recipient_ids = compose_state.private_message_recipient_ids();// If there are no recipients or any recipient is// invalid, narrow to your direct message feed.- if (emails.length === 0 || invalid.length > 0) {+ if (recipient_ids.length === 0 || !people.is_valid_user_ids(recipient_ids)) {show([{operator: "is", operand: "dm"}], opts);return;}- show([{operator: "dm", operand: util.normalize_recipients(recipient_string)}], opts);+ show([{operator: "dm", operand: recipient_ids}], opts);}}@@ -1606,7 +1609,10 @@ export function narrow_to_message_near(message: Message, trigger: string): voidcase "private":show([- {operator: "dm", operand: message.reply_to},+ {+ operator: "dm",+ operand: people.user_ids_string_to_ids_array(message.to_user_ids),+ },{operator: "near", operand: String(message.id)},],{trigger},diff --git a/web/src/narrow_banner.ts b/web/src/narrow_banner.tsindex f7c4156def0..70b0615bfe6 100644--- a/web/src/narrow_banner.ts+++ b/web/src/narrow_banner.ts@@ -231,7 +231,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDaif (_.isEqual(current_terms_types, ["sender", "has-reaction"]) &&- current_filter.terms_with_operator("sender")[0]!.operand === people.my_current_email()+ current_filter.terms_with_operator("sender")[0]!.operand === people.my_current_user_id()) {return {title: $t({defaultMessage: "None of your messages have emoji reactions yet."}),@@ -349,8 +349,8 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDareturn empty_search_query_banner(current_filter);}case "dm": {- if (!people.is_valid_bulk_emails_for_compose(first_term.operand.split(","))) {- if (!first_term.operand.includes(",")) {+ if (!people.is_valid_bulk_user_ids_for_compose(first_term.operand, true)) {+ if (first_term.operand.length === 1) {return {title: $t({defaultMessage: "This user does not exist!"}),};@@ -359,7 +359,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDatitle: $t({defaultMessage: "One or more of these users do not exist!"}),};}- const user_ids = people.emails_strings_to_user_ids_array(first_term.operand);+ const user_ids = first_term.operand;assert(user_ids?.[0] !== undefined);const user_ids_string = util.sorted_ids(user_ids).join(",");const direct_message_error_string =@@ -378,7 +378,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa),};}- if (!first_term.operand.includes(",")) {+ if (user_ids.length === 1) {const recipient_user = people.get_by_user_id(user_ids[0]);// You have no direct messages with this personif (people.is_my_user_id(recipient_user.user_id)) {@@ -444,7 +444,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa};}case "sender": {- const sender = people.get_by_email(first_term.operand);+ const sender = people.maybe_get_user_by_id(first_term.operand, true);if (sender) {return {title: $t(@@ -464,9 +464,9 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa};}case "dm-including": {- const people_in_dms = first_term.operand- .split(",")- .map((email) => people.get_by_email(email));+ const people_in_dms = first_term.operand.map((user_id) =>+ people.maybe_get_user_by_id(user_id, true),+ );if (people_in_dms.length === 1 && !people_in_dms[0]) {return {title: $t({defaultMessage: "This user does not exist!"}),diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.tsindex 57a4c2df3d6..c171461b1fe 100644--- a/web/src/narrow_state.ts+++ b/web/src/narrow_state.ts@@ -55,16 +55,6 @@ export function is_message_feed_visible(): boolean {return message_lists.current !== undefined;}-export function update_email(- user_id: number,- new_email: string,- current_filter: Filter | undefined = filter(),-): void {- if (current_filter !== undefined) {- current_filter.update_email(user_id, new_email);- }-}-/* Search terms we should send to the server. */export function public_search_terms(current_filter: Filter | undefined = filter(),@@ -127,14 +117,12 @@ export function set_compose_defaults(): {}const dm_term = single.get("dm");- const private_message_recipient_emails = dm_term?.operand;if (- private_message_recipient_emails !== undefined &&- people.is_valid_bulk_emails_for_compose(private_message_recipient_emails.split(","))+ // Check for typescript to understand operand type.+ dm_term?.operator === "dm" &&+ people.is_valid_bulk_user_ids_for_compose(dm_term.operand, true)) {- opts.private_message_recipient_ids = people.emails_string_to_user_ids(- private_message_recipient_emails,- );+ opts.private_message_recipient_ids = dm_term.operand;}return opts;}@@ -196,7 +184,7 @@ export function topic(current_filter: Filter | undefined = filter()): string | ureturn undefined;}-export function pm_ids_string(current_filter: Filter | undefined = filter()): string | undefined {+export function pm_ids(current_filter: Filter | undefined = filter()): number[] | undefined {if (current_filter === undefined) {return undefined;}@@ -207,17 +195,24 @@ export function pm_ids_string(current_filter: Filter | undefined = filter()): st}// If you are narrowed to a group direct message with users 4, 5, and 99,- // this will return "4,5,99". Will return undefined when the value of the- // operand string does not translate to a comma-separated list of valid- // user emails.- const emails_string = util.the(terms).operand;- return people.reply_to_to_user_ids_string(emails_string);+ // this will return [4,5,99].+ const user_ids = util.the(terms).operand;+ if (user_ids.length === 0 || !people.is_valid_user_ids(user_ids)) {+ return undefined;+ }++ return util.the(terms).operand;+}++export function pm_ids_string(current_filter: Filter | undefined = filter()): string | undefined {+ const ids = pm_ids(current_filter);++ return ids ? String(ids) : undefined;}export function pm_ids_set(filter?: Filter): Set<number> {- const ids_string = pm_ids_string(filter);- const pm_ids_list = ids_string ? people.user_ids_string_to_ids_array(ids_string) : [];- return new Set(pm_ids_list);+ const ids = pm_ids(filter) ?? [];+ return new Set(ids);}// We expect get_first_unread_info and therefore _possible_unread_message_idsdiff --git a/web/src/narrow_title.ts b/web/src/narrow_title.tsindex 6eb89548045..d90f19cce8d 100644--- a/web/src/narrow_title.ts+++ b/web/src/narrow_title.ts@@ -52,13 +52,13 @@ export function compute_narrow_title(filter?: Filter): string {}if (filter.has_operator("dm")) {- const emails = filter.terms_with_operator("dm")[0]!.operand;- const user_ids = people.reply_to_to_user_ids_string(emails);+ const user_ids = filter.terms_with_operator("dm")[0]!.operand;- if (user_ids !== undefined) {- return people.format_recipients(user_ids, "long");+ if (people.is_valid_user_ids(user_ids)) {+ return people.format_recipients(String(user_ids), "long");}- if (emails.includes(",")) {++ if (user_ids.length > 1) {return $t({defaultMessage: "Invalid users"});}return $t({defaultMessage: "Invalid user"});diff --git a/web/src/onboarding_steps.ts b/web/src/onboarding_steps.tsindex 4f4ed163c58..f32e1ffdfb4 100644--- a/web/src/onboarding_steps.ts+++ b/web/src/onboarding_steps.ts@@ -84,7 +84,7 @@ function narrow_to_dm_with_welcome_bot_new_user([{operator: "dm",- operand: people.WELCOME_BOT.email,+ operand: [people.WELCOME_BOT.user_id],},],{trigger: "sidebar"},diff --git a/web/src/people.ts b/web/src/people.tsindex 12cf485be18..eb05af74e95 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -227,19 +227,6 @@ export function can_admin_user(user: User): boolean {);}-export function id_matches_email_operand(user_id: number, email: string): boolean {- const person = get_by_email(email);-- if (!person) {- // The user may type bad data into the search bar, so- // we don't complain too loud here.- blueslip.debug("User email operand unknown: " + email);- return false;- }-- return person.user_id === user_id;-}-export function update_email(user_id: number, new_email: string): void {const person = get_by_user_id(user_id);person.email = new_email;@@ -758,29 +745,6 @@ export function update_email_in_reply_to(return emails.join(",");}-export function pm_with_operand_ids(operand: string): number[] | undefined {- let emails = operand.split(",");- emails = emails.map((email) => email.trim());- let persons = util.try_parse_as_truthy(emails.map((email) => people_dict.get(email)));-- if (persons === undefined) {- return undefined;- }-- // If your email is included in a group direct message with other people,- // then ignore it.- if (persons.length > 1) {- const my_user = people_by_user_id_dict.get(my_user_id);- persons = persons.filter((person) => person !== my_user);- }-- let user_ids = persons.map((person) => person.user_id);-- user_ids = util.sorted_ids(user_ids);-- return user_ids;-}-export function filter_other_guest_ids(user_ids: number[]): number[] {return util.sorted_ids(user_ids.filter((id) => id !== current_user.user_id && get_by_user_id(id)?.is_guest),@@ -793,30 +757,8 @@ export function user_ids_to_full_names_array(user_ids: number[]): string[] {return names;}-export function emails_to_slug(emails_string: string): string | undefined {- let slug = reply_to_to_user_ids_string(emails_string);-- if (!slug) {- return undefined;- }-- slug += "-";-- const emails = emails_string.split(",");-- if (emails.length === 1 && emails[0] !== undefined) {- const person = get_by_email(emails[0]);- assert(person !== undefined, "Unknown person in emails_to_slug");- slug += get_slug_from_full_name(person.full_name);- } else {- slug += "group";- }-- return slug;-}-export function user_ids_to_slug(user_ids: number[]): string | undefined {- if (user_ids.length === 0) {+ if (user_ids.length === 0 || !is_valid_user_ids(user_ids)) {return undefined;}@@ -837,7 +779,7 @@ export function user_ids_string_to_slug(user_ids_string: string): string | undefreturn user_ids_to_slug(user_ids);}-export function slug_to_emails(slug: string): string | undefined {+export function slug_to_user_ids(slug: string): number[] | undefined {/*It's not super important to be flexible aboutdirect message related slugs, since you would@@ -852,29 +794,27 @@ export function slug_to_emails(slug: string): string | undefined {*/const m = /^([\d,]+)(-.*)?/.exec(slug);if (m) {- let user_ids_string = m[1]!;- user_ids_string = exclude_me_from_string(user_ids_string);- return user_ids_string_to_emails_string(user_ids_string);+ const user_ids_string = m[1]!;+ return exclude_me_from_user_ids(split_to_ints(user_ids_string));}/* istanbul ignore next */return undefined;}-export function exclude_me_from_string(user_ids_string: string): string {+export function exclude_me_from_user_ids(user_ids: number[]): number[] {// Exclude me from a user_ids_string UNLESS I'm the// only one in it.- let user_ids = split_to_ints(user_ids_string);if (user_ids.length <= 1) {// We either have a message to ourself, an empty// slug, or a message to somebody else where we weren't// part of the slug.- return user_ids.join(",");+ return user_ids;}user_ids = user_ids.filter((user_id) => !is_my_user_id(user_id));- return user_ids.join(",");+ return user_ids;}export function sender_is_bot(message: Message): boolean {@@ -1063,12 +1003,12 @@ export function get_muted_user_avatar_url(): string {return "/static/images/muted-user/muted-sender.png";}-export function is_valid_user_id_for_compose(user_id: number): boolean {+export function is_valid_user_id_for_compose(user_id: number, ignore_missing = false): boolean {if (cross_realm_dict.has(user_id)) {return true;}- const person = maybe_get_user_by_id(user_id);+ const person = maybe_get_user_by_id(user_id, ignore_missing);if (!person || person.is_inaccessible_user) {return false;}@@ -1103,10 +1043,13 @@ export function is_valid_bulk_emails_for_compose(emails: string[]): boolean {});}-export function is_valid_bulk_user_ids_for_compose(user_ids: number[]): boolean {+export function is_valid_bulk_user_ids_for_compose(+ user_ids: number[],+ ignore_missing = true,+): boolean {// Returns false if at least one of the user_ids is invalid.return user_ids.every((user_id) => {- if (!is_valid_user_id_for_compose(user_id)) {+ if (!is_valid_user_id_for_compose(user_id, ignore_missing)) {return false;}return true;diff --git a/web/src/personal_menu_popover.ts b/web/src/personal_menu_popover.tsindex 70516ac703b..2c0f21b983b 100644--- a/web/src/personal_menu_popover.ts+++ b/web/src/personal_menu_popover.ts@@ -5,7 +5,6 @@ import render_navbar_personal_menu_popover from "../templates/popovers/navbar/naimport * as channel from "./channel.ts";import * as information_density from "./information_density.ts";import * as message_view from "./message_view.ts";-import * as people from "./people.ts";import * as popover_menus from "./popover_menus.ts";import * as popover_menus_data from "./popover_menus_data.ts";import * as popovers from "./popovers.ts";@@ -71,12 +70,11 @@ export function initialize(): void {$popper.one("click", ".narrow-self-direct-message", (e) => {const user_id = current_user.user_id;- const email = people.get_by_user_id(user_id).email;message_view.show([{operator: "dm",- operand: email,+ operand: [user_id],},],{trigger: "personal menu"},@@ -87,12 +85,11 @@ export function initialize(): void {$popper.one("click", ".narrow-messages-sent", (e) => {const user_id = current_user.user_id;- const email = people.get_by_user_id(user_id).email;message_view.show([{operator: "sender",- operand: email,+ operand: user_id,},],{trigger: "personal menu"},diff --git a/web/src/pm_list_data.ts b/web/src/pm_list_data.tsindex b8b156718a4..f2753feec85 100644--- a/web/src/pm_list_data.ts+++ b/web/src/pm_list_data.ts@@ -1,3 +1,4 @@+import * as blueslip from "./blueslip.ts";import * as buddy_data from "./buddy_data.ts";import * as hash_util from "./hash_util.ts";import * as narrow_state from "./narrow_state.ts";@@ -20,17 +21,18 @@ export function get_active_user_ids_string(): string | undefined {return undefined;}- const emails = filter.terms_with_operator("dm")[0]?.operand;+ const user_ids = filter.terms_with_operator("dm")[0]?.operand;- if (!emails) {+ if (!user_ids || user_ids.length === 0) {return undefined;}- const users_ids_array = people.emails_strings_to_user_ids_array(emails);- if (!users_ids_array || users_ids_array.length === 0) {+ if (!people.is_valid_user_ids(user_ids)) {+ blueslip.warn("Invalid user_ids", {user_ids});return undefined;}- return people.sorted_other_user_ids(users_ids_array).join(",");++ return people.sorted_other_user_ids(user_ids).join(",");}export type DisplayObject = {diff --git a/web/src/scheduled_messages_ui.ts b/web/src/scheduled_messages_ui.tsindex 31e5773f791..bde71703182 100644--- a/web/src/scheduled_messages_ui.ts+++ b/web/src/scheduled_messages_ui.ts@@ -21,7 +21,7 @@ type ScheduledMessageComposeArgs =}| {message_type: "private";- private_message_recipient: string;+ private_message_recipient_ids: number[];content: string;keep_composebox_empty: boolean;};@@ -45,7 +45,8 @@ function narrow_via_edit_scheduled_message(compose_args: ScheduledMessageCompose{trigger: "edit scheduled message"},);} else {- message_view.show([{operator: "dm", operand: compose_args.private_message_recipient}], {+ const user_ids = compose_args.private_message_recipient_ids;+ message_view.show([{operator: "dm", operand: user_ids}], {trigger: "edit scheduled message",});}@@ -56,7 +57,6 @@ export function open_scheduled_message_in_compose(should_narrow_to_recipient?: boolean,): void {let compose_args;- let narrow_args;if (scheduled_message.type === "stream") {compose_args = {@@ -65,32 +65,20 @@ export function open_scheduled_message_in_compose(topic: scheduled_message.topic,content: scheduled_message.content,};- narrow_args = compose_args;} else {const recipient_ids = scheduled_message.to.filter((recipient_id) => !people.get_by_user_id(recipient_id).is_inaccessible_user,);- const recipient_emails = recipient_ids.map(- (recipient_id) => people.get_by_user_id(recipient_id).email,- );compose_args = {message_type: "private" as const,private_message_recipient_ids: recipient_ids,content: scheduled_message.content,keep_composebox_empty: true,};- // Narrow filters still use emails for PMs, though we'll- // eventually want to migrate that as well.- narrow_args = {- message_type: "private" as const,- private_message_recipient: recipient_emails.join(","),- content: scheduled_message.content,- keep_composebox_empty: true,- };}if (should_narrow_to_recipient) {- narrow_via_edit_scheduled_message(narrow_args);+ narrow_via_edit_scheduled_message(compose_args);}compose_actions.start(compose_args);diff --git a/web/src/search_pill.ts b/web/src/search_pill.tsindex f59a628d240..9731e96ec05 100644--- a/web/src/search_pill.ts+++ b/web/src/search_pill.ts@@ -13,7 +13,6 @@ import * as people from "./people.ts";import type {User} from "./people.ts";import {type Suggestion, search_term_description_html} from "./search_suggestion.ts";import type {NarrowCanonicalTerm, NarrowTermSuggestion} from "./state_data.ts";-import * as state_data from "./state_data.ts";import * as stream_data from "./stream_data.ts";import * as user_status from "./user_status.ts";import type {UserStatusEmojiInfo} from "./user_status.ts";@@ -56,8 +55,29 @@ export function create_item_from_search_string(search_string: string): SearchPil}export function get_search_string_from_item(item: SearchPill): string {+ let operand: string;+ switch (item.operator) {+ case "dm":+ case "dm-including":+ case "sender":+ assert(item.type === "search_user");+ operand = item.users.map((user) => user.email).join(",");+ break;+ case "topic":+ operand = util.get_final_topic_display_name(item.operand);+ break;+ case "channel":+ if (item.operand === "") {+ operand = "";+ }+ operand = stream_data.get_valid_sub_by_id_string(item.operand).name;+ break;+ default:+ operand = item.operand;+ }+const sign = item.negated ? "-" : "";- return `${sign}${item.operator}: ${get_search_operand(item, true)}`;+ return `${sign}${item.operator}: ${operand}`;}// This is called when the a pill is closed. We have custom logic here@@ -257,20 +277,28 @@ export function create_pills($pill_container: JQuery): SearchPillWidget {split_text_on_comma: false,convert_to_pill_on_enter: false,generate_pill_html(item) {- if (item.type === "search_user") {- return render_search_user_pill(item);- }- if (item.operator === "topic" && item.operand === "") {- return render_input_pill({- is_empty_string_topic: true,- sign: item.negated ? "-" : "",- topic_display_name: util.get_final_topic_display_name(""),- });+ switch (item.operator) {+ case "dm":+ case "dm-including":+ case "sender":+ assert(item.type === "search_user");+ return render_search_user_pill(item);+ case "topic":+ if (item.operand === "") {+ return render_input_pill({+ is_empty_string_topic: true,+ sign: item.negated ? "-" : "",+ topic_display_name: util.get_final_topic_display_name(""),+ });+ }+ return render_input_pill({+ display_value: get_search_string_from_item(item),+ });+ default:+ return render_input_pill({+ display_value: get_search_string_from_item(item),+ });}- const display_value = get_search_string_from_item(item);- return render_input_pill({- display_value,- });},get_display_value_from_item: get_search_string_from_item,on_pill_exit,@@ -281,16 +309,21 @@ export function create_pills($pill_container: JQuery): SearchPillWidget {return pills;}+function get_user_ids_from_term_with_user_pill_operator(term: NarrowCanonicalTerm): number[] {+ if (term.operator === "sender") {+ return [term.operand];+ }++ assert(term.operator === "dm" || term.operator === "dm-including");+ return term.operand;+}+function search_user_pill_data_from_term(term: NarrowCanonicalTerm): SearchUserPill {assert(term.operator === "dm" || term.operator === "dm-including" || term.operator === "sender",);- const emails = term.operand.split(",");- const users = emails.map((email) => {- const person = people.get_by_email(email);- assert(person !== undefined);- return person;- });+ const user_ids = get_user_ids_from_term_with_user_pill_operator(term);+ const users = user_ids.map((user_id) => people.get_by_user_id(user_id));return search_user_pill_data(users, term.operator, term.negated ?? false);}@@ -298,7 +331,7 @@ function is_sent_by_me_pill(pill: SearchUserPill): boolean {return (pill.operator === "sender" &&pill.users.length === 1 &&- util.the(pill.users).email === state_data.current_user.email+ util.the(pill.users).user_id === people.my_current_user_id());}@@ -372,7 +405,8 @@ export function set_search_bar_contents(continue;}- if (Filter.convert_suggestion_to_term(term) === undefined) {+ const narrow_term = Filter.convert_suggestion_to_term(term);+ if (narrow_term === undefined) {invalid_inputs.push(input);continue;}@@ -381,12 +415,8 @@ export function set_search_bar_contents(case "dm":case "dm-including":case "sender": {- const users = term.operand.split(",").map((email) => {- // This is definitely not undefined, because we just validated it- // with `Filter.is_valid_search_term`.- const user = people.get_by_email(email)!;- return user;- });+ const user_ids = get_user_ids_from_term_with_user_pill_operator(narrow_term);+ const users = user_ids.map((user_id) => people.get_by_user_id(user_id));append_user_pill(users, pill_widget, term.operator, term.negated ?? false);added_pills_as_input_strings.add(input);break;@@ -413,31 +443,32 @@ export function set_search_bar_contents(}}-function get_search_operand(item: SearchPill, for_display: boolean): string {- if (item.type === "search_user") {- return item.users.map((user) => user.email).join(",");- }- // When we're displaying the operand in a pill, we sometimes want to make- // it more human readable. We do this for channel pills (with channels- // specified) and topic pills only.- if (for_display) {- if (item.operator === "channel" && item.operand !== "") {- return stream_data.get_valid_sub_by_id_string(item.operand).name;- }- if (item.operator === "topic") {- return util.get_final_topic_display_name(item.operand);- }- // For all other `for_display=true` cases, we just show the default operand.- }- return item.operand;-}-export function get_current_search_pill_terms(pill_widget: SearchPillWidget,): NarrowCanonicalTerm[] {- return pill_widget.items().map((item) => ({- operator: item.operator,- operand: get_search_operand(item, false),- negated: item.negated,- }));+ return pill_widget.items().map((item) => {+ switch (item.operator) {+ case "dm":+ case "dm-including":+ assert(item.type === "search_user");+ return {+ operator: item.operator,+ operand: item.users.map((user) => user.user_id),+ negated: item.negated,+ };+ case "sender":+ assert(item.type === "search_user");+ return {+ operator: item.operator,+ operand: item.users[0]!.user_id,+ negated: item.negated,+ };+ default:+ return {+ operator: item.operator,+ operand: item.operand,+ negated: item.negated,+ };+ }+ });}diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.tsindex 627c89e31d4..9d82ddef1f3 100644--- a/web/src/search_suggestion.ts+++ b/web/src/search_suggestion.ts@@ -185,19 +185,16 @@ function check_validity(return true;}-function format_as_suggestion(terms: NarrowTerm[]): Suggestion {+function format_as_suggestion(terms: NarrowTerm[], is_operator_suggestion = false): Suggestion {return {- search_string: Filter.unparse(terms),+ search_string: Filter.unparse(terms, is_operator_suggestion),};}function compare_by_direct_message_group(- direct_message_group_emails: string[],+ valid_user_ids: number[],): (person1: User, person2: User) => number {- const user_ids = direct_message_group_emails.slice(0, -1).flatMap((person) => {- const user = people.get_by_email(person);- return user?.user_id ?? [];- });+ assert(people.is_valid_user_ids(valid_user_ids));// Construct dict for all direct message groups, so we can// look up each's recencyconst direct_message_groups = direct_message_group_data.get_direct_message_groups();@@ -207,8 +204,14 @@ function compare_by_direct_message_group(}return function (person1: User, person2: User): number {- const direct_message_group1 = people.concat_direct_message_group(user_ids, person1.user_id);- const direct_message_group2 = people.concat_direct_message_group(user_ids, person2.user_id);+ const direct_message_group1 = people.concat_direct_message_group(+ valid_user_ids,+ person1.user_id,+ );+ const direct_message_group2 = people.concat_direct_message_group(+ valid_user_ids,+ person2.user_id,+ );// If not in the dict, assign an arbitrarily high indexconst score1 =direct_message_group_dict.get(direct_message_group1) ??@@ -279,75 +282,51 @@ function get_group_suggestions(}assert(last_complete_term.operator === group_operator);+ let new_query: string;+ let existing_user_ids: number[];+// If they started typing since a user pill, we'll parse that as "search"// but they might actually want to parse that as a user instead to add to// the most recent pill. So we shuffle some things around to support that.if (last.operator === "search") {- const text_input = last.operand;- const operand = `${last_complete_term.operand},${text_input}`;- last = {- ...last_complete_term,- operand,- };+ new_query = last.operand;+ existing_user_ids = last_complete_term.operand;terms = terms.slice(-1);} else if (last.operator === "") {// User hasn't started typing the next term yet; use the// last complete term to generate suggestions.assert(last.operand === "");- last = last_complete_term;+ new_query = "";+ existing_user_ids = last_complete_term.operand;} else {// If they already started another term with an other operator, we're// no longer dealing with a group DM situation.return [];}- const operand = last.operand;- const negated = last.negated;-- // The operand has the form "part1,part2,pa", where all but the last part- // are emails, and the last part is an arbitrary query.- //- // We only generate group suggestions when there's more than one part, and- // we only use the last part to generate suggestions.-- const last_comma_index = operand.lastIndexOf(",");- let all_but_last_part;- let last_part;- if (last_comma_index === -1) {- all_but_last_part = operand;- last_part = "";- } else {- // Neither all_but_last_part nor last_part include the final comma.- all_but_last_part = operand.slice(0, last_comma_index);- last_part = operand.slice(last_comma_index + 1);+ // Somehow an invalid user id is showing up earlier in the group.+ // This can happen if e.g. the user manually enters multiple user ids.+ // We won't have group suggestions built from an invalid user, so+ // return an empty list.+ if (!people.is_valid_user_ids(existing_user_ids)) {+ return [];}- // We don't suggest a person if their email is already present in the+ // We don't suggest a person if their user id is already present in the// operand (not including the last part).- const parts = [...all_but_last_part.split(","), people.my_current_email()];-- const all_users_but_last_part = [];- for (const email of all_but_last_part.split(",")) {- const user = people.get_by_email(email);- // Somehow an invalid email is showing up earlier in the group.- // This can happen if e.g. the user manually enters multiple emails.- // We won't have group suggestions built from an invalid user, so- // return an empty list.- if (user === undefined) {- return [];+ const person_matcher = people.build_person_matcher(new_query);+ let persons = people.filter_all_persons((person) => {+ if (person.user_id === people.my_current_user_id()) {+ return false;}- all_users_but_last_part.push(user);- }- const person_matcher = people.build_person_matcher(last_part);- let persons = people.filter_all_persons((person) => {- if (parts.includes(person.email)) {+ if (existing_user_ids.includes(person.user_id)) {return false;}- return last_part === "" || person_matcher(person);+ return new_query === "" || person_matcher(person);});- persons.sort(compare_by_direct_message_group(parts));+ persons.sort(compare_by_direct_message_group(existing_user_ids));// Take top 15 persons, since they're ordered by pm_recipient_count.persons = persons.slice(0, 15);@@ -355,12 +334,12 @@ function get_group_suggestions(return persons.map((person) => {const term: NarrowCanonicalTerm = {operator: group_operator,- operand: all_but_last_part + "," + person.email,- negated,+ operand: [...existing_user_ids, person.user_id],+ negated: last_complete_term.negated,};let terms: NarrowCanonicalTerm[] = [term];- if (group_operator === "dm" && negated) {+ if (group_operator === "dm" && last_complete_term.negated) {terms = [{operator: "is", operand: "dm"}, term];}@@ -420,13 +399,25 @@ function get_person_suggestions(const persons = people_getter();return persons.map((person) => {- const terms: NarrowTerm[] = [- {- operator: autocomplete_operator,- operand: person.email,- negated: last.negated,- },- ];+ const terms: NarrowCanonicalTerm[] = [];+ switch (autocomplete_operator) {+ case "dm":+ case "dm-including":+ terms.push({+ operator: autocomplete_operator,+ operand: [person.user_id],+ negated: last.negated,+ });+ break;+ case "sender":+ terms.push({+ operator: "sender",+ operand: person.user_id,+ negated: last.negated,+ });+ break;+ }+if (last.negated && autocomplete_operator === "dm") {// In the special case of "-dm" or "-pm-with", add "is:dm" before// it because we assume the user still wants to narrow to direct@@ -860,7 +851,8 @@ function get_sent_by_me_suggestions(last.negated === true || (last.operator === "search" && last.operand.startsWith("-"));const negated_symbol = negated ? "-" : "";- const sender_query = negated_symbol + "sender:" + people.my_current_email();+ const sender_query = negated_symbol + "sender:" + people.my_current_user_id();+ const sender_email_string = negated_symbol + "sender:" + people.my_current_email();const sender_me_query = negated_symbol + "sender:me";const from_string = negated_symbol + "from";const sent_string = negated_symbol + "sent";@@ -874,6 +866,7 @@ function get_sent_by_me_suggestions(sender_query.startsWith(last_string) ||sender_me_query.startsWith(last_string) ||from_string.startsWith(last_string) ||+ sender_email_string.startsWith(last_string) ||last_string === sent_string) {return [@@ -945,8 +938,37 @@ function get_operator_suggestions(if (choice === "streams") {choice = "channels";}- const op = [{operator: choice, operand: "", negated}];- return format_as_suggestion(op);++ // Set is_operator_suggestion to true, since we're only suggesting+ // the operator and don't want any operand, but we can't put empty+ // strings here for typescript reasons..+ switch (choice) {+ case "dm":+ case "dm-including":+ return format_as_suggestion(+ [+ {+ operator: choice,+ operand: [],+ negated,+ },+ ],+ true,+ );+ case "sender":+ return format_as_suggestion(+ [+ {+ operator: choice,+ operand: -1,+ negated,+ },+ ],+ true,+ );+ default:+ return format_as_suggestion([{operator: choice, operand: "", negated}], true);+ }});}@@ -1084,12 +1106,23 @@ export function get_search_result(): Suggestion[] {let suggestion_line: SuggestionLine;const text_search_terms: NarrowCanonicalTermSuggestion[] = text_search_terms_non_canonical.map(- (term) =>- Filter.convert_suggestion_to_term(term) ?? {+ (term) => {+ // Try to parse term into canonical form first to+ // perform any necessary conversions.+ const canonical_term = Filter.convert_suggestion_to_term(term);+ if (canonical_term) {+ return {+ operator: canonical_term.operator,+ operand: String(canonical_term.operand),+ negated: canonical_term.negated,+ };+ }+ return {operator: filter_util.canonicalize_operator(term.operator),operand: term.operand,negated: term.negated,- },+ };+ },);// search_terms correspond to the terms for the query in the input.// This includes the entire query entered in the searchbox.diff --git a/web/src/state_data.ts b/web/src/state_data.tsindex 510e5a6f05a..768591c198d 100644--- a/web/src/state_data.ts+++ b/web/src/state_data.ts@@ -125,17 +125,17 @@ export const narrow_canonical_term_schema = z.discriminatedUnion("operator", [}),z.object({operator: z.literal("sender"),- operand: z.string(),+ operand: z.number(),negated: z.optional(z.boolean()),}),z.object({operator: z.literal("dm-including"),- operand: z.string(),+ operand: z.array(z.number()),negated: z.optional(z.boolean()),}),z.object({operator: z.literal("dm"),- operand: z.string(),+ operand: z.array(z.number()),negated: z.optional(z.boolean()),}),]);diff --git a/web/src/typing_events.ts b/web/src/typing_events.tsindex 65f2358fe01..8f1ff498b92 100644--- a/web/src/typing_events.ts+++ b/web/src/typing_events.ts@@ -94,12 +94,11 @@ function get_users_typing_for_narrow(): number[] {const current_filter = narrow_state.filter()!;if (current_filter.has_operator("dm")) {// Get list of users typing in this conversation- const narrow_emails_string = current_filter.terms_with_operator("dm")[0]!.operand;- if (!people.is_valid_bulk_emails_for_compose(narrow_emails_string.split(","))) {+ const narrow_user_ids = current_filter.terms_with_operator("dm")[0]!.operand;+ if (!people.is_valid_bulk_user_ids_for_compose(narrow_user_ids, true)) {// Narrowed to an invalid direct message recipient.return [];}- const narrow_user_ids = people.emails_string_to_user_ids(narrow_emails_string);const group = [...narrow_user_ids, current_user.user_id];return typing_data.get_group_typists(group);}diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex 003fe469dcc..87fde37ab7f 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -702,12 +702,12 @@ export async function initialize_everything(state_data) {}});activity_ui.initialize({- narrow_by_email(email) {+ narrow_by_user_id(user_id) {message_view.show([{operator: "dm",- operand: email,+ operand: [user_id],},],{trigger: "sidebar"},diff --git a/web/src/user_card_popover.ts b/web/src/user_card_popover.tsindex f27aa639936..488cc2e5171 100644--- a/web/src/user_card_popover.ts+++ b/web/src/user_card_popover.ts@@ -359,7 +359,7 @@ function get_user_card_popover_data(pm_with_url: hash_util.pm_with_url(user.user_id.toString()),user_circle_class: buddy_data.get_user_circle_class(user.user_id),private_message_class: private_msg_class,- sent_by_url: hash_util.by_sender_url(user.email),+ sent_by_url: hash_util.by_sender_url(user.user_id),user_email: user.delivery_email,user_full_name: user.full_name,user_id: user.user_id,@@ -409,7 +409,7 @@ function show_user_card_popover(let popover_html;let args;if (user.is_inaccessible_user) {- const sent_by_url = hash_util.by_sender_url(user.email);+ const sent_by_url = hash_util.by_sender_url(user.user_id);const user_avatar = people.small_avatar_url_for_person(user);args = {user_id: user.user_id,@@ -734,12 +734,11 @@ function register_click_handlers(): void {$("body").on("click", ".user-card-popover-actions .narrow_to_private_messages", function (e) {const user_id = elem_to_user_id($(this).parents("ul"));- const email = people.get_by_user_id(user_id).email;message_view.show([{operator: "dm",- operand: email,+ operand: [user_id],},],{trigger: "user sidebar popover"},@@ -754,12 +753,11 @@ function register_click_handlers(): void {$("body").on("click", ".user-card-popover-actions .narrow_to_messages_sent", function (e) {const user_id = elem_to_user_id($(this).parents("ul"));- const email = people.get_by_user_id(user_id).email;message_view.show([{operator: "sender",- operand: email,+ operand: user_id,},],{trigger: "user sidebar popover"},diff --git a/web/src/user_events.ts b/web/src/user_events.tsindex 21511b983ec..31c8b7341c8 100644--- a/web/src/user_events.ts+++ b/web/src/user_events.ts@@ -12,7 +12,6 @@ import {buddy_list} from "./buddy_list.ts";import * as compose_pm_pill from "./compose_pm_pill.ts";import * as compose_state from "./compose_state.ts";import * as message_live_update from "./message_live_update.ts";-import * as narrow_state from "./narrow_state.ts";import * as navbar_alerts from "./navbar_alerts.ts";import * as people from "./people.ts";import * as pm_list from "./pm_list.ts";@@ -73,7 +72,6 @@ export const update_person = function update(event: UserUpdate): void {const new_email = event.new_email;people.update_email(user_id, new_email);- narrow_state.update_email(user_id, new_email);compose_state.update_email(user_id, new_email);if (people.is_my_user_id(event.user_id)) {diff --git a/web/tests/activity.test.cjs b/web/tests/activity.test.cjsindex 0007dc29e7b..03cc899d284 100644--- a/web/tests/activity.test.cjs+++ b/web/tests/activity.test.cjs@@ -93,13 +93,13 @@ const zoe = {full_name: "Zoe Yang",};-people.add_active_user(alice);-people.add_active_user(fred);-people.add_active_user(jill);-people.add_active_user(mark);-people.add_active_user(norbert);-people.add_active_user(zoe);-people.add_active_user(me);+people.add_active_user(alice, "server_events");+people.add_active_user(fred, "server_events");+people.add_active_user(jill, "server_events");+people.add_active_user(mark, "server_events");+people.add_active_user(norbert, "server_events");+people.add_active_user(zoe, "server_events");+people.add_active_user(me, "server_events");people.initialize_current_user(me.user_id);const $alice_stub = $.create("alice stub");@@ -233,8 +233,8 @@ test("handlers", ({override, override_rewire}) => {let narrowed;- function narrow_by_email(email) {- assert.equal(email, "[email protected]");+ function narrow_by_user_id(user_id) {+ assert.equal(user_id, alice.user_id);narrowed = true;}@@ -245,7 +245,7 @@ test("handlers", ({override, override_rewire}) => {buddy_list.start_scroll_handler = noop;override_rewire(util, "call_function_periodically", noop);override_rewire(activity, "send_presence_to_server", noop);- activity_ui.initialize({narrow_by_email});+ activity_ui.initialize({narrow_by_user_id});buddy_list.populate({all_user_ids: [me.user_id, alice.user_id, fred.user_id],diff --git a/web/tests/activity_ui.test.cjs b/web/tests/activity_ui.test.cjsindex 7b224107dfd..191cd499652 100644--- a/web/tests/activity_ui.test.cjs+++ b/web/tests/activity_ui.test.cjs@@ -60,17 +60,17 @@ run_test("initialize", ({override, override_rewire}) => {assert.equal(delay, 42000);});- let my_email = "";+ let my_user_id;- function narrow_by_email(email) {- my_email = email;+ function narrow_by_user_id(user_id) {+ my_user_id = user_id;}- activity_ui.initialize({narrow_by_email});+ activity_ui.initialize({narrow_by_user_id});- assert.equal(my_email, "");- activity_ui.get_narrow_by_email_function_for_test_code()("[email protected]");- assert.equal(my_email, "[email protected]");+ assert.equal(my_user_id, undefined);+ activity_ui.get_narrow_by_user_id_function_for_test_code()(1);+ assert.equal(my_user_id, 1);// Simulate the subsequent calls to// activity.send_presence_to_server.diff --git a/web/tests/buddy_data.test.cjs b/web/tests/buddy_data.test.cjsindex 3cbd2082419..809b8e0c878 100644--- a/web/tests/buddy_data.test.cjs+++ b/web/tests/buddy_data.test.cjs@@ -105,14 +105,15 @@ const bot_with_owner = {};function add_canned_users() {- people.add_active_user(alice);- people.add_active_user(bot);- people.add_active_user(bot_with_owner);- people.add_active_user(fred);- people.add_active_user(jill);- people.add_active_user(mark);- people.add_active_user(old_user);- people.add_active_user(selma);+ people.add_active_user(alice, "server_events");+ people.add_active_user(bot, "server_events");+ people.add_active_user(bot_with_owner, "server_events");+ people.add_active_user(fred, "server_events");+ people.add_active_user(jill, "server_events");+ people.add_active_user(mark, "server_events");+ people.add_active_user(old_user, "server_events");+ people.add_active_user(selma, "server_events");+ people.add_active_user(me, "server_events");}function test(label, f) {@@ -384,8 +385,8 @@ test("always show me", () => {});test("always show pm users", () => {- people.add_active_user(selma);- message_lists.set_current(make_message_list([{operator: "dm", operand: selma.email}]));+ people.add_active_user(selma, "server_events");+ message_lists.set_current(make_message_list([{operator: "dm", operand: [selma.user_id]}]));assert.deepEqual(buddy_data.get_filtered_and_sorted_user_ids(""), [me.user_id, selma.user_id]);});@@ -611,8 +612,7 @@ test("user_last_seen_time_status", ({override}) => {});test("get_items_for_users", ({override}) => {- people.add_active_user(alice);- people.add_active_user(fred);+ add_canned_users();set_presence(alice.user_id, "offline");override(user_settings, "emojiset", "google");override(user_settings, "user_list_style", 2);diff --git a/web/tests/example8.test.cjs b/web/tests/example8.test.cjsindex 851fe6b7f18..2d0e9c3d695 100644--- a/web/tests/example8.test.cjs+++ b/web/tests/example8.test.cjs@@ -85,8 +85,7 @@ run_test("typing_events.render_notifications_for_narrow", ({override, mock_temploverride(current_user, "user_id", anna.user_id);const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];const conversation_key = typing_data.get_direct_message_conversation_key(group);- const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;- message_lists.set_current(make_message_list([{operator: "dm", operand: group_emails}]));+ message_lists.set_current(make_message_list([{operator: "dm", operand: group}]));// Based on typing_events.MAX_USERS_TO_DISPLAY_NAME (which is currently 3),// we display either the list of all users typing (if they do not exceeddiff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex c4876bb67b3..51e0d56401a 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -22,6 +22,7 @@ const filter_util = zrequire("filter_util");const {set_current_user, set_realm} = zrequire("state_data");const {initialize_user_settings} = zrequire("user_settings");const muted_users = zrequire("muted_users");+const state_data = zrequire("state_data");const realm = make_realm();set_realm(realm);@@ -70,13 +71,16 @@ const annie = {is_guest: true,};-people.add_active_user(me);-people.add_active_user(joe);-people.add_active_user(steve);-people.add_active_user(alice);-people.add_active_user(jeff);-people.add_active_user(annie);+// Add users to `valid_user_ids`.+const source = "server_events";+people.add_active_user(me, source);+people.add_active_user(joe, source);+people.add_active_user(steve, source);+people.add_active_user(alice, source);+people.add_active_user(jeff, source);+people.add_active_user(annie, source);people.initialize_current_user(me.user_id);+state_data.set_current_user(me);muted_users.add_muted_user(jeff.user_id);muted_users.add_muted_user(annie.user_id);@@ -411,7 +415,7 @@ test("basics", () => {assert.ok(!filter.is_channel_view());assert.ok(!filter.has_exactly_channel_topic_operators());- terms = [{operator: "dm", operand: "[email protected]"}];+ terms = [{operator: "dm", operand: [joe.user_id]}];filter = new Filter(terms);assert.ok(filter.is_search_for_specific_group_or_user());assert.ok(filter.contains_only_private_messages());@@ -427,7 +431,7 @@ test("basics", () => {assert.ok(!filter.has_exactly_channel_topic_operators());terms = [- {operator: "dm", operand: "[email protected]"},+ {operator: "dm", operand: [joe.user_id]},{operator: "near", operand: "17"},];filter = new Filter(terms);@@ -444,7 +448,7 @@ test("basics", () => {assert.ok(!filter.is_channel_view());assert.ok(!filter.has_exactly_channel_topic_operators());- terms = [{operator: "dm", operand: "[email protected],[email protected]"}];+ terms = [{operator: "dm", operand: [joe.user_id, steve.user_id]}];filter = new Filter(terms);assert.ok(filter.is_search_for_specific_group_or_user());assert.ok(filter.contains_only_private_messages());@@ -459,7 +463,7 @@ test("basics", () => {assert.ok(!filter.has_exactly_channel_topic_operators());terms = [- {operator: "dm", operand: "[email protected],[email protected]"},+ {operator: "dm", operand: [joe.user_id, steve.user_id]},{operator: "with", operand: "12"},];filter = new Filter(terms);@@ -475,14 +479,14 @@ test("basics", () => {assert.ok(!filter.has_exactly_channel_topic_operators());// "pm-with" was renamed to "dm"- terms = [{operator: "pm-with", operand: "[email protected]"}];+ terms = [{operator: "pm-with", operand: [joe.user_id]}];filter = new Filter(terms);assert.ok(filter.has_operator("dm"));assert.ok(!filter.has_operator(" pm-with"));assert.ok(!filter.is_channel_view());assert.ok(!filter.has_exactly_channel_topic_operators());- terms = [{operator: "dm-including", operand: "[email protected]"}];+ terms = [{operator: "dm-including", operand: [joe.user_id]}];filter = new Filter(terms);assert.ok(filter.is_search_for_specific_group_or_user());assert.ok(filter.contains_only_private_messages());@@ -497,7 +501,7 @@ test("basics", () => {assert.ok(!filter.has_exactly_channel_topic_operators());// "group-pm-with" was replaced with "dm-including"- terms = [{operator: "group-pm-with", operand: "[email protected]"}];+ terms = [{operator: "group-pm-with", operand: [joe.user_id]}];filter = new Filter(terms);assert.ok(filter.has_operator("dm-including"));assert.ok(!filter.has_operator("group-pm-with"));@@ -774,11 +778,11 @@ test("can_mark_messages_read", () => {filter = new Filter(channel_negated_topic_terms);assert.ok(!filter.can_mark_messages_read());- const dm = [{operator: "dm", operand: "[email protected],"}];+ const dm = [{operator: "dm", operand: [joe.user_id]}];- const dm_negated = [{operator: "dm", operand: "[email protected],", negated: true}];+ const dm_negated = [{operator: "dm", operand: [joe.user_id], negated: true}];- const dm_group = [{operator: "dm", operand: "[email protected],[email protected]"}];+ const dm_group = [{operator: "dm", operand: [joe.user_id, steve.user_id]}];filter = new Filter(dm);assert.ok(filter.can_mark_messages_read());filter = new Filter(dm_negated);@@ -977,14 +981,14 @@ test("redundancies", () => {let filter;terms = [- {operator: "dm", operand: "[email protected],"},+ {operator: "dm", operand: [joe.user_id]},{operator: "is", operand: "dm"},];filter = new Filter(terms);assert.ok(filter.can_bucket_by("dm"));terms = [- {operator: "dm", operand: "[email protected],", negated: true},+ {operator: "dm", operand: [joe.user_id], negated: true},{operator: "is", operand: "dm"},];filter = new Filter(terms);@@ -1006,19 +1010,19 @@ test("canonicalization", () => {assert.equal(term.operator, "channel");assert.equal(term.operand, "Denmark");- term = Filter.canonicalize_term({operator: "sender", operand: "me"});+ term = Filter.convert_suggestion_to_term({operator: "sender", operand: "me"});assert.equal(term.operator, "sender");- assert.equal(term.operand, "[email protected]");+ assert.equal(term.operand, me.user_id);// "pm-with" was renamed to "dm"- term = Filter.canonicalize_term({operator: "pm-with", operand: "me"});+ term = Filter.convert_suggestion_to_term({operator: "pm-with", operand: "me"});assert.equal(term.operator, "dm");- assert.equal(term.operand, "[email protected]");+ assert.deepEqual(term.operand, [me.user_id]);// "group-pm-with" was replaced with "dm-including"- term = Filter.canonicalize_term({operator: "group-pm-with", operand: "[email protected]"});+ term = Filter.canonicalize_term({operator: "group-pm-with", operand: [joe.user_id]});assert.equal(term.operator, "dm-including");- assert.equal(term.operand, "[email protected]");+ assert.deepEqual(term.operand, [joe.user_id]);term = Filter.canonicalize_term({operator: "search", operand: "foo"});assert.equal(term.operator, "search");@@ -1079,7 +1083,7 @@ test("ensure_channel_topic_terms", () => {);const term_4 = Filter.ensure_channel_topic_terms([- {operator: "dm", operand: "[email protected]"},+ {operator: "dm", operand: [joe.user_id]},{operator: "with", operand: message.id},],message,@@ -1277,11 +1281,11 @@ test("predicate_basics", ({override}) => {assert.ok(predicate({type: stream_message, id: 5, topic: "lunch"}));assert.ok(!predicate({type: stream_message, id: 5, topic: "dinner"}));- predicate = get_predicate([["sender", "[email protected]"]]);+ predicate = get_predicate([["sender", joe.user_id]]);assert.ok(predicate({sender_id: joe.user_id}));assert.ok(!predicate({sender_email: steve.user_id}));- predicate = get_predicate([["dm", "[email protected]"]]);+ predicate = get_predicate([["dm", [joe.user_id]]]);assert.ok(predicate({type: direct_message,@@ -1302,7 +1306,7 @@ test("predicate_basics", ({override}) => {);assert.ok(!predicate({type: stream_message}));- predicate = get_predicate([["dm", "[email protected],[email protected]"]]);+ predicate = get_predicate([["dm", [joe.user_id, steve.user_id]]]);assert.ok(predicate({type: direct_message,@@ -1310,8 +1314,8 @@ test("predicate_basics", ({override}) => {}),);- // Make sure your own email is ignored+ // Make sure your own user id is ignored+ predicate = get_predicate([["dm", [joe.user_id, steve.user_id, me.user_id]]]);assert.ok(predicate({type: direct_message,@@ -1319,7 +1323,7 @@ test("predicate_basics", ({override}) => {}),);- predicate = get_predicate([["dm", "[email protected]"]]);+ predicate = get_predicate([["dm", [1000]]]);assert.ok(!predicate({type: direct_message,@@ -1327,7 +1331,7 @@ test("predicate_basics", ({override}) => {}),);- predicate = get_predicate([["dm-including", "[email protected]"]]);+ predicate = get_predicate([["dm-including", [1000]]]);assert.ok(!predicate({type: direct_message,@@ -1335,7 +1339,7 @@ test("predicate_basics", ({override}) => {}),);- predicate = get_predicate([["dm-including", "[email protected]"]]);+ predicate = get_predicate([["dm-including", [joe.user_id]]]);assert.ok(predicate({type: direct_message,@@ -1537,11 +1541,11 @@ test("parse", () => {_test();string = "sender:me";- terms = [{operator: "sender", operand: `${me.email}`}];+ terms = [{operator: "sender", operand: `${me.user_id}`}];_test(true);string = "-sender:me";- terms = [{operator: "sender", operand: `${me.email}`, negated: true}];+ terms = [{operator: "sender", operand: `${me.user_id}`, negated: true}];_test(true);string = "https://www.google.com";@@ -1681,11 +1685,8 @@ test("unparse", () => {string = `channel:${foo_stream_id} topic:Bar`;assert.deepEqual(Filter.unparse(terms), string);- terms = [- {operator: "dm", operand: '\t "%+.\u00A0'},- {operator: "topic", operand: '\t "%+.\u00A0'},- ];- string = "dm:%09%20%22%25+.%C2%A0 topic:%09+%22%25%2B.%C2%A0";+ terms = [{operator: "topic", operand: '\t "%+.\u00A0'}];+ string = "topic:%09+%22%25%2B.%C2%A0";assert.equal(Filter.unparse(terms), string);assert_same_terms(Filter.parse(string), terms);});@@ -1850,9 +1851,8 @@ test("describe", ({mock_template, override}) => {string = "combined feed";assert.equal(Filter.search_description_as_html(narrow, false), string);- // canonical version of the operator is used in descriptionnarrow = [- {operator: "stream", operand: devel_id.toString()},+ {operator: "channel", operand: devel_id.toString()},{operator: "subject", operand: "JS", negated: true},];string = "messages in #devel, exclude topic JS";@@ -1930,14 +1930,14 @@ test("can_bucket_by", () => {assert.equal(filter.can_bucket_by("channel", "topic"), false);assert.equal(filter.can_bucket_by("dm"), false);- terms = [{operator: "dm", operand: "[email protected]", negated: true}];+ terms = [{operator: "dm", operand: [steve.user_id], negated: true}];filter = new Filter(terms);assert.equal(filter.can_bucket_by("channel"), false);assert.equal(filter.can_bucket_by("channel", "topic"), false);assert.equal(filter.can_bucket_by("dm"), false);assert.equal(filter.can_bucket_by("dm", "with"), false);- terms = [{operator: "dm", operand: "[email protected],[email protected]"}];+ terms = [{operator: "dm", operand: [steve.user_id, joe.user_id]}];filter = new Filter(terms);assert.equal(filter.can_bucket_by("channel"), false);assert.equal(filter.can_bucket_by("channel", "topic"), false);@@ -1947,7 +1947,7 @@ test("can_bucket_by", () => {assert.equal(filter.can_bucket_by("is-dm"), false);terms = [- {operator: "dm", operand: "[email protected],[email protected]"},+ {operator: "dm", operand: [steve.user_id, joe.user_id]},{operator: "with", operand: "7"},];filter = new Filter(terms);@@ -2037,7 +2037,7 @@ test("term_type", () => {const terms = [{operator: "topic", operand: "lunch"},- {operator: "sender", operand: "[email protected]"},+ {operator: "sender", operand: steve.user_id},{operator: "channel", operand: new_stream_id().toString()},];let filter = new Filter(terms);@@ -2110,11 +2110,11 @@ test("convert_suggestion_to_term", () => {["channels:public", true],["channels:private", false],["topic:GhostTown", true],- ["dm-including:[email protected]", true],- ["sender:[email protected]", false],+ [`dm-including:${alice.user_id}`, true],+ ["sender:-1", false],["sender:me", true],- ["dm:[email protected],[email protected]", false],- ["dm:[email protected],[email protected]", true],+ [`dm:${[alice.user_id, -1]}`, false],+ [`dm:${[alice.user_id, joe.user_id]}`, true],];for (const [search_term_string, expected_is_valid] of test_data) {assert.equal(@@ -2133,27 +2133,6 @@ test("convert_suggestion_to_term", () => {);});-test("update_email", () => {- const terms = [- {operator: "dm", operand: "[email protected]"},- {operator: "sender", operand: "[email protected]"},- {operator: "channel", operand: "[email protected]"}, // try to be tricky- ];- const filter = new Filter(terms);- filter.update_email(steve.user_id, "[email protected]");-- const dm_terms = filter.terms_with_operator("dm");- assert.deepEqual(dm_terms, [{operator: "dm", operand: "[email protected]", negated: false}]);- const sender_terms = filter.terms_with_operator("sender");- assert.deepEqual(sender_terms, [- {operator: "sender", operand: "[email protected]", negated: false},- ]);- const channel_terms = filter.terms_with_operator("channel");- assert.deepEqual(channel_terms, [- {operator: "channel", operand: "[email protected]", negated: false},- ]);-});-test("try_adjusting_for_moved_with_target", ({override}) => {const scotland_id = new_stream_id();make_sub("Scotland", scotland_id);@@ -2231,14 +2210,14 @@ test("try_adjusting_for_moved_with_target", ({override}) => {filter.try_adjusting_for_moved_with_target();assert.deepEqual(filter.requires_adjustment_for_moved_with_target, false);assert.deepEqual(filter.terms(), [- {operator: "dm", operand: "[email protected]", negated: false},+ {operator: "dm", operand: [3], negated: false},{operator: "with", operand: "2", negated: false},]);// When the narrow consists of `dm` operators, while the `with`// operator corresponds to that of a channel topic message.terms = [- {operator: "dm", operand: "[email protected]"},+ {operator: "dm", operand: [alice.user_id]},{operator: "with", operand: "12"},];filter = new Filter(terms);@@ -2391,9 +2370,9 @@ test("navbar_helpers", ({override}) => {test_redirect_url_with_search(test_case);}- const sender = [{operator: "sender", operand: joe.email}];- const guest_sender = [{operator: "sender", operand: alice.email}];- const invalid_sender = [{operator: "sender", operand: "[email protected]"}];+ const sender = [{operator: "sender", operand: joe.user_id}];+ const guest_sender = [{operator: "sender", operand: alice.user_id}];+ const invalid_sender = [{operator: "sender", operand: 9999}];const in_home = [{operator: "in", operand: "home"}];const in_all = [{operator: "in", operand: "all"}];const is_starred = [{operator: "is", operand: "starred"}];@@ -2410,7 +2389,7 @@ test("navbar_helpers", ({override}) => {];const has_reaction_sender_me = [{operator: "has", operand: "reaction"},- {operator: "sender", operand: "me"},+ {operator: "sender", operand: me.user_id},];// foo channel existsconst channel_term = [{operator: "channel", operand: foo_stream_id.toString()}];@@ -2437,28 +2416,22 @@ test("navbar_helpers", ({override}) => {const archived_sub_id = new_stream_id();make_archived_sub("archivedSub", archived_sub_id);const archived_channel_term = [{operator: "channel", operand: archived_sub_id.toString()}];- const dm = [{operator: "dm", operand: "[email protected]"}];+ const dm = [{operator: "dm", operand: [joe.user_id]}];const dm_with = [- {operator: "dm", operand: "[email protected]"},+ {operator: "dm", operand: [joe.user_id]},{operator: "with", operand: "12"},];- const dm_with_self = [{operator: "dm", operand: "[email protected]"}];- const dm_group = [{operator: "dm", operand: "[email protected],[email protected]"}];- const dm_with_guest = [{operator: "dm", operand: "[email protected]"}];- const dm_with_muted_user = [{operator: "dm", operand: "[email protected]"}];- const dm_with_muted_guest_user = [{operator: "dm", operand: "[email protected]"}];- const dm_group_including_guest = [- {operator: "dm", operand: "[email protected],[email protected]"},- ];- const dm_group_including_muted_user = [- {operator: "dm", operand: "[email protected],[email protected]"},- ];+ const dm_with_self = [{operator: "dm", operand: [me.user_id]}];+ const dm_group = [{operator: "dm", operand: [joe.user_id, steve.user_id]}];+ const dm_with_guest = [{operator: "dm", operand: [alice.user_id]}];+ const dm_with_muted_user = [{operator: "dm", operand: [jeff.user_id]}];+ const dm_with_muted_guest_user = [{operator: "dm", operand: [annie.user_id]}];+ const dm_group_including_guest = [{operator: "dm", operand: [joe.user_id, alice.user_id]}];+ const dm_group_including_muted_user = [{operator: "dm", operand: [joe.user_id, jeff.user_id]}];const dm_group_including_muted_guest_user = [- {operator: "dm", operand: "[email protected],[email protected]"},- ];- const dm_group_including_missing_person = [+ {operator: "dm", operand: [joe.user_id, annie.user_id]},];+ const dm_group_including_missing_person = [{operator: "dm", operand: [9999, joe.user_id]}];// not common narrows, but used for browser title updatesconst is_alerted = [{operator: "is", operand: "alerted"}];const is_unread = [{operator: "is", operand: "unread"}];@@ -2468,7 +2441,7 @@ test("navbar_helpers", ({override}) => {{operator: "near", operand: "12"},];const dm_near = [- {operator: "dm", operand: "[email protected]"},+ {operator: "dm", operand: [joe.user_id]},{operator: "near", operand: "12"},];const channel_with = [@@ -2700,11 +2673,7 @@ test("navbar_helpers", ({override}) => {terms: dm_group_including_missing_person,is_common_narrow: true,zulip_icon: "user",- title: properly_separated_names([- joe.full_name,- "[email protected]",- steve.full_name,- ]),+ title: "joe and translated: Unknown user (9999)",redirect_url_with_search: "/#narrow/dm/undefined",},{@@ -2774,8 +2743,8 @@ test("navbar_helpers", ({override}) => {}// TODO: these may be removed, based on design decisions- const sender_me = [{operator: "sender", operand: "me"}];- const sender_joe = [{operator: "sender", operand: joe.email}];+ const sender_me = [{operator: "sender", operand: me.user_id}];+ const sender_joe = [{operator: "sender", operand: joe.user_id}];const redirect_edge_cases = [{@@ -2800,7 +2769,7 @@ test("navbar_helpers", ({override}) => {const complex_term = [{operator: "channel", operand: foo_stream_id.toString()},{operator: "topic", operand: "bar"},- {operator: "sender", operand: "me"},+ {operator: "sender", operand: me.user_id},];const redirect_url = "#";@@ -2875,7 +2844,7 @@ test("error_cases", () => {// This test just gives us 100% line coverage on defensive code that// should not be reached unless we break other code.- const predicate = get_predicate([["dm", "[email protected]"]]);+ const predicate = get_predicate([["dm", [joe.user_id]]]);blueslip.expect("error", "Empty recipient list in message");assert.ok(!predicate({type: direct_message, display_recipient: []}));});@@ -3039,7 +3008,7 @@ run_test("adjusted_terms_if_moved", ({override}) => {];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepEqual(result, [- {operator: "dm", operand: "[email protected]", negated: false},+ {operator: "dm", operand: [3], negated: false},{operator: "with", operand: "2"},]);@@ -3054,7 +3023,7 @@ run_test("adjusted_terms_if_moved", ({override}) => {];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepEqual(result, [- {operator: "dm", operand: me.email, negated: false},+ {operator: "dm", operand: [me.user_id], negated: false},{operator: "with", operand: "2"},]);@@ -3117,7 +3086,7 @@ run_test("adjusted_terms_if_moved", ({override}) => {raw_terms = [{operator: "channel", operand: "999"},{operator: "topic", operand: "random"},- {operator: "sender", operand: "alice"},+ {operator: "sender", operand: alice.user_id},];message = {type: "stream",@@ -3128,7 +3097,7 @@ run_test("adjusted_terms_if_moved", ({override}) => {expected = [{negated: false, operator: "channel", operand: general_sub.stream_id.toString()},{negated: false, operator: "topic", operand: "discussion"},- {negated: false, operator: "sender", operand: "alice"},+ {negated: false, operator: "sender", operand: alice.user_id},];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepStrictEqual(result, expected);diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjsindex a994e94ce11..b89167a5a58 100644--- a/web/tests/hash_util.test.cjs+++ b/web/tests/hash_util.test.cjs@@ -19,7 +19,7 @@ const hamlet = {full_name: "Hamlet",};-people.add_active_user(hamlet);+people.add_active_user(hamlet, "server_events");const frontend_id = 99;const frontend = {@@ -40,7 +40,7 @@ run_test("hash_util", () => {}let operator = "sender";- let operand = hamlet.email;+ let operand = hamlet.user_id;encode_decode_operand(operator, operand, "15-Hamlet");diff --git a/web/tests/hashchange.test.cjs b/web/tests/hashchange.test.cjsindex b236ed5d2c6..9299d442dac 100644--- a/web/tests/hashchange.test.cjs+++ b/web/tests/hashchange.test.cjs@@ -101,51 +101,6 @@ run_test("terms_round_trip", () => {]);});-run_test("stream_to_channel_rename", () => {- let terms;- let hash;- let narrow;- let filter;-- // Confirm searches with "stream" and "streams" return URLs and- // Filter objects with the new "channel" and "channels" operators.- terms = [{operator: "channel", operand: devel_id.toString()}];- hash = hash_util.search_terms_to_hash(terms);- assert.equal(hash, "#narrow/channel/100-devel");- narrow = hash_util.parse_narrow(hash.split("/"));- assert.deepEqual(narrow, [{operator: "channel", operand: devel_id.toString(), negated: false}]);- filter = new Filter(narrow);- assert.deepEqual(filter.terms(), [- {operator: "channel", operand: devel_id.toString(), negated: false},- ]);-- terms = [{operator: "channels", operand: "public"}];- hash = hash_util.search_terms_to_hash(terms);- assert.equal(hash, "#narrow/channels/public");- narrow = hash_util.parse_narrow(hash.split("/"));- assert.deepEqual(narrow, [{operator: "channels", operand: "public", negated: false}]);- filter = new Filter(narrow);- assert.deepEqual(filter.terms(), [{operator: "channels", operand: "public", negated: false}]);-- // Confirm that a narrow URL with "channel" and an enocoded stream/channel ID,- // will be decoded correctly.- const test_stream_id = 34;- const test_channel = {- name: "decode",- stream_id: test_stream_id,- };- stream_data.add_sub_for_tests(test_channel);- hash = "#narrow/channel/34-decode";- narrow = hash_util.parse_narrow(hash.split("/"));- assert.deepEqual(narrow, [- {operator: "channel", operand: test_stream_id.toString(), negated: false},- ]);- filter = new Filter(narrow);- assert.deepEqual(filter.terms(), [- {operator: "channel", operand: test_stream_id.toString(), negated: false},- ]);-});-run_test("terms_trailing_slash", () => {const hash = "#narrow/channel/100-devel/topic/algol/";const narrow = hash_util.parse_narrow(hash.split("/"));@@ -166,18 +121,18 @@ run_test("people_slugs", () => {full_name: "Alice Smith",};- people.add_active_user(alice);- terms = [{operator: "sender", operand: "[email protected]"}];+ people.add_active_user(alice, "server_events");+ terms = [{operator: "sender", operand: alice.user_id}];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}]);+ assert.deepEqual(narrow, [{operator: "sender", operand: alice.user_id, negated: false}]);- terms = [{operator: "dm", operand: "[email protected]"}];+ terms = [{operator: "dm", operand: [alice.user_id]}];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}]);+ assert.deepEqual(narrow, [{operator: "dm", operand: [alice.user_id], negated: false}]);});function test_helper({override, override_rewire, change_tab}) {diff --git a/web/tests/message_list_data.test.cjs b/web/tests/message_list_data.test.cjsindex 65a2f07024f..5ca155308d0 100644--- a/web/tests/message_list_data.test.cjs+++ b/web/tests/message_list_data.test.cjs@@ -129,7 +129,7 @@ run_test("basics", () => {});run_test("muting", () => {- const dm_filter = new Filter([{operator: "dm", operand: "[email protected]"}]);+ const dm_filter = new Filter([{operator: "dm", operand: [1]}]);let mld = new MessageListData({excludes_muted_topics: dm_filter.excludes_muted_topics(),excludes_muted_users: dm_filter.excludes_muted_users(),diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjsindex ce5632dc9b6..56987a353e8 100644--- a/web/tests/message_view.test.cjs+++ b/web/tests/message_view.test.cjs@@ -199,9 +199,9 @@ run_test("empty_narrow_html", ({mock_template}) => {});run_test("urls", () => {- people.add_active_user(ray);- people.add_active_user(alice);- people.add_active_user(me);+ people.add_active_user(ray, "server_events");+ people.add_active_user(alice, "server_events");+ people.add_active_user(me, "server_events");people.initialize_current_user(me.user_id);let url = hash_util.pm_with_url(ray.user_id.toString());@@ -210,17 +210,17 @@ run_test("urls", () => {url = hash_util.direct_message_group_with_url("22,23");assert.equal(url, "#narrow/dm/22,23-group");- url = hash_util.by_sender_url(ray.email);+ url = hash_util.by_sender_url(ray.user_id);assert.equal(url, "#narrow/sender/22-Raymond");- let emails = hash_util.decode_operand("dm", "22,23-group");- assert.equal(emails, "[email protected],[email protected]");+ let user_ids = hash_util.decode_operand("dm", "22,23-group");+ assert.deepEqual(user_ids, [22, 23]);- emails = hash_util.decode_operand("dm", "5,22,23-group");- assert.equal(emails, "[email protected],[email protected]");+ user_ids = hash_util.decode_operand("dm", "5,22,23-group");+ assert.deepEqual(user_ids, [22, 23]);- emails = hash_util.decode_operand("dm", "5-group");- assert.equal(emails, "[email protected]");+ user_ids = hash_util.decode_operand("dm", "5-group");+ assert.deepEqual(user_ids, [5]);});run_test("show_empty_narrow_message", ({mock_template, override}) => {@@ -383,22 +383,21 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {override(realm, "realm_direct_message_permission_group", nobody.id);// prioritize information about invalid user(s) in narrow/search- current_filter = set_filter([["dm", "Yo"]]);+ current_filter = set_filter([["dm", [-1]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: This user does not exist!"),);- people.add_active_user(alice);- current_filter = set_filter([["dm", "[email protected],Yo"]]);+ current_filter = set_filter([["dm", [9999, alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: One or more of these users do not exist!"),);- current_filter = set_filter([["dm", "[email protected]"]]);+ current_filter = set_filter([["dm", [alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -410,8 +409,8 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// direct messages with a bot are possible even though// the organization has disabled sending direct messages- people.add_active_user(bot);- current_filter = set_filter([["dm", "[email protected]"]]);+ people.add_active_user(bot, "server_events");+ current_filter = set_filter([["dm", [bot.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -423,7 +422,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// group direct messages with bots are not possible when// sending direct messages is disabled- current_filter = set_filter([["dm", bot.email + "," + alice.email]]);+ current_filter = set_filter([["dm", [bot.user_id, alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -435,7 +434,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// sending direct messages enabledoverride(realm, "realm_direct_message_permission_group", everyone.id);- current_filter = set_filter([["dm", "[email protected]"]]);+ current_filter = set_filter([["dm", [alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -448,7 +447,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// sending direct messages to deactivated useroverride(realm, "realm_direct_message_permission_group", everyone.id);people.deactivate(alice);- current_filter = set_filter([["dm", alice.email]]);+ current_filter = set_filter([["dm", [alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -458,7 +457,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {people.add_active_user(me);people.initialize_current_user(me.user_id);- current_filter = set_filter([["dm", me.email]]);+ current_filter = set_filter([["dm", [me.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -468,7 +467,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {),);- current_filter = set_filter([["dm", me.email + "," + alice.email]]);+ current_filter = set_filter([["dm", [me.user_id, alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -480,7 +479,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// group dm with a deactivated userpeople.deactivate(alice);- current_filter = set_filter([["dm", ray.email + "," + alice.email]]);+ current_filter = set_filter([["dm", [ray.user_id, alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -492,21 +491,21 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {override(realm, "realm_direct_message_permission_group", nobody.id);// prioritize information about invalid user in narrow/search- current_filter = set_filter([["dm-including", "Yo"]]);+ current_filter = set_filter([["dm-including", [-1]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: This user does not exist!"),);- current_filter = set_filter([["dm-including", "[email protected],[email protected]"]]);+ current_filter = set_filter([["dm-including", [9999, 88888]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: This user does not exist!"),);- current_filter = set_filter([["dm-including", "[email protected]"]]);+ current_filter = set_filter([["dm-including", [alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -518,7 +517,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// direct messages with a bot are possible even though// the organization has disabled sending direct messages- current_filter = set_filter([["dm-including", "[email protected]"]]);+ current_filter = set_filter([["dm-including", [bot.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -528,28 +527,28 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {// sending direct messages enabledoverride(realm, "realm_direct_message_permission_group", everyone.id);override(realm, "realm_direct_message_permission_group", everyone.id);- current_filter = set_filter([["dm-including", "[email protected]"]]);+ current_filter = set_filter([["dm-including", [alice.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: You have no direct messages including Alice Smith yet."),);- current_filter = set_filter([["dm-including", me.email]]);+ current_filter = set_filter([["dm-including", [me.user_id]]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: You don't have any direct message conversations yet."),);- current_filter = set_filter([["sender", "[email protected]"]]);+ current_filter = set_filter([["sender", ray.user_id]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html("translated: You haven't received any messages sent by Raymond yet."),);- current_filter = set_filter([["sender", "[email protected]"]]);+ current_filter = set_filter([["sender", 9999]]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal($(".empty_feed_notice_main").html(),@@ -559,7 +558,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {);current_filter = set_filter([- ["sender", "[email protected]"],+ ["sender", alice.user_id],["stream", rome_id.toString()],]);narrow_banner.show_empty_narrow_message(current_filter);@@ -627,7 +626,7 @@ run_test("show_empty_narrow_message", ({mock_template, override}) => {current_filter = set_filter([["has", "reaction"],- ["sender", "me"],+ ["sender", me.user_id],]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal(@@ -758,8 +757,8 @@ run_test("show_invalid_narrow_message", ({mock_template}) => {people.add_active_user(alice);current_filter = set_filter([- ["sender", "[email protected]"],- ["sender", "[email protected]"],+ ["sender", alice.user_id],+ ["sender", ray.user_id],]);narrow_banner.show_empty_narrow_message(current_filter);assert.equal(@@ -865,8 +864,8 @@ run_test("narrow_to_compose_target direct messages", ({override, override_rewireargs.called = true;});- let emails;- override(compose_pm_pill, "get_emails", () => emails);+ let user_ids;+ override(compose_pm_pill, "get_user_ids", () => user_ids);compose_state.set_message_type("private");people.add_active_user(ray);@@ -874,35 +873,35 @@ run_test("narrow_to_compose_target direct messages", ({override, override_rewirepeople.add_active_user(me);// Test with valid person- emails = "[email protected]";+ user_ids = [alice.user_id];args.called = false;message_view.to_compose_target();assert.equal(args.called, true);- assert.deepEqual(args.terms, [{operator: "dm", operand: "[email protected]"}]);+ assert.deepEqual(args.terms, [{operator: "dm", operand: [alice.user_id]}]);// Test with valid persons- emails = "[email protected],[email protected]";+ user_ids = [alice.user_id, ray.user_id];args.called = false;message_view.to_compose_target();assert.equal(args.called, true);- assert.deepEqual(args.terms, [{operator: "dm", operand: "[email protected],[email protected]"}]);+ assert.deepEqual(args.terms, [{operator: "dm", operand: [alice.user_id, ray.user_id]}]);// Test with some invalid persons- emails = "[email protected],random,[email protected]";+ user_ids = [alice.user_id, 9999, 8888];args.called = false;message_view.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.terms, [{operator: "is", operand: "dm"}]);// Test with all invalid persons- emails = "alice,random,ray";+ user_ids = [9999, 8888];args.called = false;message_view.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.terms, [{operator: "is", operand: "dm"}]);// Test with no persons- emails = "";+ user_ids = [];args.called = false;message_view.to_compose_target();assert.equal(args.called, true);@@ -931,7 +930,7 @@ run_test("narrow_compute_title", () => {filter = new Filter([{operator: "search", operand: "potato"}]);assert.equal(narrow_title.compute_narrow_title(filter), "translated: Search results");- filter = new Filter([{operator: "sender", operand: "me"}]);+ filter = new Filter([{operator: "sender", operand: me.user_id}]);assert.equal(narrow_title.compute_narrow_title(filter), "translated: Messages sent by you");// Stream narrows@@ -960,14 +959,14 @@ run_test("narrow_compute_title", () => {user_id: 31,full_name: "joe",};- people.add_active_user(joe);+ people.add_active_user(joe, "server_events");- filter = new Filter([{operator: "dm", operand: "[email protected]"}]);+ filter = new Filter([{operator: "dm", operand: [joe.user_id]}]);assert.equal(narrow_title.compute_narrow_title(filter), "joe");- filter = new Filter([{operator: "dm", operand: "[email protected],[email protected]"}]);+ filter = new Filter([{operator: "dm", operand: [9999, joe.user_id]}]);assert.equal(narrow_title.compute_narrow_title(filter), "translated: Invalid users");- filter = new Filter([{operator: "dm", operand: "[email protected]"}]);+ filter = new Filter([{operator: "dm", operand: [9999]}]);assert.equal(narrow_title.compute_narrow_title(filter), "translated: Invalid user");});diff --git a/web/tests/narrow_local.test.cjs b/web/tests/narrow_local.test.cjsindex 9ac94e624ce..8902a4f5716 100644--- a/web/tests/narrow_local.test.cjs+++ b/web/tests/narrow_local.test.cjs@@ -189,7 +189,7 @@ test_fixture("is private with no target", {});test_fixture("dm with target outside of range", {- filter_terms: [{operator: "dm", operand: "[email protected]"}],+ filter_terms: [{operator: "dm", operand: [1]}],target_id: 5,unread_info: {flavor: "not_found",diff --git a/web/tests/narrow_state.test.cjs b/web/tests/narrow_state.test.cjsindex 753bc882c48..da9309be581 100644--- a/web/tests/narrow_state.test.cjs+++ b/web/tests/narrow_state.test.cjs@@ -108,7 +108,7 @@ test("narrowed", () => {assert.ok(narrow_state.narrowed_by_stream_reply());assert.ok(!narrow_state.is_search_view());- set_filter([["dm", "[email protected]"]]);+ set_filter([["dm", [1]]]);assert.ok(narrow_state.narrowed_to_pms());assert.ok(narrow_state.narrowed_by_reply());assert.ok(narrow_state.narrowed_by_pm_reply());@@ -223,7 +223,7 @@ test("set_compose_defaults", () => {assert.equal(stream_and_topic.stream_id, foo_stream_id);assert.equal(stream_and_topic.topic, "Bar");- set_filter([["dm", "[email protected]"]]);+ set_filter([["dm", [1]]]);let dm_test = narrow_state.set_compose_defaults();assert.equal(dm_test.private_message_recipient, undefined);@@ -232,16 +232,15 @@ test("set_compose_defaults", () => {user_id: 57,full_name: "John Doe",};- people.add_active_user(john);- people.add_active_user(john);+ people.add_active_user(john, "server_events");- set_filter([["dm", "[email protected]"]]);+ set_filter([["dm", [john.user_id]]]);dm_test = narrow_state.set_compose_defaults();assert.deepEqual(dm_test.private_message_recipient_ids, [john.user_id]);// Even though we renamed "pm-with" to "dm",// compose defaults are set correctly.- set_filter([["pm-with", "[email protected]"]]);+ set_filter([["pm-with", [john.user_id]]]);dm_test = narrow_state.set_compose_defaults();assert.deepEqual(dm_test.private_message_recipient_ids, [john.user_id]);@@ -259,26 +258,6 @@ test("set_compose_defaults", () => {assert.equal(stream_test.stream_id, rome_id);});-test("update_email", () => {- const steve = {- email: "[email protected]",- user_id: 43,- full_name: "Steve",- };-- people.add_active_user(steve);- set_filter([- ["dm", "[email protected]"],- ["sender", "[email protected]"],- ["stream", "[email protected]"], // try to be tricky- ]);- narrow_state.update_email(steve.user_id, "[email protected]");- const filter = narrow_state.filter();- assert.deepEqual(filter.terms_with_operator("dm")[0].operand, "[email protected]");- assert.deepEqual(filter.terms_with_operator("sender")[0].operand, "[email protected]");- assert.deepEqual(filter.terms_with_operator("channel")[0].operand, "[email protected]");-});-test("topic", () => {set_filter([["stream", foo_stream.stream_id.toString()],@@ -296,8 +275,8 @@ test("topic", () => {assert.equal(narrow_state.topic(), undefined);set_filter([- ["sender", "[email protected]"],- ["dm", "[email protected]"],+ ["sender", 1],+ ["dm", [1]],]);assert.equal(narrow_state.topic(), undefined);@@ -323,7 +302,7 @@ test("stream_sub", () => {assert.deepEqual(narrow_state.stream_sub(), sub);set_filter([- ["sender", "someone"],+ ["sender", 1],["topic", "random"],]);assert.equal(narrow_state.stream_name(), undefined);@@ -344,11 +323,11 @@ test("pm_ids_string", () => {assert.equal(narrow_state.pm_ids_string(), undefined);assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set());- set_filter([["dm", ""]]);+ set_filter([["dm", []]]);assert.equal(narrow_state.pm_ids_string(), undefined);assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set());- set_filter([["dm", "[email protected]"]]);+ set_filter([["dm", [9999]]]);assert.equal(narrow_state.pm_ids_string(), undefined);assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set());@@ -364,10 +343,10 @@ test("pm_ids_string", () => {full_name: "Bob",};- people.add_active_user(alice);- people.add_active_user(bob);+ people.add_active_user(alice, "server_events");+ people.add_active_user(bob, "server_events");- set_filter([["dm", "[email protected],[email protected]"]]);+ set_filter([["dm", [alice.user_id, bob.user_id]]]);assert.equal(narrow_state.pm_ids_string(), "444,555");assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set([444, 555]));});diff --git a/web/tests/narrow_unread.test.cjs b/web/tests/narrow_unread.test.cjsindex 13c68b2b028..b3074ba3528 100644--- a/web/tests/narrow_unread.test.cjs+++ b/web/tests/narrow_unread.test.cjs@@ -20,7 +20,12 @@ const narrow_state = zrequire("narrow_state");const message_lists = zrequire("message_lists");const {set_current_user, set_realm} = zrequire("state_data");-set_current_user({});+const current_user = {+ email: "[email protected]",+ user_id: 123,+ full_name: "me",+};+set_current_user(current_user);set_realm(make_stream());const alice = {@@ -32,7 +37,8 @@ const alice = {const bogus_stream_id = "999999";people.init();-people.add_active_user(alice);+people.add_active_user(alice, "server_events");+people.add_active_user(current_user, "server_events");function set_filter(terms) {const filter = new Filter(terms);@@ -117,7 +123,8 @@ run_test("get_unread_ids", () => {assert.equal(unread_ids, undefined);assert_unread_info({flavor: "cannot_compute"});- terms = [{operator: "dm", operand: "123123"}];+ const bogus_user_id = 123123;+ terms = [{operator: "dm", operand: [bogus_user_id]}];set_filter(terms);unread_ids = candidate_ids();assert.deepEqual(unread_ids, []);@@ -168,7 +175,7 @@ run_test("get_unread_ids", () => {unread_ids = candidate_ids();assert.deepEqual(unread_ids, [stream_msg.id]);- terms = [{operator: "sender", operand: "[email protected]"}];+ terms = [{operator: "sender", operand: current_user.user_id}];set_filter(terms);// note that our candidate ids are just "all" ids nowunread_ids = candidate_ids();@@ -177,7 +184,7 @@ run_test("get_unread_ids", () => {// this actually does filteringassert_unread_info({flavor: "not_found"});- terms = [{operator: "dm", operand: "[email protected]"}];+ terms = [{operator: "dm", operand: [alice.user_id]}];set_filter(terms);unread_ids = candidate_ids();assert.deepEqual(unread_ids, []);@@ -210,12 +217,6 @@ run_test("get_unread_ids", () => {unread_ids = candidate_ids();assert.deepEqual(unread_ids, [stream_msg.id, private_msg.id]);- terms = [{operator: "dm", operand: "[email protected]"}];- set_filter(terms);-- unread_ids = candidate_ids();- assert.deepEqual(unread_ids, []);-terms = [{operator: "is", operand: "starred"}];set_filter(terms);unread_ids = candidate_ids();@@ -270,7 +271,8 @@ run_test("defensive code", ({override_rewire}) => {// couldn't compute the unread message ids, but that// invariant is hard to future-proof.override_rewire(narrow_state, "_possible_unread_message_ids", () => undefined);- const terms = [{operator: "dm", operand: "12344"}];+ const bogus_user_id = 123123;+ const terms = [{operator: "dm", operand: [bogus_user_id]}];set_filter(terms);assert_unread_info({flavor: "cannot_compute",diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjsindex 101c911d51c..ff4594df45b 100644--- a/web/tests/people.test.cjs+++ b/web/tests/people.test.cjs@@ -956,8 +956,10 @@ run_test("user_ids_to_full_names_array", () => {run_test("multi_user_methods", () => {initialize();- people.add_active_user(emp401);- people.add_active_user(emp402);+ // Add users to valid_user_ids.+ const source = "server_events";+ people.add_active_user(emp401, source);+ people.add_active_user(emp402, source);// The order of user_ids is relevant here.assert.equal(emp401.user_id, 401);@@ -966,11 +968,11 @@ run_test("multi_user_methods", () => {let emails_string = people.user_ids_string_to_emails_string("402,401");assert.equal(emails_string, "[email protected],[email protected]");- emails_string = people.slug_to_emails("402,401");- assert.equal(emails_string, "[email protected],[email protected]");+ let user_ids = people.slug_to_user_ids("402,401");+ assert.deepEqual(user_ids, [402, 401]);- emails_string = people.slug_to_emails("402,401-group");- assert.equal(emails_string, "[email protected],[email protected]");+ user_ids = people.slug_to_user_ids("402,401-group");+ assert.deepEqual(user_ids, [402, 401]);emails_string = "[email protected],[email protected]";let user_ids_string = people.emails_strings_to_user_ids_string(emails_string);@@ -979,9 +981,6 @@ run_test("multi_user_methods", () => {user_ids_string = people.reply_to_to_user_ids_string(emails_string);assert.equal(user_ids_string, "401,402");- const slug = people.emails_to_slug(emails_string);- assert.equal(slug, "401,402-group");-assert.equal(people.reply_to_to_user_ids_string("[email protected]"), undefined);assert.equal(people.user_ids_string_to_slug("401,402"), "401,402-group");@@ -1244,20 +1243,6 @@ run_test("maybe_incr_recipient_count", () => {assert.equal(people.get_recipient_count(maria), 1);});-run_test("slugs", () => {- initialize();- people.add_active_user(debbie);-- const slug = people.emails_to_slug(debbie.email);- assert.equal(slug, "501-Debra-Henton");-- const email = people.slug_to_emails(slug);- assert.equal(email, "[email protected]");-- // Test undefined slug- assert.equal(people.emails_to_slug("[email protected]"), undefined);-});-run_test("get_people_for_search_bar", ({override}) => {initialize();let user_ids;@@ -1465,7 +1450,8 @@ run_test("initialize", () => {assert.ok(people.is_valid_bulk_user_ids_for_compose([17, 16, 15]));blueslip.reset();blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id");- assert.ok(!people.is_valid_bulk_user_ids_for_compose([17, 9999, 15]));+ assert.ok(!people.is_valid_bulk_user_ids_for_compose([17, 9999, 15], false));+ blueslip.reset();assert.ok(people.is_my_user_id(42));const fetched_retiree = people.get_by_user_id(15);diff --git a/web/tests/people_errors.test.cjs b/web/tests/people_errors.test.cjsindex 5dfc1387a17..e5df73f651a 100644--- a/web/tests/people_errors.test.cjs+++ b/web/tests/people_errors.test.cjs@@ -42,9 +42,6 @@ run_test("report_late_add", ({override}) => {run_test("blueslip", () => {const unknown_email = "[email protected]";- blueslip.expect("debug", "User email operand unknown: " + unknown_email);- people.id_matches_email_operand(42, unknown_email);-blueslip.expect("error", "Unknown user_id");people.get_actual_name_from_user_id(9999);diff --git a/web/tests/pm_list_data.test.cjs b/web/tests/pm_list_data.test.cjsindex 8472d9225da..28850e0a554 100644--- a/web/tests/pm_list_data.test.cjs+++ b/web/tests/pm_list_data.test.cjs@@ -74,13 +74,15 @@ const bot_test = {is_admin: false,is_bot: true,};-people.add_active_user(alice);-people.add_active_user(bob);-people.add_active_user(me);-people.add_active_user(zoe);-people.add_active_user(cardelio);-people.add_active_user(iago);-people.add_active_user(bot_test);+// Add users to `valid_user_ids`.+const source = "server_events";+people.add_active_user(alice, source);+people.add_active_user(bob, source);+people.add_active_user(me, source);+people.add_active_user(zoe, source);+people.add_active_user(cardelio, source);+people.add_active_user(iago, source);+people.add_active_user(bot_test, source);people.initialize_current_user(me.user_id);function test(label, f) {@@ -91,8 +93,8 @@ function test(label, f) {});}-function set_pm_with_filter(emails) {- message_lists.set_current(make_message_list([{operator: "dm", operand: emails}]));+function set_pm_with_filter(user_ids) {+ message_lists.set_current(make_message_list([{operator: "dm", operand: user_ids}]));}function check_list_info(list, length, more_unread, recipients_array) {@@ -177,7 +179,7 @@ test("get_conversations", ({override}) => {is_bot: false,has_unread_mention: false,});- set_pm_with_filter("[email protected]");+ set_pm_with_filter([iago.user_id]);pm_data = pm_list_data.get_conversations();assert.deepEqual(pm_data, expected_data);@@ -246,15 +248,15 @@ test("get_active_user_ids_string", () => {message_lists.set_current(make_message_list([{operator: "stream", operand: "test"}]));assert.equal(pm_list_data.get_active_user_ids_string(), undefined);- set_pm_with_filter("[email protected],[email protected]");+ set_pm_with_filter([bob.user_id, alice.user_id]);assert.equal(pm_list_data.get_active_user_ids_string(), "101,102");- blueslip.expect("warn", "Unknown emails");- set_pm_with_filter("[email protected]");+ blueslip.expect("warn", "Invalid user_ids");+ set_pm_with_filter([-1]);assert.equal(pm_list_data.get_active_user_ids_string(), undefined);blueslip.reset();+ set_pm_with_filter([alice.user_id, bob.user_id, me.user_id]);assert.equal(pm_list_data.get_active_user_ids_string(), "101,102");});@@ -319,7 +321,7 @@ test("get_list_info_unread_messages", ({override}) => {// Narrowing to direct messages with Alice adds older// one-on-one conversation with her to the list and one// unread is removed from more_conversations_unread_count.- set_pm_with_filter("[email protected]");+ set_pm_with_filter([alice.user_id]);list_info = pm_list_data.get_list_info(false);check_list_info(list_info, 16, 1, ["Iago",@@ -395,7 +397,7 @@ test("get_list_info_no_unread_messages", ({override}) => {// Narrowing to direct messages with Alice adds older// one-on-one conversation with her to the list.- set_pm_with_filter("[email protected]");+ set_pm_with_filter([alice.user_id]);list_info = pm_list_data.get_list_info(false);check_list_info(list_info, 9, 0, ["Bob, Cardelio",diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjsindex 261d77e5561..039959f91a4 100644--- a/web/tests/search.test.cjs+++ b/web/tests/search.test.cjs@@ -42,6 +42,13 @@ const verona = {};stream_data.add_sub_for_tests(verona);+const zoe = {+ email: "[email protected]",+ user_id: 3,+ full_name: "Zoe",+};+people.add_active_user(zoe, "server_events");+run_test("initialize", ({override, override_rewire, mock_template}) => {const $search_query_box = $("#search_query");const $searchbox_form = $("#searchbox_form");@@ -174,21 +181,21 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {"dm-including:zo",{description_html: "group direct messages including",- search_string: "dm-including:[email protected]",+ search_string: "dm-including:" + zoe.user_id,},],["dm:zo",{description_html: "direct messages with",- search_string: "dm:[email protected]",+ search_string: `dm:${zoe.user_id}`,},],["sender:zo",{description_html: "sent by",- search_string: "sender:[email protected]",+ search_string: `sender:${zoe.user_id}`,},],[@@ -213,11 +220,14 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {let expected_value = `<div class="search_list_item">\n <div class="description">${description_html}</div>\n \n</div>\n`;assert.equal(opts.item_html(source[0], "zo"), expected_value);- people.add_active_user({- email: "[email protected]",- user_id: 3,- full_name: "Zoe",- });+ people.add_active_user(+ {+ email: "[email protected]",+ user_id: 3,+ full_name: "Zoe",+ },+ "server_events",+ );override(realm, "realm_enable_guest_user_indicator", true);expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class="user-pill-container pill" tabindex=0>\n <span class="pill-label">sender:\n </span>\n <div class="pill" data-user-id="3">\n <img class="pill-image" src="/avatar/3" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">Zoe</span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n </div>\n</div>\n</span>\n \n</div>\n`;assert.equal(opts.item_html(source[1], "zo"), expected_value);diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjsindex 190b4d76f98..b34be7cdc84 100644--- a/web/tests/search_suggestion.test.cjs+++ b/web/tests/search_suggestion.test.cjs@@ -66,12 +66,14 @@ function new_stream_id() {function init({override}) {override(current_user, "is_admin", true);+ // Add users to `valid_user_ids`.+ const source = "server_events";people.init();- people.add_active_user(bob);- people.add_active_user(me);- people.add_active_user(ted);- people.add_active_user(alice);- people.add_active_user(jeff);+ people.add_active_user(bob, source);+ people.add_active_user(me, source);+ people.add_active_user(ted, source);+ people.add_active_user(alice, source);+ people.add_active_user(jeff, source);people.initialize_current_user(me.user_id);@@ -81,7 +83,10 @@ function init({override}) {}function get_suggestions(query, pill_query = "") {- return search.get_suggestions(Filter.parse(pill_query), Filter.parse(query));+ return search.get_suggestions(+ Filter.parse(pill_query).map((suggestion) => Filter.convert_suggestion_to_term(suggestion)),+ Filter.parse(query),+ );}function test(label, f) {@@ -155,11 +160,11 @@ test("dm_suggestions", ({override}) => {let suggestions = get_suggestions(query);let expected = ["is:dm",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",+ `dm:${alice.user_id}`,+ `dm:${bob.user_id}`,+ `dm:${jeff.user_id}`,+ `dm:${me.user_id}`,+ `dm:${ted.user_id}`,];assert.deepEqual(suggestions.strings, expected);@@ -168,9 +173,9 @@ test("dm_suggestions", ({override}) => {expected = ["is:dm al","is:dm is:alerted",- "is:dm dm:[email protected]",- "is:dm sender:[email protected]",- "is:dm dm-including:[email protected]",+ `is:dm dm:${alice.user_id}`,+ `is:dm sender:${alice.user_id}`,+ `is:dm dm-including:${alice.user_id}`,];assert.deepEqual(suggestions.strings, expected);@@ -187,52 +192,52 @@ test("dm_suggestions", ({override}) => {// Same search suggestions as for "is:dm"expected = ["is:dm",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",+ `dm:${alice.user_id}`,+ `dm:${bob.user_id}`,+ `dm:${jeff.user_id}`,+ `dm:${me.user_id}`,+ `dm:${ted.user_id}`,];assert.deepEqual(suggestions.strings, expected);query = "dm:t";suggestions = get_suggestions(query);- expected = ["dm:[email protected]"];+ expected = [`dm:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "-dm:t";suggestions = get_suggestions(query);- expected = ["is:dm -dm:[email protected]"];+ expected = [`is:dm -dm:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);- query = "dm:[email protected]";+ query = `dm:${ted.user_id}`;suggestions = get_suggestions(query);- expected = ["dm:[email protected]"];+ expected = [`dm:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "sender:ted";suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "sender:te";suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "-sender:te";suggestions = get_suggestions(query);- expected = ["-sender:[email protected]"];+ expected = [`-sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);- query = "sender:[email protected]";+ query = `sender:${ted.user_id}`;suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "is:unread from:ted";suggestions = get_suggestions(query);- expected = ["is:unread sender:[email protected]"];+ expected = [`is:unread sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);// Users can enter bizarre queries, and if they do, we want to@@ -242,15 +247,15 @@ test("dm_suggestions", ({override}) => {expected = ["is:dm near:3"];assert.deepEqual(suggestions.strings, expected);- query = "dm:[email protected] near:3";+ query = `dm:${ted.user_id} near:3`;suggestions = get_suggestions(query);- expected = ["dm:[email protected] near:3"];+ expected = [`dm:${ted.user_id} near:3`];assert.deepEqual(suggestions.strings, expected);// Make sure suggestions still work if preceding tokens- query = "is:alerted sender:[email protected]";+ query = `is:alerted sender:${ted.user_id}`;suggestions = get_suggestions(query);- expected = ["is:alerted sender:[email protected]"];+ expected = [`is:alerted sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "is:starred has:link is:dm al";@@ -258,15 +263,15 @@ test("dm_suggestions", ({override}) => {expected = ["is:starred has:link is:dm al","is:starred has:link is:dm is:alerted",- "is:starred has:link is:dm dm:[email protected]",- "is:starred has:link is:dm sender:[email protected]",- "is:starred has:link is:dm dm-including:[email protected]",+ `is:starred has:link is:dm dm:${alice.user_id}`,+ `is:starred has:link is:dm sender:${alice.user_id}`,+ `is:starred has:link is:dm dm-including:${alice.user_id}`,];assert.deepEqual(suggestions.strings, expected);- query = "from:[email protected]";+ query = `from:${ted.user_id}`;suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);// "pm-with" operator returns search result@@ -279,7 +284,7 @@ test("dm_suggestions", ({override}) => {query = "pm-with:t";suggestions = get_suggestions(query);- expected = ["dm:[email protected]"];+ expected = [`dm:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);});@@ -287,25 +292,25 @@ test("group_suggestions", () => {// If there's an existing completed user pill right before// the input string, we suggest a user group as one of the// suggestions.- let pill_query = "dm:[email protected]";+ let pill_query = `dm:${bob.user_id}`;let query = "alice";let suggestions = get_suggestions(query, pill_query);let expected = [- "dm:[email protected] alice",- "dm:[email protected],[email protected]",- "dm:[email protected] sender:[email protected]",- "dm:[email protected] dm-including:[email protected]",+ `dm:${bob.user_id} alice`,+ `dm:${bob.user_id},${alice.user_id}`,+ `dm:${bob.user_id} sender:${alice.user_id}`,+ `dm:${bob.user_id} dm-including:${alice.user_id}`,];assert.deepEqual(suggestions.strings, expected);// Do not suggest "[email protected]" (the name of the current user) for dms- pill_query = "dm:[email protected]";+ pill_query = `dm:${ted.user_id}`;query = "my";suggestions = get_suggestions(query, pill_query);expected = [- "dm:[email protected] my",- "dm:[email protected] sender:[email protected]",- "dm:[email protected] dm-including:[email protected]",+ `dm:${ted.user_id} my`,+ `dm:${ted.user_id} sender:${me.user_id}`,+ `dm:${ted.user_id} dm-including:${me.user_id}`,];assert.deepEqual(suggestions.strings, expected);@@ -314,38 +319,38 @@ test("group_suggestions", () => {query = "-dm:[email protected]";suggestions = get_suggestions(query);- expected = ["is:dm -dm:[email protected]"];+ expected = [`is:dm -dm:${bob.user_id}`];assert.deepEqual(suggestions.strings, expected);// If user types "pm-with" operator, show suggestions for// group direct messages with the "dm" operator.- pill_query = "pm-with:[email protected]";+ pill_query = `pm-with:${bob.user_id}`;query = "alice";suggestions = get_suggestions(query, pill_query);expected = [- "dm:[email protected] alice",- "dm:[email protected],[email protected]",- "dm:[email protected] sender:[email protected]",- "dm:[email protected] dm-including:[email protected]",+ `dm:${bob.user_id} alice`,+ `dm:${bob.user_id},${alice.user_id}`,+ `dm:${bob.user_id} sender:${alice.user_id}`,+ `dm:${bob.user_id} dm-including:${alice.user_id}`,];assert.deepEqual(suggestions.strings, expected);// Test multiple terms- pill_query = "is:starred has:link dm:[email protected]";+ pill_query = `is:starred has:link dm:${bob.user_id}`;query = "Smit";suggestions = get_suggestions(query, pill_query);expected = [- "is:starred has:link dm:[email protected] Smit",- "is:starred has:link dm:[email protected],[email protected]",- "is:starred has:link dm:[email protected] sender:[email protected]",- "is:starred has:link dm:[email protected] dm-including:[email protected]",+ `is:starred has:link dm:${bob.user_id} Smit`,+ `is:starred has:link dm:${bob.user_id},${ted.user_id}`,+ `is:starred has:link dm:${bob.user_id} sender:${ted.user_id}`,+ `is:starred has:link dm:${bob.user_id} dm-including:${ted.user_id}`,];assert.deepEqual(suggestions.strings, expected);// Doesn't show dms because it's invalid in combination// with a channel. (Random channel id.)stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});- query = "channel:66 has:link dm:[email protected],Smit";+ query = `channel:66 has:link dm:${bob.user_id},Smit`;suggestions = get_suggestions(query);expected = [];assert.deepEqual(suggestions.strings, expected);@@ -384,7 +389,7 @@ test("empty_query_suggestions", () => {"is:muted","is:resolved","-is:resolved",- "sender:[email protected]",+ `sender:${me.user_id}`,`channel:${devel_id}`,`channel:${office_id}`,"has:link",@@ -457,9 +462,9 @@ test("check_is_suggestions", ({override}) => {"is:unread","is:muted","is:resolved",- "dm:[email protected]",- "sender:[email protected]",- "dm-including:[email protected]",+ `dm:${alice.user_id}`,+ `sender:${alice.user_id}`,+ `dm-including:${alice.user_id}`,"has:image",];assert.deepEqual(suggestions.strings, expected);@@ -524,46 +529,46 @@ test("sent_by_me_suggestions", ({override}) => {let query = "";let suggestions = get_suggestions(query);- assert.ok(suggestions.strings.includes("sender:[email protected]"));+ assert.ok(suggestions.strings.includes(`sender:${me.user_id}`));query = "sender";suggestions = get_suggestions(query);- let expected = ["sender", "sender:", "sender:[email protected]"];+ let expected = ["sender", "sender:", `sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "-sender";suggestions = get_suggestions(query);- expected = ["-sender", "-sender:", "-sender:[email protected]"];+ expected = ["-sender", "-sender:", `-sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "from";suggestions = get_suggestions(query);- expected = ["from", "sender:", "sender:[email protected]"];+ expected = ["from", "sender:", `sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "-from";suggestions = get_suggestions(query);- expected = ["-from", "-sender:", "-sender:[email protected]"];+ expected = ["-from", "-sender:", `-sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);- query = "sender:[email protected]";+ query = `sender:${bob.user_id}`;suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${bob.user_id}`];assert.deepEqual(suggestions.strings, expected);- query = "from:[email protected]";+ query = `from:${bob.user_id}`;suggestions = get_suggestions(query);- expected = ["sender:[email protected]"];+ expected = [`sender:${bob.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "sent";suggestions = get_suggestions(query);- expected = ["sent", "sender:[email protected]"];+ expected = ["sent", `sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "-sent";suggestions = get_suggestions(query);- expected = ["-sent", "-sender:[email protected]"];+ expected = ["-sent", `-sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);const denmark_id = new_stream_id();@@ -573,13 +578,13 @@ test("sent_by_me_suggestions", ({override}) => {suggestions = get_suggestions(query);expected = [`channel:${denmark_id} topic:Denmark1 sent`,- `channel:${denmark_id} topic:Denmark1 sender:[email protected]`,+ `channel:${denmark_id} topic:Denmark1 sender:${me.user_id}`,];assert.deepEqual(suggestions.strings, expected);query = "is:starred sender:m";suggestions = get_suggestions(query);- expected = ["is:starred sender:[email protected]"];+ expected = [`is:starred sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);});@@ -597,7 +602,7 @@ test("topic_suggestions", ({override}) => {stream_data.add_sub_for_tests({stream_id: office_id, name: "office", subscribed: true});suggestions = get_suggestions("te");- expected = ["te", "dm:[email protected]", "sender:[email protected]", "dm-including:[email protected]"];+ expected = ["te", `dm:${ted.user_id}`, `sender:${ted.user_id}`, `dm-including:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);stream_topic_history.add_message({@@ -615,9 +620,9 @@ test("topic_suggestions", ({override}) => {suggestions = get_suggestions("te");expected = ["te",- "dm:[email protected]",- "sender:[email protected]",- "dm-including:[email protected]",+ `dm:${ted.user_id}`,+ `sender:${ted.user_id}`,+ `dm-including:${ted.user_id}`,`channel:${office_id} topic:team`,`channel:${office_id} topic:✔+team+work`,`channel:${office_id} topic:test`,@@ -848,12 +853,6 @@ test("people_suggestions", ({override}) => {override(narrow_state, "stream_id", noop);- const ted = {- email: "[email protected]",- user_id: 201,- full_name: "Ted Smith",- };-const bob = {email: "[email protected]",user_id: 202,@@ -867,9 +866,9 @@ test("people_suggestions", ({override}) => {user_id: 203,full_name: "Alice Ignore",};- people.add_active_user(ted);- people.add_active_user(bob);- people.add_active_user(alice);+ people.add_active_user(ted, "server_events");+ people.add_active_user(bob, "server_events");+ people.add_active_user(alice, "server_events");// Add an inaccessible user to verify that it is not included in// suggestions.@@ -887,12 +886,12 @@ test("people_suggestions", ({override}) => {let expected = ["te",- "dm:[email protected]", // bob térry- "dm:[email protected]",- "sender:[email protected]",- "sender:[email protected]",- "dm-including:[email protected]",- "dm-including:[email protected]",+ `dm:${bob.user_id}`, // bob térry+ `dm:${ted.user_id}`,+ `sender:${bob.user_id}`,+ `sender:${ted.user_id}`,+ `dm-including:${bob.user_id}`,+ `dm-including:${ted.user_id}`,];assert.deepEqual(suggestions.strings, expected);@@ -902,36 +901,36 @@ test("people_suggestions", ({override}) => {full_name: "Test unknown user",email: "[email protected]",};- people.add_active_user(accessible_user);+ people.add_active_user(accessible_user, "server_events");suggestions = get_suggestions(query);expected = ["te",- "dm:[email protected]",- "dm:[email protected]",- "dm:[email protected]",- "sender:[email protected]",- "sender:[email protected]",- "sender:[email protected]",- "dm-including:[email protected]",- "dm-including:[email protected]",- "dm-including:[email protected]",+ `dm:${bob.user_id}`,+ `dm:${ted.user_id}`,+ `dm:${inaccessible_user.user_id}`,+ `sender:${bob.user_id}`,+ `sender:${ted.user_id}`,+ `sender:${inaccessible_user.user_id}`,+ `dm-including:${bob.user_id}`,+ `dm-including:${ted.user_id}`,+ `dm-including:${inaccessible_user.user_id}`,];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions("Ted "); // note space- expected = ["Ted", "dm:[email protected]", "sender:[email protected]", "dm-including:[email protected]"];+ expected = ["Ted", `dm:${ted.user_id}`, `sender:${ted.user_id}`, `dm-including:${ted.user_id}`];assert.deepEqual(suggestions.strings, expected);query = "sender:ted sm";- expected = ["sender:[email protected]"];+ expected = [`sender:${ted.user_id}`];suggestions = get_suggestions(query);assert.deepEqual(suggestions.strings, expected);query = "sender:[email protected] new";- expected = ["sender:[email protected] new"];+ expected = ["new"];suggestions = get_suggestions(query);assert.deepEqual(suggestions.strings, expected);@@ -958,7 +957,7 @@ test("operator_suggestions", ({override}) => {query = "-s";suggestions = get_suggestions(query);- expected = ["-s", "-sender:", "-channels:", "-channel:", "-sender:[email protected]"];+ expected = ["-s", "-sender:", "-channels:", "-channel:", `-sender:${me.user_id}`];assert.deepEqual(suggestions.strings, expected);stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});@@ -967,7 +966,7 @@ test("operator_suggestions", ({override}) => {expected = ["channel:66 is:alerted -f","channel:66 is:alerted -sender:",- "channel:66 is:alerted -sender:[email protected]",+ `channel:66 is:alerted -sender:${me.user_id}`,];assert.deepEqual(suggestions.strings, expected);});diff --git a/web/tests/typing_events.test.cjs b/web/tests/typing_events.test.cjsindex 3864fbdf448..e5e32bf408c 100644--- a/web/tests/typing_events.test.cjs+++ b/web/tests/typing_events.test.cjs@@ -54,8 +54,7 @@ run_test("render_notifications_for_narrow", ({override, mock_template}) => {override(settings_data, "user_can_access_all_other_users", () => true);const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];const conversation_key = typing_data.get_direct_message_conversation_key(group);- const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;- message_lists.set_current(make_message_list([{operator: "dm", operand: group_emails}]));+ message_lists.set_current(make_message_list([{operator: "dm", operand: group}]));const $typing_notifications = $("#typing_notifications");