Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_data: Allow undefined stream_id in get_color.
evykassirer97c46a73754f
diff --git a/web/src/stream_bar.ts b/web/src/stream_bar.tsindex f714ceb9893..b9b7499ca1d 100644--- a/web/src/stream_bar.ts+++ b/web/src/stream_bar.ts@@ -1,11 +1,10 @@import * as stream_data from "./stream_data";-import {DEFAULT_COLOR} from "./stream_data";// In an attempt to decrease mixing, set stream bar// color look like the stream being used.// (In particular, if there's a color associated with it,// have that color be reflected here too.)export function decorate(stream_id: number | undefined, $element: JQuery): void {- const color = stream_id === undefined ? DEFAULT_COLOR : stream_data.get_color(stream_id);+ const color = stream_data.get_color(stream_id);$element.css("background-color", color);}diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex 579618c31ef..548d230410b 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -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;diff --git a/web/tests/stream_data.test.js b/web/tests/stream_data.test.jsindex f34966ccd00..abe4445f563 100644--- a/web/tests/stream_data.test.js+++ b/web/tests/stream_data.test.js@@ -140,6 +140,7 @@ test("basics", () => {assert.equal(stream_data.get_color(social.stream_id), "red");assert.equal(stream_data.get_color(undefined), "#c2c2c2");+ assert.equal(stream_data.get_color(1234567), "#c2c2c2");assert.equal(stream_data.get_name("denMARK"), "Denmark");assert.equal(stream_data.get_name("unknown Stream"), "unknown Stream");