mirror of https://github.com/zulip/zulip.git
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.
This commit is contained in:
parent
772ed724c0
commit
f4ad102d39
|
@ -186,6 +186,12 @@ export function pm_ids_string(): string | undefined {
|
|||
return user_ids_string;
|
||||
}
|
||||
|
||||
export function pm_ids_set(): Set<number> {
|
||||
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;
|
||||
|
|
|
@ -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]));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue