From f4ad102d3974352aa2d592f3cb31eb50178dcdf2 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 6 Feb 2024 13:21:20 -0800 Subject: [PATCH] narrow_state: Add pm_ids_set helper. This provides a more easy to work with model of which users, if any, are involved in the current DM conversation, if any. --- web/src/narrow_state.ts | 6 ++++++ web/tests/narrow_state.test.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.ts index 372d295c82..2145bcdba2 100644 --- a/web/src/narrow_state.ts +++ b/web/src/narrow_state.ts @@ -186,6 +186,12 @@ export function pm_ids_string(): string | undefined { return user_ids_string; } +export function pm_ids_set(): Set { + const ids_string = pm_ids_string(); + const pm_ids_list = ids_string ? people.user_ids_string_to_ids_array(ids_string) : []; + return new Set(pm_ids_list); +} + export function pm_emails_string(): string | undefined { if (current_filter === undefined) { return undefined; diff --git a/web/tests/narrow_state.test.js b/web/tests/narrow_state.test.js index 6e24feb813..d217df6215 100644 --- a/web/tests/narrow_state.test.js +++ b/web/tests/narrow_state.test.js @@ -304,18 +304,22 @@ test("pm_ids_string", () => { // direct messages) with real users. narrow_state.set_current_filter(undefined); assert.equal(narrow_state.pm_ids_string(), undefined); + assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set()); set_filter([ ["stream", "Foo"], ["topic", "Bar"], ]); assert.equal(narrow_state.pm_ids_string(), undefined); + assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set()); set_filter([["dm", ""]]); assert.equal(narrow_state.pm_ids_string(), undefined); + assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set()); set_filter([["dm", "bogus@foo.com"]]); assert.equal(narrow_state.pm_ids_string(), undefined); + assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set()); const alice = { email: "alice@foo.com", @@ -334,4 +338,5 @@ test("pm_ids_string", () => { set_filter([["dm", "bob@foo.com,alice@foo.com"]]); assert.equal(narrow_state.pm_ids_string(), "444,555"); + assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set([444, 555])); });