From fecb9afa9424f3fb06e8152d2d6d8252dc4e2ade Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 5 Jun 2024 07:36:28 +0000 Subject: [PATCH] narrow: Rename `activate` to `show`. This make the main call which displays message list sound similar to `recent_view.show` and `inbox_ui.show`. --- web/src/drafts_overlay_ui.js | 4 +-- web/src/hashchange.js | 4 +-- web/src/hotkey.js | 8 +++--- web/src/message_events.js | 2 +- web/src/narrow.js | 42 +++++++++++++++---------------- web/src/personal_menu_popover.js | 4 +-- web/src/scheduled_messages_ui.js | 4 +-- web/src/tutorial.js | 2 +- web/src/ui_init.js | 8 +++--- web/src/user_card_popover.js | 4 +-- web/tests/hashchange.test.js | 12 ++++----- web/tests/hotkey.test.js | 2 +- web/tests/narrow.test.js | 6 ++--- web/tests/narrow_activate.test.js | 10 ++++---- 14 files changed, 56 insertions(+), 56 deletions(-) diff --git a/web/src/drafts_overlay_ui.js b/web/src/drafts_overlay_ui.js index 5b62338a3b..a4b08dc7f4 100644 --- a/web/src/drafts_overlay_ui.js +++ b/web/src/drafts_overlay_ui.js @@ -24,7 +24,7 @@ function restore_draft(draft_id) { if (compose_args.type === "stream") { if (draft.stream_id !== undefined && draft.topic !== "") { - narrow.activate( + narrow.show( [ { operator: "channel", @@ -37,7 +37,7 @@ function restore_draft(draft_id) { } } else { if (compose_args.private_message_recipient !== "") { - narrow.activate([{operator: "dm", operand: compose_args.private_message_recipient}], { + narrow.show([{operator: "dm", operand: compose_args.private_message_recipient}], { trigger: "restore draft", }); } diff --git a/web/src/hashchange.js b/web/src/hashchange.js index 8f619adda6..dfeb5b2cab 100644 --- a/web/src/hashchange.js +++ b/web/src/hashchange.js @@ -57,7 +57,7 @@ function show_all_message_view() { // Don't export this function outside of this module since // `change_hash` is false here which means it is should only // be called after hash is updated in the URL. - narrow.activate([{operator: "in", operand: "home"}], { + narrow.show([{operator: "in", operand: "home"}], { trigger: "hashchange", change_hash: false, then_select_id: history.state?.narrow_pointer, @@ -198,7 +198,7 @@ function do_hashchange_normal(from_reload) { narrow_opts.then_select_offset = data_for_hash.narrow_offset; narrow_opts.show_more_topics = data_for_hash.show_more_topics ?? false; } - narrow.activate(terms, narrow_opts); + narrow.show(terms, narrow_opts); return true; } case "": diff --git a/web/src/hotkey.js b/web/src/hotkey.js index a643e1a950..a546a3a1ea 100644 --- a/web/src/hotkey.js +++ b/web/src/hotkey.js @@ -925,7 +925,7 @@ export function process_hotkey(e, hotkey) { // Shortcuts that don't require a message switch (event_name) { case "narrow_private": - narrow.activate( + narrow.show( [ { operator: "is", @@ -1194,10 +1194,10 @@ export function process_hotkey(e, hotkey) { case "zoom_to_message_near": { // The following code is essentially equivalent to // `window.location = hashutil.by_conversation_and_time_url(msg)` - // but we use `narrow.activate` to pass in the `trigger` parameter + // but we use `narrow.show` to pass in the `trigger` parameter switch (msg.type) { case "private": - narrow.activate( + narrow.show( [ {operator: "dm", operand: msg.reply_to}, {operator: "near", operand: msg.id}, @@ -1206,7 +1206,7 @@ export function process_hotkey(e, hotkey) { ); return true; case "stream": - narrow.activate( + narrow.show( [ { operator: "channel", diff --git a/web/src/message_events.js b/web/src/message_events.js index f9245d1373..439327e59e 100644 --- a/web/src/message_events.js +++ b/web/src/message_events.js @@ -429,7 +429,7 @@ export function update_messages(events) { trigger: "stream/topic change", then_select_id: current_selected_id, }; - narrow.activate(terms, opts); + narrow.show(terms, opts); } } diff --git a/web/src/narrow.js b/web/src/narrow.js index f561c31ac0..e6fed8e71a 100644 --- a/web/src/narrow.js +++ b/web/src/narrow.js @@ -171,7 +171,7 @@ function create_and_update_message_list(filter, id_info, opts) { // // It's fine for the hash change to happen anytime before updating // the current message list as we are trying to emulate the `hashchange` - // workflow we have which calls `narrow.activate` after hash is updated. + // workflow we have which calls `narrow.show` after hash is updated. if (opts.change_hash) { update_hash_to_match_filter(filter, opts.trigger); opts.show_more_topics = history.state?.show_more_topics ?? false; @@ -219,7 +219,7 @@ function handle_post_message_list_change( compose_recipient.handle_middle_pane_transition(); } -export function activate(raw_terms, opts) { +export function show(raw_terms, opts) { /* Main entry point for switching to a new view / message list. Supported parameters: @@ -271,12 +271,12 @@ export function activate(raw_terms, opts) { // cause you to end up in the wrong place if you are actively scrolling // on an unnarrow. Wait a bit and try again once the scrolling is likely over. setTimeout(() => { - activate(raw_terms, opts); + show(raw_terms, opts); }, 50); return; } - // Since narrow.activate is called directly from various + // Since narrow.show is called directly from various // places in our code without passing through hashchange, // we need to check if the narrow is allowed for spectator here too. if ( @@ -405,7 +405,7 @@ export function activate(raw_terms, opts) { return; } - activate(adjusted_terms, { + show(adjusted_terms, { ...opts, // Update the URL fragment to reflect the redirect. change_hash: true, @@ -438,7 +438,7 @@ export function activate(raw_terms, opts) { ) { const adjusted_terms = adjusted_terms_if_moved(raw_terms, target_message); if (adjusted_terms !== null) { - activate(adjusted_terms, { + show(adjusted_terms, { ...opts, // Update the URL fragment to reflect the redirect. change_hash: true, @@ -456,10 +456,10 @@ export function activate(raw_terms, opts) { success(data) { // After the message is fetched, we make the // message locally available and then call - // narrow.activate recursively, setting a flag to + // narrow.show recursively, setting a flag to // indicate we've already done this. message_helper.process_new_message(data.message); - activate(raw_terms, { + show(raw_terms, { ...opts, fetched_target_message: true, }); @@ -470,15 +470,15 @@ export function activate(raw_terms, opts) { // happen, for example, if a user types // `stream:foo topic:bar near:1` into the search // box. No special rewriting is required, so call - // narrow.activate recursively. - activate(raw_terms, { + // narrow.show recursively. + show(raw_terms, { fetched_target_message: true, ...opts, }); }, }); - // The channel.get will call narrow.activate recursively + // The channel.get will call narrow.show recursively // from a continuation unconditionally; the correct thing // to do here is return. return; @@ -487,7 +487,7 @@ export function activate(raw_terms, opts) { // IMPORTANT: No code that modifies UI state should appear above // this point. This is important to prevent calling such functions - // more than once in the event that we call narrow.activate + // more than once in the event that we call narrow.show // recursively. reset_ui_state(opts); @@ -890,7 +890,7 @@ export function render_message_list_with_selected_message(opts) { export function activate_stream_for_cycle_hotkey(stream_name) { // This is the common code for A/D hotkeys. const filter_expr = [{operator: "channel", operand: stream_name}]; - activate(filter_expr, {}); + show(filter_expr, {}); } export function stream_cycle_backward() { @@ -964,7 +964,7 @@ export function narrow_to_next_topic(opts = {}) { {operator: "topic", operand: next_narrow.topic}, ]; - activate(filter_expr, opts); + show(filter_expr, opts); } export function narrow_to_next_pm_string(opts = {}) { @@ -994,7 +994,7 @@ export function narrow_to_next_pm_string(opts = {}) { force_close: true, }; - activate(filter_expr, updated_opts); + show(filter_expr, updated_opts); } export function by_topic(target_id, opts) { @@ -1024,7 +1024,7 @@ export function by_topic(target_id, opts) { {operator: "topic", operand: original.topic}, ]; opts = {then_select_id: target_id, ...opts}; - activate(search_terms, opts); + show(search_terms, opts); } export function narrow_by_recipient(target_id, opts) { @@ -1044,7 +1044,7 @@ export function narrow_by_recipient(target_id, opts) { // in the new view. unread_ops.notify_server_message_read(message); } - activate([{operator: "dm", operand: message.reply_to}], opts); + show([{operator: "dm", operand: message.reply_to}], opts); break; case "stream": @@ -1058,7 +1058,7 @@ export function narrow_by_recipient(target_id, opts) { // in the new view. unread_ops.notify_server_message_read(message); } - activate( + show( [ { operator: "stream", @@ -1095,7 +1095,7 @@ export function to_compose_target() { if (topic !== "") { terms.push({operator: "topic", operand: topic}); } - activate(terms, opts); + show(terms, opts); return; } @@ -1106,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) { - activate([{operator: "is", operand: "dm"}], opts); + show([{operator: "is", operand: "dm"}], opts); return; } - activate([{operator: "dm", operand: util.normalize_recipients(recipient_string)}], opts); + show([{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 3a92555285..ef4185f3e3 100644 --- a/web/src/personal_menu_popover.js +++ b/web/src/personal_menu_popover.js @@ -79,7 +79,7 @@ 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.activate( + narrow.show( [ { operator: "dm", @@ -95,7 +95,7 @@ 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.activate( + narrow.show( [ { operator: "sender", diff --git a/web/src/scheduled_messages_ui.js b/web/src/scheduled_messages_ui.js index f1763b658c..fbe51e4fa1 100644 --- a/web/src/scheduled_messages_ui.js +++ b/web/src/scheduled_messages_ui.js @@ -19,7 +19,7 @@ export function hide_scheduled_message_success_compose_banner(scheduled_message_ function narrow_via_edit_scheduled_message(compose_args) { if (compose_args.message_type === "stream") { - narrow.activate( + narrow.show( [ { operator: "channel", @@ -30,7 +30,7 @@ function narrow_via_edit_scheduled_message(compose_args) { {trigger: "edit scheduled message"}, ); } else { - narrow.activate([{operator: "dm", operand: compose_args.private_message_recipient}], { + narrow.show([{operator: "dm", operand: compose_args.private_message_recipient}], { trigger: "edit scheduled message", }); } diff --git a/web/src/tutorial.js b/web/src/tutorial.js index 46d656f771..bd849e1cfc 100644 --- a/web/src/tutorial.js +++ b/web/src/tutorial.js @@ -13,7 +13,7 @@ function set_tutorial_status(status, callback) { export function initialize() { if (page_params.needs_tutorial) { set_tutorial_status("started"); - narrow.activate( + narrow.show( [ { operator: "is", diff --git a/web/src/ui_init.js b/web/src/ui_init.js index 3affd3c28c..aeb3d0be83 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -774,7 +774,7 @@ export function initialize_everything(state_data) { const sub = sub_store.get(stream_id); sidebar_ui.hide_all(); popovers.hide_all(); - narrow.activate( + narrow.show( [ { operator: "stream", @@ -832,7 +832,7 @@ export function initialize_everything(state_data) { compose_textarea.initialize(); upload.initialize(); search.initialize({ - on_narrow_search: narrow.activate, + on_narrow_search: narrow.show, }); desktop_notifications.initialize(); audible_notifications.initialize(); @@ -859,7 +859,7 @@ export function initialize_everything(state_data) { activity.initialize(); activity_ui.initialize({ narrow_by_email(email) { - narrow.activate( + narrow.show( [ { operator: "dm", @@ -886,7 +886,7 @@ export function initialize_everything(state_data) { topic_list.initialize({ on_topic_click(stream_id, topic) { const sub = sub_store.get(stream_id); - narrow.activate( + narrow.show( [ {operator: "channel", operand: sub.name}, {operator: "topic", operand: topic}, diff --git a/web/src/user_card_popover.js b/web/src/user_card_popover.js index 7483cc1f82..7ce27685c5 100644 --- a/web/src/user_card_popover.js +++ b/web/src/user_card_popover.js @@ -688,7 +688,7 @@ 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.activate( + narrow.show( [ { operator: "dm", @@ -708,7 +708,7 @@ 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.activate( + narrow.show( [ { operator: "sender", diff --git a/web/tests/hashchange.test.js b/web/tests/hashchange.test.js index 5764bf220e..def4b83bf7 100644 --- a/web/tests/hashchange.test.js +++ b/web/tests/hashchange.test.js @@ -181,9 +181,9 @@ function test_helper({override, override_rewire, change_tab}) { stub(ui_report, "error"); if (change_tab) { - override_rewire(narrow, "activate", (terms) => { + override_rewire(narrow, "show", (terms) => { narrow_terms = terms; - events.push("narrow.activate"); + events.push("narrow.show"); }); override(info_overlay, "show", (name) => { @@ -237,7 +237,7 @@ run_test("hash_interactions", ({override, override_rewire}) => { helper.assert_events([ [overlays, "close_for_hash_change"], [message_viewport, "stop_auto_scrolling"], - "narrow.activate", + "narrow.show", ]); helper.clear_events(); @@ -245,7 +245,7 @@ run_test("hash_interactions", ({override, override_rewire}) => { helper.assert_events([ [overlays, "close_for_hash_change"], [message_viewport, "stop_auto_scrolling"], - "narrow.activate", + "narrow.show", ]); // Test old "#recent_topics" hash redirects to "#recent". @@ -268,7 +268,7 @@ run_test("hash_interactions", ({override, override_rewire}) => { helper.assert_events([ [overlays, "close_for_hash_change"], [message_viewport, "stop_auto_scrolling"], - "narrow.activate", + "narrow.show", ]); let terms = helper.get_narrow_terms(); assert.equal(terms[0].operand, "Denmark"); @@ -280,7 +280,7 @@ run_test("hash_interactions", ({override, override_rewire}) => { helper.assert_events([ [overlays, "close_for_hash_change"], [message_viewport, "stop_auto_scrolling"], - "narrow.activate", + "narrow.show", ]); terms = helper.get_narrow_terms(); assert.equal(terms.length, 0); diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js index c3bc98bb7a..2d535abca5 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, "activate"); + assert_mapping("P", narrow, "show"); assert_mapping("g", gear_menu, "toggle"); }); diff --git a/web/tests/narrow.test.js b/web/tests/narrow.test.js index 439d49648d..89da301107 100644 --- a/web/tests/narrow.test.js +++ b/web/tests/narrow.test.js @@ -661,7 +661,7 @@ run_test("show_invalid_narrow_message", ({mock_template}) => { }); run_test("narrow_to_compose_target errors", ({disallow_rewire}) => { - disallow_rewire(narrow, "activate"); + disallow_rewire(narrow, "show"); // No-op when not composing. compose_state.set_message_type(undefined); @@ -675,7 +675,7 @@ run_test("narrow_to_compose_target errors", ({disallow_rewire}) => { run_test("narrow_to_compose_target streams", ({override_rewire}) => { const args = {called: false}; - override_rewire(narrow, "activate", (terms, opts) => { + override_rewire(narrow, "show", (terms, opts) => { args.terms = terms; args.opts = opts; args.called = true; @@ -723,7 +723,7 @@ run_test("narrow_to_compose_target streams", ({override_rewire}) => { run_test("narrow_to_compose_target direct messages", ({override, override_rewire}) => { const args = {called: false}; - override_rewire(narrow, "activate", (terms, opts) => { + override_rewire(narrow, "show", (terms, opts) => { args.terms = terms; args.opts = opts; args.called = true; diff --git a/web/tests/narrow_activate.test.js b/web/tests/narrow_activate.test.js index d727a484ea..24adc9b35c 100644 --- a/web/tests/narrow_activate.test.js +++ b/web/tests/narrow_activate.test.js @@ -60,7 +60,7 @@ mock_esm("../src/unread_ui", { }); // -// We have strange hacks in narrow.activate to sleep 0 +// We have strange hacks in narrow.show to sleep 0 // seconds. set_global("setTimeout", (f, t) => { assert.equal(t, 0); @@ -211,7 +211,7 @@ run_test("basics", ({override}) => { opts.cont(); }; - narrow.activate(terms, { + narrow.show(terms, { then_select_id: selected_id, }); @@ -243,7 +243,7 @@ run_test("basics", ({override}) => { message_lists.current.selected_id = () => -1; message_lists.current.get_row = () => row; - narrow.activate([{operator: "is", operand: "private"}], { + narrow.show([{operator: "is", operand: "private"}], { then_select_id: selected_id, }); @@ -254,7 +254,7 @@ run_test("basics", ({override}) => { row.get_offset_to_window = () => ({top: 100, bottom: 150}); message_lists.current.get_row = () => row; - narrow.activate(terms, { + narrow.show(terms, { then_select_id: selected_id, }); @@ -266,7 +266,7 @@ run_test("basics", ({override}) => { row.get_offset_to_window = () => ({top: 150, bottom: 250}); message_lists.current.get_row = () => row; - narrow.activate(terms, { + narrow.show(terms, { then_select_id: selected_id, });