stream_data: Allow undefined stream_id in get_color.

Sometimes get_color is called with undefined
stream ids. This change makes more clear
what was already happening, and allows
for smoother conversion of other files
to typescript, including an upcoming
conversion of the drafts module, which
can call `get_color` with a draft with
undefined stream_id.

This keeps the color logic contained in
the `get_color` function, which seems
cleaner than the alternative of exporting
DEFAULT_COLOR to be used wherever sream_id
might be undefined.
This commit is contained in:
evykassirer
2024-02-14 22:20:57 -08:00
committed by Tim Abbott
parent 8784fd9944
commit 97c46a7375
3 changed files with 7 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ export type InviteStreamData = {
default_stream: boolean;
};
export const DEFAULT_COLOR = "#c2c2c2";
const DEFAULT_COLOR = "#c2c2c2";
// Expose get_subscriber_count for our automated puppeteer tests.
export const get_subscriber_count = peer_data.get_subscriber_count;
@@ -457,7 +457,10 @@ export function canonicalized_name(stream_name: string): string {
return stream_name.toString().toLowerCase();
}
export function get_color(stream_id: number): string {
export function get_color(stream_id: number | undefined): string {
if (stream_id === undefined) {
return DEFAULT_COLOR;
}
const sub = get_sub_by_id(stream_id);
if (sub === undefined) {
return DEFAULT_COLOR;