Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_ui_updates: Cut import of stream_settings_ui.
Anders Kaseorg521cb15a07f2
diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.jsindex 82d64daf9e4..ba16ef83f65 100644--- a/web/src/stream_settings_ui.js+++ b/web/src/stream_settings_ui.js@@ -74,16 +74,12 @@ export const show_subs_pane = {},};-export function row_for_stream_id(stream_id) {- return $(`.stream-row[data-stream-id='${CSS.escape(stream_id)}']`);-}-export function is_sub_already_present(sub) {- return row_for_stream_id(sub.stream_id).length > 0;+ return stream_ui_updates.row_for_stream_id(sub.stream_id).length > 0;}export function update_left_panel_row(sub) {- const $row = row_for_stream_id(sub.stream_id);+ const $row = stream_ui_updates.row_for_stream_id(sub.stream_id);if ($row.length === 0) {return;@@ -107,14 +103,6 @@ export function update_left_panel_row(sub) {$row.replaceWith($new_row);}-export function settings_button_for_sub(sub) {- // We don't do expectOne() here, because this button is only- // visible if the user has that stream selected in the streams UI.- return $(- `.stream_settings_header[data-stream-id='${CSS.escape(sub.stream_id)}'] .subscribe-button`,- );-}-function get_row_data($row) {const row_id = Number.parseInt($row.attr("data-stream-id"), 10);if (row_id) {@@ -155,14 +143,6 @@ export function toggle_pin_to_top_stream(sub) {stream_settings_api.set_stream_property(sub, "pin_to_top", !sub.pin_to_top);}-let subscribed_only = true;--export function is_subscribed_stream_tab_active() {- // Returns true if "Subscribed" tab in stream settings is open- // otherwise false.- return subscribed_only;-}-export function update_stream_name(sub, new_name) {// Rename the stream internally.stream_data.rename_sub(sub, new_name);@@ -175,7 +155,7 @@ export function update_stream_name(sub, new_name) {stream_edit.update_stream_name(sub, new_name);// Update the subscriptions page- const $sub_row = row_for_stream_id(stream_id);+ const $sub_row = stream_ui_updates.row_for_stream_id(stream_id);$sub_row.find(".stream-name").text(new_name);// Update the message feed.@@ -196,7 +176,7 @@ export function update_stream_description(sub, description, rendered_descriptionstream_data.clean_up_description(sub);// Update stream row- const $sub_row = row_for_stream_id(sub.stream_id);+ const $sub_row = stream_ui_updates.row_for_stream_id(sub.stream_id);$sub_row.find(".description").html(util.clean_user_content_links(sub.rendered_description));// Update stream settings@@ -297,7 +277,7 @@ export function add_sub_to_table(sub) {// good way to associate with this request because the stream// ID isn't known yet. These are appended to the top of the// list, so they are more visible.- row_for_stream_id(sub.stream_id).trigger("click");+ stream_ui_updates.row_for_stream_id(sub.stream_id).trigger("click");stream_create.reset_created_stream();}update_empty_left_panel_message();@@ -306,7 +286,7 @@ export function add_sub_to_table(sub) {export function remove_stream(stream_id) {// It is possible that row is empty when we deactivate a// stream, but we let jQuery silently handle that.- const $row = row_for_stream_id(stream_id);+ const $row = stream_ui_updates.row_for_stream_id(stream_id);$row.remove();update_empty_left_panel_message();if (hash_parser.is_editing_stream(stream_id)) {@@ -347,7 +327,7 @@ export function show_active_stream_in_left_panel() {const selected_row = hash_parser.get_current_hash_section();if (Number.parseFloat(selected_row)) {- const $sub_row = row_for_stream_id(selected_row);+ const $sub_row = stream_ui_updates.row_for_stream_id(selected_row);$sub_row.addClass("active");}}@@ -449,7 +429,7 @@ export function update_empty_left_panel_message() {// Check if we have any streams in panel to decide whether to// display a notice.let has_streams;- if (is_subscribed_stream_tab_active()) {+ if (stream_ui_updates.is_subscribed_stream_tab_active()) {// We don't remove stream row from UI on unsubscribe, To handle// this case here we are also checking DOM if there are streams// displayed in panel or not.@@ -463,7 +443,7 @@ export function update_empty_left_panel_message() {$(".no-streams-to-show").hide();return;}- if (is_subscribed_stream_tab_active()) {+ if (stream_ui_updates.is_subscribed_stream_tab_active()) {$(".all_streams_tab_empty_text").hide();$(".subscribed_streams_tab_empty_text").show();} else {@@ -538,7 +518,7 @@ export function get_left_panel_params() {const input = $search_box.expectOne().val().trim();const params = {input,- subscribed_only,+ subscribed_only: stream_ui_updates.subscribed_only,sort_order,};return params;@@ -563,9 +543,9 @@ export function switch_stream_tab(tab_name) {*/if (tab_name === "all-streams") {- subscribed_only = false;+ stream_ui_updates.set_subscribed_only(false);} else if (tab_name === "subscribed") {- subscribed_only = true;+ stream_ui_updates.set_subscribed_only(true);}redraw_left_panel();@@ -661,7 +641,7 @@ export function setup_page(callback) {// Reset our internal state to reflect that we're initially in// the "Subscribed" tab if we're reopening "Manage streams".- subscribed_only = true;+ stream_ui_updates.set_subscribed_only(true);toggler = components.toggle({child_wants_focus: true,values: [@@ -776,7 +756,7 @@ export function setup_page(callback) {}export function switch_to_stream_row(stream_id) {- const $stream_row = row_for_stream_id(stream_id);+ const $stream_row = stream_ui_updates.row_for_stream_id(stream_id);const $container = $(".streams-list");get_active_data().$row.removeClass("active");@@ -1099,58 +1079,6 @@ export function sub_or_unsub(sub, $stream_row) {}}-export function update_web_public_stream_privacy_option_state($container) {- const $web_public_stream_elem = $container.find(- `input[value='${CSS.escape(- settings_config.stream_privacy_policy_values.web_public.code,- )}']`,- );-- const for_stream_edit_panel = $container.attr("id") === "stream_permission_settings";- if (for_stream_edit_panel) {- const stream_id = Number.parseInt(- $container.closest(".subscription_settings.show").attr("data-stream-id"),- 10,- );- const sub = sub_store.get(stream_id);- if (!stream_data.can_change_permissions(sub)) {- // We do not want to enable the already disabled web-public option- // in stream-edit panel if user is not allowed to change stream- // privacy at all.- return;- }- }-- if (- !page_params.server_web_public_streams_enabled ||- !page_params.realm_enable_spectator_access- ) {- if (for_stream_edit_panel && $web_public_stream_elem.is(":checked")) {- // We do not hide web-public option in the "Change privacy" modal if- // stream is web-public already. The option is disabled in this case.- $web_public_stream_elem.prop("disabled", true);- return;- }- $web_public_stream_elem.closest(".settings-radio-input-parent").hide();- $container- .find(".stream-privacy-values .settings-radio-input-parent:visible")- .last()- .css("border-bottom", "none");- } else {- if (!$web_public_stream_elem.is(":visible")) {- $container- .find(".stream-privacy-values .settings-radio-input-parent:visible")- .last()- .css("border-bottom", "");- $web_public_stream_elem.closest(".settings-radio-input-parent").show();- }- $web_public_stream_elem.prop(- "disabled",- !settings_data.user_can_create_web_public_streams(),- );- }-}-export function update_public_stream_privacy_option_state($container) {const $public_stream_elem = $container.find(`input[value='${CSS.escape(settings_config.stream_privacy_policy_values.public.code)}']`,@@ -1158,37 +1086,12 @@ export function update_public_stream_privacy_option_state($container) {$public_stream_elem.prop("disabled", !settings_data.user_can_create_public_streams());}-export function update_private_stream_privacy_option_state($container, is_default_stream = false) {- // 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)}']`,- );- const $private_with_public_history_elem = $container.find(- `input[value='${CSS.escape(- settings_config.stream_privacy_policy_values.private_with_public_history.code,- )}']`,- );-- const disable_private_stream_options =- is_default_stream || !settings_data.user_can_create_private_streams();-- $private_stream_elem.prop("disabled", disable_private_stream_options);- $private_with_public_history_elem.prop("disabled", disable_private_stream_options);-- $private_stream_elem- .closest("div")- .toggleClass("default_stream_private_tooltip", is_default_stream);- $private_with_public_history_elem- .closest("div")- .toggleClass("default_stream_private_tooltip", is_default_stream);-}-export function hide_or_disable_stream_privacy_options_if_required($container) {- update_web_public_stream_privacy_option_state($container);+ stream_ui_updates.update_web_public_stream_privacy_option_state($container);update_public_stream_privacy_option_state($container);- update_private_stream_privacy_option_state($container);+ stream_ui_updates.update_private_stream_privacy_option_state($container);}export function update_stream_privacy_choices(policy) {@@ -1207,13 +1110,13 @@ export function update_stream_privacy_choices(policy) {}if (policy === "create_private_stream_policy") {- update_private_stream_privacy_option_state($container);+ stream_ui_updates.update_private_stream_privacy_option_state($container);}if (policy === "create_public_stream_policy") {update_public_stream_privacy_option_state($container);}if (policy === "create_web_public_stream_policy") {- update_web_public_stream_privacy_option_state($container);+ stream_ui_updates.update_web_public_stream_privacy_option_state($container);}}diff --git a/web/src/stream_ui_updates.js b/web/src/stream_ui_updates.jsindex 939385831c1..0ca00468baf 100644--- a/web/src/stream_ui_updates.js+++ b/web/src/stream_ui_updates.js@@ -8,12 +8,114 @@ import render_stream_settings_tip from "../templates/stream_settings/stream_settimport * as hash_parser from "./hash_parser";import {$t} from "./i18n";import {page_params} from "./page_params";+import * as settings_config from "./settings_config";import * as settings_data from "./settings_data";import * as settings_org from "./settings_org";import * as stream_data from "./stream_data";import * as stream_edit_toggler from "./stream_edit_toggler";import * as stream_settings_containers from "./stream_settings_containers";-import * as stream_settings_ui from "./stream_settings_ui";+import * as sub_store from "./sub_store";++export function row_for_stream_id(stream_id) {+ return $(`.stream-row[data-stream-id='${CSS.escape(stream_id)}']`);+}++function settings_button_for_sub(sub) {+ // We don't do expectOne() here, because this button is only+ // visible if the user has that stream selected in the streams UI.+ return $(+ `.stream_settings_header[data-stream-id='${CSS.escape(sub.stream_id)}'] .subscribe-button`,+ );+}++export let subscribed_only = true;++export function is_subscribed_stream_tab_active() {+ // Returns true if "Subscribed" tab in stream settings is open+ // otherwise false.+ return subscribed_only;+}++export function set_subscribed_only(value) {+ subscribed_only = value;+}++export function update_web_public_stream_privacy_option_state($container) {+ const $web_public_stream_elem = $container.find(+ `input[value='${CSS.escape(+ settings_config.stream_privacy_policy_values.web_public.code,+ )}']`,+ );++ const for_stream_edit_panel = $container.attr("id") === "stream_permission_settings";+ if (for_stream_edit_panel) {+ const stream_id = Number.parseInt(+ $container.closest(".subscription_settings.show").attr("data-stream-id"),+ 10,+ );+ const sub = sub_store.get(stream_id);+ if (!stream_data.can_change_permissions(sub)) {+ // We do not want to enable the already disabled web-public option+ // in stream-edit panel if user is not allowed to change stream+ // privacy at all.+ return;+ }+ }++ if (+ !page_params.server_web_public_streams_enabled ||+ !page_params.realm_enable_spectator_access+ ) {+ if (for_stream_edit_panel && $web_public_stream_elem.is(":checked")) {+ // We do not hide web-public option in the "Change privacy" modal if+ // stream is web-public already. The option is disabled in this case.+ $web_public_stream_elem.prop("disabled", true);+ return;+ }+ $web_public_stream_elem.closest(".settings-radio-input-parent").hide();+ $container+ .find(".stream-privacy-values .settings-radio-input-parent:visible")+ .last()+ .css("border-bottom", "none");+ } else {+ if (!$web_public_stream_elem.is(":visible")) {+ $container+ .find(".stream-privacy-values .settings-radio-input-parent:visible")+ .last()+ .css("border-bottom", "");+ $web_public_stream_elem.closest(".settings-radio-input-parent").show();+ }+ $web_public_stream_elem.prop(+ "disabled",+ !settings_data.user_can_create_web_public_streams(),+ );+ }+}++export function update_private_stream_privacy_option_state($container, is_default_stream = false) {+ // 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)}']`,+ );+ const $private_with_public_history_elem = $container.find(+ `input[value='${CSS.escape(+ settings_config.stream_privacy_policy_values.private_with_public_history.code,+ )}']`,+ );++ const disable_private_stream_options =+ is_default_stream || !settings_data.user_can_create_private_streams();++ $private_stream_elem.prop("disabled", disable_private_stream_options);+ $private_with_public_history_elem.prop("disabled", disable_private_stream_options);++ $private_stream_elem+ .closest("div")+ .toggleClass("default_stream_private_tooltip", is_default_stream);+ $private_with_public_history_elem+ .closest("div")+ .toggleClass("default_stream_private_tooltip", is_default_stream);+}export function initialize_disable_btn_hint_popover($btn_wrapper, hint_text) {tippy($btn_wrapper[0], {@@ -75,7 +177,7 @@ export function update_settings_button_for_sub(sub) {}// This is for the Subscribe/Unsubscribe button in the right panel.- const $settings_button = stream_settings_ui.settings_button_for_sub(sub);+ const $settings_button = settings_button_for_sub(sub);if (!$settings_button.length) {// `subscribe` button hasn't been rendered yet while we are processing the event.@@ -137,7 +239,7 @@ export function update_default_stream_and_stream_privacy_state($container) {// If the default stream option is checked, the private stream options are disabled.const is_default_stream = $default_stream.find("input").prop("checked");- stream_settings_ui.update_private_stream_privacy_option_state($container, is_default_stream);+ update_private_stream_privacy_option_state($container, is_default_stream);}export function enable_or_disable_permission_settings_in_edit_panel(sub) {@@ -167,9 +269,7 @@ export function enable_or_disable_permission_settings_in_edit_panel(sub) {.find(".message-retention-setting-custom-input").prop("disabled", disable_message_retention_setting);- stream_settings_ui.update_web_public_stream_privacy_option_state(- $("#stream_permission_settings"),- );+ update_web_public_stream_privacy_option_state($("#stream_permission_settings"));}export function update_announce_stream_option() {@@ -233,8 +333,8 @@ export function update_stream_row_in_settings_tab(sub) {// If user is subscribed to stream, it will show sub row under// "Subscribed" tab, otherwise if stream is not public hide// stream row under tab.- if (stream_settings_ui.is_subscribed_stream_tab_active()) {- const $sub_row = stream_settings_ui.row_for_stream_id(sub.stream_id);+ if (is_subscribed_stream_tab_active()) {+ const $sub_row = row_for_stream_id(sub.stream_id);if (sub.subscribed) {$sub_row.removeClass("notdisplayed");} else if (sub.invite_only || page_params.is_guest) {