mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
stream-settings: Move functions to update stream privacy choices.
This is a preparatory refactor to avoid import cycles in future commits for fixing live update behavior when archiving channels.
This commit is contained in:
@@ -287,7 +287,7 @@ export function dispatch_normal_event(event) {
|
||||
}
|
||||
|
||||
if (event.property === "enable_spectator_access") {
|
||||
stream_settings_ui.update_stream_privacy_choices(
|
||||
stream_ui_updates.update_stream_privacy_choices(
|
||||
"can_create_web_public_channel_group",
|
||||
);
|
||||
}
|
||||
@@ -347,7 +347,7 @@ export function dispatch_normal_event(event) {
|
||||
key === "can_create_private_channel_group" ||
|
||||
key === "can_create_web_public_channel_group"
|
||||
) {
|
||||
stream_settings_ui.update_stream_privacy_choices(key);
|
||||
stream_ui_updates.update_stream_privacy_choices(key);
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -457,9 +457,7 @@ function clear_error_display(): void {
|
||||
export function show_new_stream_modal(): void {
|
||||
$("#stream-creation").removeClass("hide");
|
||||
$(".right .settings").hide();
|
||||
stream_settings_components.hide_or_disable_stream_privacy_options_if_required(
|
||||
$("#stream-creation"),
|
||||
);
|
||||
stream_ui_updates.hide_or_disable_stream_privacy_options_if_required($("#stream-creation"));
|
||||
|
||||
stream_create_subscribers.build_widgets();
|
||||
|
||||
|
||||
@@ -12,11 +12,9 @@ import {$t, $t_html} from "./i18n.ts";
|
||||
import * as loading from "./loading.ts";
|
||||
import * as overlays from "./overlays.ts";
|
||||
import * as peer_data from "./peer_data.ts";
|
||||
import * as settings_config from "./settings_config.ts";
|
||||
import * as settings_data from "./settings_data.ts";
|
||||
import {current_user} from "./state_data.ts";
|
||||
import * as stream_data from "./stream_data.ts";
|
||||
import * as stream_ui_updates from "./stream_ui_updates.ts";
|
||||
import type {StreamSubscription} from "./sub_store.ts";
|
||||
import * as ui_report from "./ui_report.ts";
|
||||
|
||||
@@ -268,18 +266,3 @@ export function sub_or_unsub(
|
||||
ajaxSubscribe(sub.name, sub.color, $stream_row);
|
||||
}
|
||||
}
|
||||
|
||||
export function update_public_stream_privacy_option_state($container: JQuery): void {
|
||||
const $public_stream_elem = $container.find(
|
||||
`input[value='${CSS.escape(settings_config.stream_privacy_policy_values.public.code)}']`,
|
||||
);
|
||||
$public_stream_elem.prop("disabled", !settings_data.user_can_create_public_streams());
|
||||
}
|
||||
|
||||
export function hide_or_disable_stream_privacy_options_if_required($container: JQuery): void {
|
||||
stream_ui_updates.update_web_public_stream_privacy_option_state($container);
|
||||
|
||||
update_public_stream_privacy_option_state($container);
|
||||
|
||||
stream_ui_updates.update_private_stream_privacy_option_state($container);
|
||||
}
|
||||
|
||||
@@ -1120,32 +1120,6 @@ export function open_create_stream(): void {
|
||||
browser_history.update("#channels/new");
|
||||
}
|
||||
|
||||
export function update_stream_privacy_choices(policy: string): void {
|
||||
if (!overlays.streams_open()) {
|
||||
return;
|
||||
}
|
||||
const stream_edit_panel_opened = $("#stream_permission_settings").is(":visible");
|
||||
const stream_creation_form_opened = $("#stream-creation").is(":visible");
|
||||
|
||||
if (!stream_edit_panel_opened && !stream_creation_form_opened) {
|
||||
return;
|
||||
}
|
||||
let $container = $("#stream-creation");
|
||||
if (stream_edit_panel_opened) {
|
||||
$container = $("#stream_permission_settings");
|
||||
}
|
||||
|
||||
if (policy === "can_create_private_channel_group") {
|
||||
stream_ui_updates.update_private_stream_privacy_option_state($container);
|
||||
}
|
||||
if (policy === "can_create_public_channel_group") {
|
||||
stream_settings_components.update_public_stream_privacy_option_state($container);
|
||||
}
|
||||
if (policy === "can_create_web_public_channel_group") {
|
||||
stream_ui_updates.update_web_public_stream_privacy_option_state($container);
|
||||
}
|
||||
}
|
||||
|
||||
export function initialize(): void {
|
||||
$("#channels_overlay_container").on("click", ".create_stream_button", (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -9,6 +9,7 @@ import render_stream_settings_tip from "../templates/stream_settings/stream_sett
|
||||
|
||||
import * as hash_parser from "./hash_parser.ts";
|
||||
import {$t} from "./i18n.ts";
|
||||
import * as overlays from "./overlays.ts";
|
||||
import * as settings_components from "./settings_components.ts";
|
||||
import * as settings_config from "./settings_config.ts";
|
||||
import * as settings_data from "./settings_data.ts";
|
||||
@@ -517,3 +518,44 @@ export function enable_or_disable_add_subscribers_elements(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function update_public_stream_privacy_option_state($container: JQuery): void {
|
||||
const $public_stream_elem = $container.find(
|
||||
`input[value='${CSS.escape(settings_config.stream_privacy_policy_values.public.code)}']`,
|
||||
);
|
||||
$public_stream_elem.prop("disabled", !settings_data.user_can_create_public_streams());
|
||||
}
|
||||
|
||||
export function hide_or_disable_stream_privacy_options_if_required($container: JQuery): void {
|
||||
update_web_public_stream_privacy_option_state($container);
|
||||
|
||||
update_public_stream_privacy_option_state($container);
|
||||
|
||||
update_private_stream_privacy_option_state($container);
|
||||
}
|
||||
|
||||
export function update_stream_privacy_choices(policy: string): void {
|
||||
if (!overlays.streams_open()) {
|
||||
return;
|
||||
}
|
||||
const stream_edit_panel_opened = $("#stream_permission_settings").is(":visible");
|
||||
const stream_creation_form_opened = $("#stream-creation").is(":visible");
|
||||
|
||||
if (!stream_edit_panel_opened && !stream_creation_form_opened) {
|
||||
return;
|
||||
}
|
||||
let $container = $("#stream-creation");
|
||||
if (stream_edit_panel_opened) {
|
||||
$container = $("#stream_permission_settings");
|
||||
}
|
||||
|
||||
if (policy === "can_create_private_channel_group") {
|
||||
update_private_stream_privacy_option_state($container);
|
||||
}
|
||||
if (policy === "can_create_public_channel_group") {
|
||||
update_public_stream_privacy_option_state($container);
|
||||
}
|
||||
if (policy === "can_create_web_public_channel_group") {
|
||||
update_web_public_stream_privacy_option_state($container);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ run_test("realm settings", ({override}) => {
|
||||
assert_same(realm.realm_default_code_block_language, "javascript");
|
||||
|
||||
let update_called = false;
|
||||
stream_settings_ui.update_stream_privacy_choices = (property) => {
|
||||
stream_ui_updates.update_stream_privacy_choices = (property) => {
|
||||
assert_same(property, "can_create_web_public_channel_group");
|
||||
update_called = true;
|
||||
};
|
||||
@@ -577,7 +577,7 @@ run_test("realm settings", ({override}) => {
|
||||
assert_same(update_called, true);
|
||||
|
||||
let update_stream_privacy_choices_called = false;
|
||||
stream_settings_ui.update_stream_privacy_choices = (property) => {
|
||||
stream_ui_updates.update_stream_privacy_choices = (property) => {
|
||||
assert_same(property, "can_create_public_channel_group");
|
||||
update_stream_privacy_choices_called = true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user