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