diff --git a/web/src/compose_fade_helper.ts b/web/src/compose_fade_helper.ts index 9b42738d65..fed984e74f 100644 --- a/web/src/compose_fade_helper.ts +++ b/web/src/compose_fade_helper.ts @@ -20,7 +20,7 @@ export function set_focused_recipient(recipient?: Recipient): void { focused_recipient = recipient; } -export function would_receive_message(user_id: number): boolean | undefined { +export function would_receive_message(user_id: number): boolean { assert(focused_recipient !== undefined); if (focused_recipient.type === "stream") { const sub = sub_store.get(focused_recipient.stream_id); diff --git a/web/src/stream_data.ts b/web/src/stream_data.ts index 5a03301871..0b758f8e2c 100644 --- a/web/src/stream_data.ts +++ b/web/src/stream_data.ts @@ -697,19 +697,19 @@ export function get_name(stream_name: string): string { return sub.name; } -export function is_user_subscribed(stream_id: number, user_id: number): boolean | undefined { +export function is_user_subscribed(stream_id: number, user_id: number): boolean { const sub = sub_store.get(stream_id); if (sub === undefined || !can_view_subscribers(sub)) { // If we don't know about the stream, or we ourselves cannot access subscriber list, - // so we return undefined (treated as falsy if not explicitly handled). + // so we return false. blueslip.warn( "We got a is_user_subscribed call for a non-existent or inaccessible stream.", ); - return undefined; + return false; } if (user_id === undefined) { blueslip.warn("Undefined user_id passed to function is_user_subscribed"); - return undefined; + return false; } return peer_data.is_user_subscribed(stream_id, user_id); diff --git a/web/tests/peer_data.test.js b/web/tests/peer_data.test.js index 169a9fa6bc..c0248175e8 100644 --- a/web/tests/peer_data.test.js +++ b/web/tests/peer_data.test.js @@ -152,7 +152,7 @@ test("subscribers", () => { // verify that checking subscription with undefined user id blueslip.expect("warn", "Undefined user_id passed to function is_user_subscribed"); - assert.equal(stream_data.is_user_subscribed(stream_id, undefined), undefined); + assert.ok(!stream_data.is_user_subscribed(stream_id, undefined)); blueslip.reset(); // Verify noop for bad stream when removing subscriber @@ -193,9 +193,9 @@ test("subscribers", () => { 2, ); sub.invite_only = true; - assert.equal(stream_data.is_user_subscribed(stream_id, brutus.user_id), undefined); + assert.ok(!stream_data.is_user_subscribed(stream_id, brutus.user_id)); peer_data.remove_subscriber(stream_id, brutus.user_id); - assert.equal(stream_data.is_user_subscribed(stream_id, brutus.user_id), undefined); + assert.ok(!stream_data.is_user_subscribed(stream_id, brutus.user_id)); blueslip.reset(); // Verify that we don't crash for a bad stream.