From e039bdd1e1f6ce073d74c8fe2d3452bf859d3805 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Wed, 25 May 2022 19:20:07 -0700 Subject: [PATCH] narrow: Replace pm_string() with _id and _email variants. This makes the format returned by these functions more clear. --- frontend_tests/node_tests/narrow_state.js | 12 +++++------ static/js/compose_closed_ui.js | 4 ++-- static/js/narrow.js | 2 +- static/js/narrow_state.js | 25 +++++++++++++---------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/frontend_tests/node_tests/narrow_state.js b/frontend_tests/node_tests/narrow_state.js index 7e6d5659cc..6d0fe0e74c 100644 --- a/frontend_tests/node_tests/narrow_state.js +++ b/frontend_tests/node_tests/narrow_state.js @@ -276,24 +276,24 @@ test("stream_sub", () => { assert.equal(narrow_state.stream(), undefined); }); -test("pm_string", () => { +test("pm_ids_string", () => { // This function will return undefined unless we're clearly // narrowed to a specific PM (including huddles) with real // users. narrow_state.set_current_filter(undefined); - assert.equal(narrow_state.pm_string(), undefined); + assert.equal(narrow_state.pm_ids_string(), undefined); set_filter([ ["stream", "Foo"], ["topic", "Bar"], ]); - assert.equal(narrow_state.pm_string(), undefined); + assert.equal(narrow_state.pm_ids_string(), undefined); set_filter([["pm-with", ""]]); - assert.equal(narrow_state.pm_string(), undefined); + assert.equal(narrow_state.pm_ids_string(), undefined); set_filter([["pm-with", "bogus@foo.com"]]); - assert.equal(narrow_state.pm_string(), undefined); + assert.equal(narrow_state.pm_ids_string(), undefined); const alice = { email: "alice@foo.com", @@ -311,5 +311,5 @@ test("pm_string", () => { people.add_active_user(bob); set_filter([["pm-with", "bob@foo.com,alice@foo.com"]]); - assert.equal(narrow_state.pm_string(), "444,555"); + assert.equal(narrow_state.pm_ids_string(), "444,555"); }); diff --git a/static/js/compose_closed_ui.js b/static/js/compose_closed_ui.js index 8a3584cabd..7ed0e4b704 100644 --- a/static/js/compose_closed_ui.js +++ b/static/js/compose_closed_ui.js @@ -19,13 +19,13 @@ export function get_recipient_label(message) { stream: narrow_state.stream(), topic: narrow_state.topic(), }; - } else if (narrow_state.pm_string()) { + } else if (narrow_state.pm_ids_string()) { // TODO: This is a total hack. Ideally, we'd rework // this to not duplicate the actual compose_actions.js // logic for what happens when you click the button, // and not call into random modules with hacky fake // "message" objects. - const user_ids = people.user_ids_string_to_ids_array(narrow_state.pm_string()); + const user_ids = people.user_ids_string_to_ids_array(narrow_state.pm_ids_string()); const user_ids_dicts = user_ids.map((user_id) => ({id: user_id})); message = { display_reply_to: message_store.get_pm_full_names({ diff --git a/static/js/narrow.js b/static/js/narrow.js index 6885958c0d..9c371cb1fe 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -860,7 +860,7 @@ export function narrow_to_next_topic() { } export function narrow_to_next_pm_string() { - const curr_pm = narrow_state.pm_string(); + const curr_pm = narrow_state.pm_ids_string(); const next_pm = topic_generator.get_next_unread_pm_string(curr_pm); diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js index d673999197..3063157b87 100644 --- a/static/js/narrow_state.js +++ b/static/js/narrow_state.js @@ -140,10 +140,21 @@ export function topic() { return undefined; } -export function pm_string() { +export function pm_ids_string() { // If you are narrowed to a PM conversation // with users 4, 5, and 99, this will return "4,5,99" + const emails_string = pm_emails_string(); + if (!emails_string) { + return undefined; + } + + const user_ids_string = people.reply_to_to_user_ids_string(emails_string); + + return user_ids_string; +} + +export function pm_emails_string() { if (current_filter === undefined) { return undefined; } @@ -153,15 +164,7 @@ export function pm_string() { return undefined; } - const emails_string = operands[0]; - - if (!emails_string) { - return undefined; - } - - const user_ids_string = people.reply_to_to_user_ids_string(emails_string); - - return user_ids_string; + return operands[0]; } export function get_first_unread_info() { @@ -240,7 +243,7 @@ export function _possible_unread_message_ids() { } if (current_filter.can_bucket_by("pm-with")) { - current_filter_pm_string = pm_string(); + current_filter_pm_string = pm_ids_string(); if (current_filter_pm_string === undefined) { return []; }