mirror of https://github.com/zulip/zulip.git
stream_data: Avoid undefined return from is_user_subscribed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
5604ebedf0
commit
a36ef0b593
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue