narrow: Migrate uses of by function to activate function.

This is part of renaming effort of `narrow` to `message_view`.
This commit is contained in:
Aman Agrawal
2024-06-05 06:54:45 +00:00
committed by Tim Abbott
parent 552ab984a9
commit 9374195418
7 changed files with 85 additions and 19 deletions

View File

@@ -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();

View File

@@ -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);
}
}

View File

@@ -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();
});

View File

@@ -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"},
);
}
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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");
});