diff --git a/web/src/stream_color.js b/web/src/stream_color.js index c8af0e1f75..32f3b4e2bd 100644 --- a/web/src/stream_color.js +++ b/web/src/stream_color.js @@ -6,7 +6,7 @@ import $ from "jquery"; import {$t} from "./i18n"; import * as settings_data from "./settings_data"; import * as stream_data from "./stream_data"; -import * as stream_settings_ui from "./stream_settings_ui"; +import * as stream_settings_api from "./stream_settings_api"; extend([lchPlugin, mixPlugin]); @@ -85,7 +85,7 @@ function picker_do_change_color(color) { $(".colorpicker").spectrum(sidebar_popover_colorpicker_options_full); const stream_id = Number.parseInt($(this).attr("stream_id"), 10); const hex_color = color.toHexString(); - stream_settings_ui.set_color(stream_id, hex_color); + stream_settings_api.set_color(stream_id, hex_color); } subscriptions_table_colorpicker_options.change = picker_do_change_color; diff --git a/web/src/stream_events.js b/web/src/stream_events.js index 539abda629..28ac9c5d59 100644 --- a/web/src/stream_events.js +++ b/web/src/stream_events.js @@ -16,6 +16,7 @@ import * as stream_color_events from "./stream_color_events"; import * as stream_data from "./stream_data"; import * as stream_list from "./stream_list"; import * as stream_muting from "./stream_muting"; +import * as stream_settings_api from "./stream_settings_api"; import * as stream_settings_ui from "./stream_settings_ui"; import * as sub_store from "./sub_store"; import * as unread_ui from "./unread_ui"; @@ -130,7 +131,7 @@ export function mark_subscribed(sub, subscribers, color) { // needed. blueslip.warn("Frontend needed to pick a color in mark_subscribed"); color = color_data.pick_color(); - stream_settings_ui.set_color(sub.stream_id, color); + stream_settings_api.set_color(sub.stream_id, color); } stream_data.subscribe_myself(sub); if (subscribers) { diff --git a/web/src/stream_settings_api.js b/web/src/stream_settings_api.js index e5b6198c6a..21535e62ec 100644 --- a/web/src/stream_settings_api.js +++ b/web/src/stream_settings_api.js @@ -1,5 +1,6 @@ import * as channel from "./channel"; import * as settings_ui from "./settings_ui"; +import * as sub_store from "./sub_store"; export function bulk_set_stream_property(sub_data, $status_element) { const url = "/json/users/me/subscriptions/properties"; @@ -20,3 +21,8 @@ export function set_stream_property(sub, property, value, $status_element) { const sub_data = {stream_id: sub.stream_id, property, value}; bulk_set_stream_property([sub_data], $status_element); } + +export function set_color(stream_id, color) { + const sub = sub_store.get(stream_id); + set_stream_property(sub, "color", color); +} diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.js index efb1d0ce22..82d64daf9e 100644 --- a/web/src/stream_settings_ui.js +++ b/web/src/stream_settings_ui.js @@ -254,11 +254,6 @@ export function update_is_default_stream() { } } -export function set_color(stream_id, color) { - const sub = sub_store.get(stream_id); - stream_settings_api.set_stream_property(sub, "color", color); -} - export function update_subscribers_ui(sub) { update_left_panel_row(sub); stream_edit_subscribers.update_subscribers_list(sub); diff --git a/web/tests/stream_events.test.js b/web/tests/stream_events.test.js index ea7cbedc11..18b5bcfb4a 100644 --- a/web/tests/stream_events.test.js +++ b/web/tests/stream_events.test.js @@ -15,6 +15,7 @@ const compose_fade = mock_esm("../src/compose_fade"); const stream_color_events = mock_esm("../src/stream_color_events"); const stream_list = mock_esm("../src/stream_list"); const stream_muting = mock_esm("../src/stream_muting"); +const stream_settings_api = mock_esm("../src/stream_settings_api"); const stream_settings_ui = mock_esm("../src/stream_settings_ui", { update_settings_for_subscribed: noop, update_empty_left_panel_message: noop, @@ -344,7 +345,7 @@ test("marked_subscribed (color)", ({override}) => { // narrow state is undefined { const stub = make_stub(); - override(stream_settings_ui, "set_color", stub.f); + override(stream_settings_api, "set_color", stub.f); blueslip.expect("warn", "Frontend needed to pick a color in mark_subscribed"); stream_events.mark_subscribed(sub, [], undefined); assert.equal(stub.num_calls, 1);