From adeee8080897f2e7fb94bb6d9bf560a55b700799 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Thu, 6 Nov 2025 18:38:25 +0530 Subject: [PATCH] stream-settings: Fix live updating of stream privacy options. There was a bug where the private stream options were live updated when a user gained access to create private streams even if the stream was set as a default stream which cannot be changed to private. This was because update_private_stream_privacy_option_state used "false" as default for "is_default_stream" parameter. This commit updates the code to compute is_default_stream value in update_private_stream_privacy_option_state itself to avoid any such bugs and this also helps in refactoring in further commits. --- web/src/stream_ui_updates.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.ts index defcc5370e..0681b4975b 100644 --- a/web/src/stream_ui_updates.ts +++ b/web/src/stream_ui_updates.ts @@ -111,10 +111,7 @@ export function update_web_public_stream_privacy_option_state($container: JQuery } } -export function update_private_stream_privacy_option_state( - $container: JQuery, - is_default_stream = false, -): void { +export function update_private_stream_privacy_option_state($container: JQuery): void { // Disable both "Private, shared history" and "Private, protected history" options. const $private_stream_elem = $container.find( `input[value='${CSS.escape(settings_config.stream_privacy_policy_values.private.code)}']`, @@ -125,6 +122,11 @@ export function update_private_stream_privacy_option_state( )}']`, ); + // If the default stream option is checked, the private stream options are disabled. + const is_default_stream = util.the( + $container.find(".default-stream input"), + ).checked; + const disable_private_stream_options = is_default_stream || !settings_data.user_can_create_private_streams(); @@ -313,9 +315,7 @@ export function update_default_stream_and_stream_privacy_state($container: JQuer is_invite_only, ); - // If the default stream option is checked, the private stream options are disabled. - const is_default_stream = util.the($default_stream.find("input")).checked; - update_private_stream_privacy_option_state($container, is_default_stream); + update_private_stream_privacy_option_state($container); } export function update_can_subscribe_group_label($container: JQuery): void {