Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

narrow: Migrate uses of `by` function to `activate` function.

Aman Agrawal9374195418f6
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 9d25f0690ba..3cb3af94114 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -925,7 +925,15 @@ export function process_hotkey(e, hotkey) {
// Shortcuts that don't require a message
switch (event_name) {
case "narrow_private":
- narrow.by("is", "dm", {trigger: "hotkey"});
+ narrow.activate(
+ [
+ {
+ operator: "is",
+ operand: "dm",
+ },
+ ],
+ {trigger: "hotkey"},
+ );
return true;
case "query_streams":
stream_list.initiate_search();
diff --git a/web/src/narrow.js b/web/src/narrow.js
index 4aeef8d5db3..8745e70a196 100644
--- a/web/src/narrow.js
+++ b/web/src/narrow.js
@@ -997,12 +997,6 @@ export function narrow_to_next_pm_string(opts = {}) {
activate(filter_expr, updated_opts);
}
-// Activate narrowing with a single operator.
-// This is just for syntactic convenience.
-export function by(operator, operand, opts) {
- activate([{operator, operand}], opts);
-}
-
export function by_topic(target_id, opts) {
// don't use message_lists.current as it won't work for muted messages or for out-of-narrow links
const original = message_store.get(target_id);
@@ -1050,7 +1044,7 @@ export function by_recipient(target_id, opts) {
// in the new view.
unread_ops.notify_server_message_read(message);
}
- by("dm", message.reply_to, opts);
+ activate([{operator: "dm", operand: message.reply_to}], opts);
break;
case "stream":
@@ -1064,7 +1058,15 @@ export function by_recipient(target_id, opts) {
// in the new view.
unread_ops.notify_server_message_read(message);
}
- by("stream", stream_data.get_stream_name_from_id(message.stream_id), opts);
+ activate(
+ [
+ {
+ operator: "stream",
+ operand: stream_data.get_stream_name_from_id(message.stream_id),
+ },
+ ],
+ opts,
+ );
break;
}
}
@@ -1104,10 +1106,10 @@ export function to_compose_target() {
// If there are no recipients or any recipient is
// invalid, narrow to your direct message feed.
if (emails.length === 0 || invalid.length > 0) {
- by("is", "dm", opts);
+ activate([{operator: "is", operand: "dm"}], opts);
return;
}
- by("dm", util.normalize_recipients(recipient_string), opts);
+ activate([{operator: "dm", operand: util.normalize_recipients(recipient_string)}], opts);
}
}
diff --git a/web/src/personal_menu_popover.js b/web/src/personal_menu_popover.js
index 4e43ddde14b..3a925552851 100644
--- a/web/src/personal_menu_popover.js
+++ b/web/src/personal_menu_popover.js
@@ -79,7 +79,15 @@ export function initialize() {
$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;
- narrow.by("dm", email, {trigger: "personal menu"});
+ narrow.activate(
+ [
+ {
+ operator: "dm",
+ operand: email,
+ },
+ ],
+ {trigger: "personal menu"},
+ );
popovers.hide_all();
e.preventDefault();
});
@@ -87,7 +95,15 @@ export function initialize() {
$popper.one("click", ".narrow-messages-sent", (e) => {
const user_id = current_user.user_id;
const email = people.get_by_user_id(user_id).email;
- narrow.by("sender", email, {trigger: "personal menu"});
+ narrow.activate(
+ [
+ {
+ operator: "sender",
+ operand: email,
+ },
+ ],
+ {trigger: "personal menu"},
+ );
popovers.hide_all();
e.preventDefault();
});
diff --git a/web/src/tutorial.js b/web/src/tutorial.js
index 486d201782d..46d656f7717 100644
--- a/web/src/tutorial.js
+++ b/web/src/tutorial.js
@@ -13,6 +13,14 @@ function set_tutorial_status(status, callback) {
export function initialize() {
if (page_params.needs_tutorial) {
set_tutorial_status("started");
- narrow.by("is", "private", {trigger: "sidebar"});
+ narrow.activate(
+ [
+ {
+ operator: "is",
+ operand: "private",
+ },
+ ],
+ {trigger: "sidebar"},
+ );
}
}
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index fbd0773ebd8..3affd3c28c6 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -774,7 +774,15 @@ export function initialize_everything(state_data) {
const sub = sub_store.get(stream_id);
sidebar_ui.hide_all();
popovers.hide_all();
- narrow.by("stream", sub.name, {trigger});
+ narrow.activate(
+ [
+ {
+ operator: "stream",
+ operand: sub.name,
+ },
+ ],
+ {trigger},
+ );
activity_ui.build_user_sidebar();
},
});
@@ -851,7 +859,15 @@ export function initialize_everything(state_data) {
activity.initialize();
activity_ui.initialize({
narrow_by_email(email) {
- narrow.by("dm", email, {trigger: "sidebar"});
+ narrow.activate(
+ [
+ {
+ operator: "dm",
+ operand: email,
+ },
+ ],
+ {trigger: "sidebar"},
+ );
},
});
// This needs to happen after activity_ui.initialize, so that user_filter
diff --git a/web/src/user_card_popover.js b/web/src/user_card_popover.js
index 303166be33c..7483cc1f82f 100644
--- a/web/src/user_card_popover.js
+++ b/web/src/user_card_popover.js
@@ -688,7 +688,15 @@ function register_click_handlers() {
$("body").on("click", ".user-card-popover-actions .narrow_to_private_messages", (e) => {
const user_id = elem_to_user_id($(e.target).parents("ul"));
const email = people.get_by_user_id(user_id).email;
- narrow.by("dm", email, {trigger: "user sidebar popover"});
+ narrow.activate(
+ [
+ {
+ operator: "dm",
+ operand: email,
+ },
+ ],
+ {trigger: "user sidebar popover"},
+ );
hide_all();
if (overlays.any_active()) {
overlays.close_active();
@@ -700,7 +708,15 @@ function register_click_handlers() {
$("body").on("click", ".user-card-popover-actions .narrow_to_messages_sent", (e) => {
const user_id = elem_to_user_id($(e.target).parents("ul"));
const email = people.get_by_user_id(user_id).email;
- narrow.by("sender", email, {trigger: "user sidebar popover"});
+ narrow.activate(
+ [
+ {
+ operator: "sender",
+ operand: email,
+ },
+ ],
+ {trigger: "user sidebar popover"},
+ );
hide_all();
if (overlays.any_active()) {
overlays.close_active();
diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js
index 440fd3958d0..c5b583947f1 100644
--- a/web/tests/hotkey.test.js
+++ b/web/tests/hotkey.test.js
@@ -318,7 +318,7 @@ run_test("basic mappings", () => {
assert_mapping("c", compose_actions, "start");
assert_mapping("x", compose_actions, "start");
- assert_mapping("P", narrow, "by");
+ assert_mapping("P", narrow, "activate");
assert_mapping("g", gear_menu, "toggle");
});