2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-06-21 09:47:45 +02:00
|
|
|
import render_subscription_invites_warning_modal from "../templates/confirm_dialog/confirm_subscription_invites_warning.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 00:39:51 +01:00
|
|
|
import * as channel from "./channel";
|
2021-05-07 19:11:16 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2022-09-28 08:27:24 +02:00
|
|
|
import * as keydown_util from "./keydown_util";
|
2021-02-28 00:36:14 +01:00
|
|
|
import * as loading from "./loading";
|
2024-04-04 13:58:27 +02:00
|
|
|
import * as onboarding_steps from "./onboarding_steps";
|
2021-02-10 16:55:52 +01:00
|
|
|
import * as people from "./people";
|
2022-04-09 09:12:03 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2024-02-13 02:08:24 +01:00
|
|
|
import {current_user, realm} from "./state_data";
|
2022-02-08 18:56:40 +01:00
|
|
|
import * as stream_create_subscribers from "./stream_create_subscribers";
|
2021-02-28 00:53:59 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
2023-10-10 19:40:26 +02:00
|
|
|
import * as stream_settings_components from "./stream_settings_components";
|
2023-05-08 08:30:26 +02:00
|
|
|
import * as stream_ui_updates from "./stream_ui_updates";
|
2021-02-28 00:58:55 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2020-08-20 21:24:06 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let created_stream;
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function reset_created_stream() {
|
2017-04-22 22:22:25 +02:00
|
|
|
created_stream = undefined;
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function set_name(stream) {
|
2017-04-22 22:22:25 +02:00
|
|
|
created_stream = stream;
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function get_name() {
|
2017-04-22 22:22:25 +02:00
|
|
|
return created_stream;
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2024-04-04 13:58:27 +02:00
|
|
|
export function set_first_stream_created_modal_shown() {
|
|
|
|
onboarding_steps.post_onboarding_step_as_read("first_stream_created_banner");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function should_show_first_stream_created_modal() {
|
|
|
|
return onboarding_steps.ONE_TIME_NOTICES_TO_DISPLAY.has("first_stream_created_banner");
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:37:12 +02:00
|
|
|
class StreamSubscriptionError {
|
|
|
|
report_no_subs_to_stream() {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#stream_subscription_error").text(
|
2024-04-18 16:26:11 +02:00
|
|
|
$t({defaultMessage: "You cannot create a channel with no subscribers."}),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2018-01-21 09:34:50 +01:00
|
|
|
$("#stream_subscription_error").show();
|
2020-07-23 02:37:12 +02:00
|
|
|
}
|
2018-01-21 09:34:50 +01:00
|
|
|
|
2022-11-15 00:02:36 +01:00
|
|
|
cant_create_stream_without_subscribing() {
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#stream_subscription_error").text(
|
2021-04-13 06:51:54 +02:00
|
|
|
$t({
|
|
|
|
defaultMessage:
|
2024-04-18 16:26:11 +02:00
|
|
|
"You must be an organization administrator to create a channel without subscribing.",
|
2021-04-13 06:51:54 +02:00
|
|
|
}),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2018-02-03 09:04:45 +01:00
|
|
|
$("#stream_subscription_error").show();
|
2020-07-23 02:37:12 +02:00
|
|
|
}
|
2018-02-03 09:04:45 +01:00
|
|
|
|
2020-07-23 02:37:12 +02:00
|
|
|
clear_errors() {
|
2018-01-21 09:34:50 +01:00
|
|
|
$("#stream_subscription_error").hide();
|
2020-07-23 02:37:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const stream_subscription_error = new StreamSubscriptionError();
|
2018-01-21 09:34:50 +01:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
class StreamNameError {
|
|
|
|
report_already_exists() {
|
2021-04-13 06:51:54 +02:00
|
|
|
$("#stream_name_error").text(
|
2024-04-18 16:26:11 +02:00
|
|
|
$t({defaultMessage: "A channel with this name already exists."}),
|
2021-04-13 06:51:54 +02:00
|
|
|
);
|
2017-04-28 22:04:32 +02:00
|
|
|
$("#stream_name_error").show();
|
2020-07-23 02:39:41 +02:00
|
|
|
}
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
clear_errors() {
|
2017-04-28 22:04:32 +02:00
|
|
|
$("#stream_name_error").hide();
|
2020-07-23 02:39:41 +02:00
|
|
|
}
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
report_empty_stream() {
|
2024-04-18 16:26:11 +02:00
|
|
|
$("#stream_name_error").text($t({defaultMessage: "Choose a name for the new channel."}));
|
2017-04-28 22:04:32 +02:00
|
|
|
$("#stream_name_error").show();
|
2020-07-23 02:39:41 +02:00
|
|
|
}
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
select() {
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#create_stream_name").trigger("focus").trigger("select");
|
2020-07-23 02:39:41 +02:00
|
|
|
}
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
pre_validate(stream_name) {
|
2017-04-28 22:04:32 +02:00
|
|
|
// Don't worry about empty strings...we just want to call this
|
|
|
|
// to warn users early before they start doing too much work
|
|
|
|
// after they make the effort to type in a stream name. (The
|
|
|
|
// use case here is that I go to create a stream, only to find
|
|
|
|
// out it already exists, and I was just too lazy to look at
|
|
|
|
// the public streams that I'm not subscribed to yet. Once I
|
|
|
|
// realize the stream already exists, I may want to cancel.)
|
|
|
|
if (stream_name && stream_data.get_sub(stream_name)) {
|
2020-07-23 02:39:41 +02:00
|
|
|
this.report_already_exists();
|
2017-04-28 22:04:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
this.clear_errors();
|
|
|
|
}
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2020-07-23 02:39:41 +02:00
|
|
|
validate_for_submit(stream_name) {
|
2017-04-28 22:04:32 +02:00
|
|
|
if (!stream_name) {
|
2020-07-23 02:39:41 +02:00
|
|
|
this.report_empty_stream();
|
|
|
|
this.select();
|
2017-04-28 22:04:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_data.get_sub(stream_name)) {
|
2020-07-23 02:39:41 +02:00
|
|
|
this.report_already_exists();
|
|
|
|
this.select();
|
2017-04-28 22:04:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got this far, then we think we have a new unique stream
|
|
|
|
// name, so we'll submit to the server. (It's still plausible,
|
|
|
|
// however, that there's some invite-only stream that we don't
|
|
|
|
// know about locally that will cause a name collision.)
|
|
|
|
return true;
|
2020-07-23 02:39:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const stream_name_error = new StreamNameError();
|
2017-04-28 22:04:32 +02:00
|
|
|
|
2022-04-09 09:12:03 +02:00
|
|
|
// Stores the previous state of the stream creation checkbox.
|
2023-12-31 01:09:34 +01:00
|
|
|
let stream_announce_previous_value;
|
2022-04-09 09:12:03 +02:00
|
|
|
|
2017-04-22 22:22:25 +02:00
|
|
|
// Within the new stream modal...
|
|
|
|
function update_announce_stream_state() {
|
2024-02-07 12:13:02 +01:00
|
|
|
// If there is no new_stream_announcements_stream, we simply hide the widget.
|
|
|
|
if (stream_data.get_new_stream_announcements_stream() === "") {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#announce-new-stream").hide();
|
2017-05-16 18:34:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-29 11:02:24 +01:00
|
|
|
// If the stream is invite only, disable the "Announce stream" option.
|
|
|
|
// Otherwise enable it.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $announce_stream_checkbox = $("#announce-new-stream input");
|
|
|
|
const $announce_stream_label = $("#announce-new-stream");
|
2019-11-02 00:06:25 +01:00
|
|
|
let disable_it = false;
|
2023-05-02 06:48:01 +02:00
|
|
|
const privacy_type = $("#stream_creation_form input[type=radio][name=privacy]:checked").val();
|
2020-07-15 00:34:28 +02:00
|
|
|
const is_invite_only =
|
|
|
|
privacy_type === "invite-only" || privacy_type === "invite-only-public-history";
|
2022-01-25 11:36:19 +01:00
|
|
|
$announce_stream_label.removeClass("control-label-disabled");
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2022-04-09 09:12:03 +02:00
|
|
|
// Here, we arrange to save the state of the announce checkbox
|
|
|
|
// when switching to creating a private stream; we will restore it
|
|
|
|
// when switching back to a public stream. This input-disabled
|
|
|
|
// check prevents overwriting stream_announce_previous_value with
|
|
|
|
// the false when switching between private stream types.
|
|
|
|
if (!$announce_stream_checkbox.prop("disabled")) {
|
|
|
|
stream_announce_previous_value = $announce_stream_checkbox.prop("checked");
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:22:25 +02:00
|
|
|
if (is_invite_only) {
|
|
|
|
disable_it = true;
|
2022-01-25 11:36:19 +01:00
|
|
|
$announce_stream_checkbox.prop("checked", false);
|
|
|
|
$announce_stream_label.addClass("control-label-disabled");
|
2022-04-09 09:12:03 +02:00
|
|
|
} else {
|
|
|
|
// If the stream was already public, this will be a noop.
|
|
|
|
$announce_stream_checkbox.prop("checked", stream_announce_previous_value);
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$announce_stream_checkbox.prop("disabled", disable_it);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#announce-new-stream").show();
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 04:07:36 +02:00
|
|
|
function create_stream() {
|
2020-02-08 06:45:49 +01:00
|
|
|
const data = {};
|
2020-07-22 03:39:41 +02:00
|
|
|
const stream_name = $("#create_stream_name").val().trim();
|
|
|
|
const description = $("#create_stream_description").val().trim();
|
2020-02-08 06:45:49 +01:00
|
|
|
created_stream = stream_name;
|
|
|
|
|
|
|
|
// Even though we already check to make sure that while typing the user cannot enter
|
2020-08-11 02:09:14 +02:00
|
|
|
// newline characters (by pressing the Enter key) it would still be possible to copy
|
2020-02-08 06:45:49 +01:00
|
|
|
// and paste over a description with newline characters in it. Prevent that.
|
2020-07-15 01:29:15 +02:00
|
|
|
if (description.includes("\n")) {
|
2021-01-27 08:16:28 +01:00
|
|
|
ui_report.client_error(
|
2024-04-18 16:26:11 +02:00
|
|
|
$t_html({defaultMessage: "The channel description cannot contain newline characters."}),
|
2020-07-15 00:34:28 +02:00
|
|
|
$(".stream_create_info"),
|
|
|
|
);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-02-08 06:45:49 +01:00
|
|
|
}
|
2020-07-20 22:18:43 +02:00
|
|
|
data.subscriptions = JSON.stringify([{name: stream_name, description}]);
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let invite_only;
|
|
|
|
let history_public_to_subscribers;
|
2020-11-10 15:51:21 +01:00
|
|
|
let is_web_public;
|
2020-07-15 01:29:15 +02:00
|
|
|
const privacy_setting = $("#stream_creation_form input[name=privacy]:checked").val();
|
2020-02-04 21:50:55 +01:00
|
|
|
|
2021-06-16 04:29:08 +02:00
|
|
|
switch (privacy_setting) {
|
|
|
|
case "invite-only": {
|
|
|
|
invite_only = true;
|
|
|
|
history_public_to_subscribers = false;
|
2020-11-10 15:51:21 +01:00
|
|
|
is_web_public = false;
|
2021-06-16 04:29:08 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "invite-only-public-history": {
|
|
|
|
invite_only = true;
|
|
|
|
history_public_to_subscribers = true;
|
2020-11-10 15:51:21 +01:00
|
|
|
is_web_public = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "web-public": {
|
|
|
|
invite_only = false;
|
|
|
|
history_public_to_subscribers = true;
|
|
|
|
is_web_public = true;
|
2021-06-16 04:29:08 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
invite_only = false;
|
|
|
|
history_public_to_subscribers = true;
|
2020-11-10 15:51:21 +01:00
|
|
|
is_web_public = false;
|
2021-06-16 04:29:08 +02:00
|
|
|
}
|
2018-05-03 18:52:39 +02:00
|
|
|
}
|
2020-11-10 15:51:21 +01:00
|
|
|
|
|
|
|
data.is_web_public = JSON.stringify(is_web_public);
|
2020-02-08 06:45:49 +01:00
|
|
|
data.invite_only = JSON.stringify(invite_only);
|
|
|
|
data.history_public_to_subscribers = JSON.stringify(history_public_to_subscribers);
|
2018-05-03 18:52:39 +02:00
|
|
|
|
2023-08-08 19:28:04 +02:00
|
|
|
const default_stream = $("#stream_creation_form .is_default_stream").prop("checked");
|
|
|
|
data.is_default_stream = JSON.stringify(default_stream);
|
|
|
|
|
2020-10-07 09:17:30 +02:00
|
|
|
const stream_post_policy = Number.parseInt(
|
2022-03-07 07:43:41 +01:00
|
|
|
$("#stream_creation_form select[name=stream-post-policy]").val(),
|
2020-07-15 00:34:28 +02:00
|
|
|
10,
|
|
|
|
);
|
2020-02-08 06:45:49 +01:00
|
|
|
|
|
|
|
data.stream_post_policy = JSON.stringify(stream_post_policy);
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
let message_retention_selection = $(
|
|
|
|
"#stream_creation_form select[name=stream_message_retention_setting]",
|
|
|
|
).val();
|
2022-10-26 16:58:31 +02:00
|
|
|
if (message_retention_selection === "custom_period") {
|
2020-10-07 09:17:30 +02:00
|
|
|
message_retention_selection = Number.parseInt(
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#stream_creation_form input[name=stream-message-retention-days]").val(),
|
|
|
|
10,
|
|
|
|
);
|
2020-06-15 17:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data.message_retention_days = JSON.stringify(message_retention_selection);
|
|
|
|
|
2023-03-22 16:50:49 +01:00
|
|
|
let announce =
|
2024-02-07 12:13:02 +01:00
|
|
|
stream_data.get_new_stream_announcements_stream() !== "" &&
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#announce-new-stream input").prop("checked");
|
2023-03-22 16:50:49 +01:00
|
|
|
|
|
|
|
if (
|
2024-02-07 12:13:02 +01:00
|
|
|
stream_data.get_new_stream_announcements_stream() === "" &&
|
|
|
|
stream_data.realm_has_new_stream_announcements_stream() &&
|
2023-03-22 16:50:49 +01:00
|
|
|
!invite_only
|
|
|
|
) {
|
|
|
|
announce = true;
|
|
|
|
}
|
|
|
|
|
2020-02-08 06:45:49 +01:00
|
|
|
data.announce = JSON.stringify(announce);
|
2017-07-08 04:07:36 +02:00
|
|
|
|
2020-02-08 06:45:49 +01:00
|
|
|
// TODO: We can eliminate the user_ids -> principals conversion
|
|
|
|
// once we upgrade the backend to accept user_ids.
|
2022-02-08 18:56:40 +01:00
|
|
|
const user_ids = stream_create_subscribers.get_principals();
|
2020-06-03 21:38:43 +02:00
|
|
|
data.principals = JSON.stringify(user_ids);
|
2019-02-20 18:36:46 +01:00
|
|
|
|
2022-12-30 10:55:10 +01:00
|
|
|
const can_remove_subscribers_group_id = Number.parseInt(
|
2023-10-10 19:40:26 +02:00
|
|
|
stream_settings_components.new_stream_can_remove_subscribers_group_widget.value(),
|
2022-12-30 10:55:10 +01:00
|
|
|
10,
|
|
|
|
);
|
2023-07-12 12:57:57 +02:00
|
|
|
data.can_remove_subscribers_group = can_remove_subscribers_group_id;
|
2022-12-30 10:55:10 +01:00
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
loading.make_indicator($("#stream_creating_indicator"), {
|
2024-04-18 16:26:11 +02:00
|
|
|
text: $t({defaultMessage: "Creating channel..."}),
|
2021-04-13 06:51:54 +02:00
|
|
|
});
|
2017-11-04 19:19:12 +01:00
|
|
|
|
2020-02-08 06:45:49 +01:00
|
|
|
// Subscribe yourself and possible other people to a new stream.
|
|
|
|
return channel.post({
|
|
|
|
url: "/json/users/me/subscriptions",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
|
|
|
success() {
|
2020-02-08 06:45:49 +01:00
|
|
|
$("#create_stream_name").val("");
|
|
|
|
$("#create_stream_description").val("");
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.success(
|
2024-04-18 16:26:11 +02:00
|
|
|
$t_html({defaultMessage: "Channel successfully created!"}),
|
2021-04-13 05:18:25 +02:00
|
|
|
$(".stream_create_info"),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#stream_creating_indicator"));
|
2020-02-08 06:45:49 +01:00
|
|
|
// The rest of the work is done via the subscribe event we will get
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2023-07-18 20:19:22 +02:00
|
|
|
if (xhr.responseJSON?.msg?.includes("access")) {
|
2023-02-02 17:49:02 +01:00
|
|
|
// If we can't access the stream, we can safely
|
|
|
|
// assume it's a duplicate stream that we are not invited to.
|
2020-02-08 06:45:49 +01:00
|
|
|
//
|
|
|
|
// BUG: This check should be using error codes, not
|
|
|
|
// parsing the error string, so it works correctly
|
|
|
|
// with i18n. And likely we should be reporting the
|
|
|
|
// error text directly rather than turning it into
|
2024-04-18 16:26:11 +02:00
|
|
|
// "Error creating channel"?
|
2024-01-18 13:46:03 +01:00
|
|
|
stream_name_error.report_already_exists();
|
2022-06-01 02:15:29 +02:00
|
|
|
stream_name_error.select();
|
2020-02-08 06:45:49 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error(
|
2024-04-18 16:26:11 +02:00
|
|
|
$t_html({defaultMessage: "Error creating channel"}),
|
2021-04-13 05:18:25 +02:00
|
|
|
xhr,
|
|
|
|
$(".stream_create_info"),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#stream_creating_indicator"));
|
2020-02-08 06:45:49 +01:00
|
|
|
},
|
|
|
|
});
|
2017-07-08 04:07:36 +02:00
|
|
|
}
|
2017-06-02 15:06:33 +02:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function new_stream_clicked(stream_name) {
|
2017-04-22 22:22:25 +02:00
|
|
|
// this changes the tab switcher (settings/preview) which isn't necessary
|
|
|
|
// to a add new stream title.
|
2023-10-10 19:40:26 +02:00
|
|
|
stream_settings_components.show_subs_pane.create_stream();
|
2017-04-22 22:22:25 +02:00
|
|
|
$(".stream-row.active").removeClass("active");
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (stream_name !== "") {
|
|
|
|
$("#create_stream_name").val(stream_name);
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
2021-02-10 16:55:52 +01:00
|
|
|
show_new_stream_modal();
|
2020-11-01 04:05:19 +01:00
|
|
|
$("#create_stream_name").trigger("focus");
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2018-03-10 03:14:48 +01:00
|
|
|
function clear_error_display() {
|
|
|
|
stream_name_error.clear_errors();
|
|
|
|
$(".stream_create_info").hide();
|
|
|
|
stream_subscription_error.clear_errors();
|
|
|
|
}
|
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function show_new_stream_modal() {
|
2017-04-22 22:22:25 +02:00
|
|
|
$("#stream-creation").removeClass("hide");
|
|
|
|
$(".right .settings").hide();
|
2023-10-10 19:40:26 +02:00
|
|
|
stream_settings_components.hide_or_disable_stream_privacy_options_if_required(
|
|
|
|
$("#stream-creation"),
|
|
|
|
);
|
2017-11-26 12:57:03 +01:00
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
stream_create_subscribers.build_widgets();
|
2021-04-22 23:40:09 +02:00
|
|
|
|
2021-12-07 08:03:02 +01:00
|
|
|
// Select the first visible and enabled choice for stream privacy.
|
2022-03-16 22:29:41 +01:00
|
|
|
$("#make-invite-only input:visible:not([disabled])").first().prop("checked", true);
|
2023-01-06 08:01:03 +01:00
|
|
|
// Make the options default to the same each time
|
2023-01-06 08:03:49 +01:00
|
|
|
|
|
|
|
// The message retention setting is visible to owners only. The below block
|
|
|
|
// sets the default state of setting if it is visible.
|
2024-02-13 02:08:16 +01:00
|
|
|
if (current_user.is_owner) {
|
2023-01-06 08:03:49 +01:00
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").hide();
|
|
|
|
$("#stream_creation_form select[name=stream_message_retention_setting]").val(
|
|
|
|
"realm_default",
|
|
|
|
);
|
|
|
|
|
2023-01-06 08:31:14 +01:00
|
|
|
// The user is not allowed to set the setting to amy value other than
|
|
|
|
// "realm_default" for realms on limited plans, so we disable the setting.
|
|
|
|
$("#stream_creation_form select[name=stream_message_retention_setting]").prop(
|
|
|
|
"disabled",
|
2024-02-13 02:08:24 +01:00
|
|
|
!realm.zulip_plan_is_not_limited,
|
2023-01-06 08:31:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// This listener is only needed if the dropdown setting is enabled.
|
2024-02-13 02:08:24 +01:00
|
|
|
if (realm.zulip_plan_is_not_limited) {
|
2023-01-06 08:31:14 +01:00
|
|
|
// Add listener to .show stream-message-retention-days-input that we've hidden above
|
|
|
|
$("#stream_creation_form .stream_message_retention_setting").on("change", (e) => {
|
|
|
|
if (e.target.value === "custom_period") {
|
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").show();
|
|
|
|
} else {
|
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-01-06 08:03:49 +01:00
|
|
|
}
|
2023-05-08 08:30:26 +02:00
|
|
|
const $add_subscribers_container = $(
|
|
|
|
"#stream_creation_form .subscriber_list_settings",
|
|
|
|
).expectOne();
|
|
|
|
|
|
|
|
stream_ui_updates.enable_or_disable_add_subscribers_elements(
|
|
|
|
$add_subscribers_container,
|
|
|
|
settings_data.user_can_subscribe_other_users(),
|
|
|
|
true,
|
|
|
|
);
|
2021-11-23 18:59:19 +01:00
|
|
|
|
2023-08-08 19:28:04 +02:00
|
|
|
// set default state for "announce stream" and "default stream" option.
|
|
|
|
$("#stream_creation_form .default-stream input").prop("checked", false);
|
2021-04-22 23:40:09 +02:00
|
|
|
update_announce_stream_state();
|
2023-08-08 19:28:04 +02:00
|
|
|
stream_ui_updates.update_default_stream_and_stream_privacy_state($("#stream-creation"));
|
2018-03-10 03:14:48 +01:00
|
|
|
clear_error_display();
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
export function set_up_handlers() {
|
2023-12-31 01:09:34 +01:00
|
|
|
stream_announce_previous_value =
|
|
|
|
settings_data.user_can_create_public_streams() ||
|
|
|
|
settings_data.user_can_create_web_public_streams();
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $people_to_add_holder = $("#people_to_add").expectOne();
|
|
|
|
stream_create_subscribers.create_handlers($people_to_add_holder);
|
2021-07-15 18:38:44 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $("#stream-creation").expectOne();
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2023-08-08 19:28:04 +02:00
|
|
|
$container.on("change", ".stream-privacy-values input", () => {
|
|
|
|
update_announce_stream_state();
|
|
|
|
stream_ui_updates.update_default_stream_and_stream_privacy_state($container);
|
|
|
|
});
|
|
|
|
|
|
|
|
$container.on("change", ".default-stream input", () => {
|
|
|
|
stream_ui_updates.update_default_stream_and_stream_privacy_state($container);
|
|
|
|
});
|
2018-03-25 18:46:10 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$container.on("click", ".finalize_create_stream", (e) => {
|
2017-04-22 22:22:25 +02:00
|
|
|
e.preventDefault();
|
2018-03-10 03:14:48 +01:00
|
|
|
clear_error_display();
|
|
|
|
|
2020-07-22 03:39:41 +02:00
|
|
|
const stream_name = $("#create_stream_name").val().trim();
|
2019-11-02 00:06:25 +01:00
|
|
|
const name_ok = stream_name_error.validate_for_submit(stream_name);
|
2017-04-28 22:04:32 +02:00
|
|
|
|
|
|
|
if (!name_ok) {
|
|
|
|
return;
|
2017-04-22 22:22:25 +02:00
|
|
|
}
|
2017-06-02 15:06:33 +02:00
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
const principals = stream_create_subscribers.get_principals();
|
2018-01-21 09:34:50 +01:00
|
|
|
if (principals.length === 0) {
|
|
|
|
stream_subscription_error.report_no_subs_to_stream();
|
|
|
|
return;
|
|
|
|
}
|
2024-02-13 02:08:16 +01:00
|
|
|
if (!principals.includes(people.my_current_user_id()) && !current_user.is_admin) {
|
2022-11-15 00:02:36 +01:00
|
|
|
stream_subscription_error.cant_create_stream_without_subscribing();
|
2018-02-03 09:04:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-01-21 09:34:50 +01:00
|
|
|
|
2017-07-08 04:21:19 +02:00
|
|
|
if (principals.length >= 50) {
|
2021-05-07 19:11:16 +02:00
|
|
|
const html_body = render_subscription_invites_warning_modal({
|
2024-04-18 16:26:11 +02:00
|
|
|
channel_name: stream_name,
|
2019-07-09 21:24:00 +02:00
|
|
|
count: principals.length,
|
|
|
|
});
|
2021-05-07 19:11:16 +02:00
|
|
|
|
|
|
|
confirm_dialog.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Large number of subscribers"}),
|
|
|
|
html_body,
|
2022-11-17 23:33:43 +01:00
|
|
|
on_click() {
|
2021-05-07 19:11:16 +02:00
|
|
|
create_stream();
|
|
|
|
},
|
|
|
|
});
|
2017-06-02 15:06:33 +02:00
|
|
|
} else {
|
|
|
|
create_stream();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$container.on("input", "#create_stream_name", () => {
|
2020-07-22 03:39:41 +02:00
|
|
|
const stream_name = $("#create_stream_name").val().trim();
|
2017-04-22 22:22:25 +02:00
|
|
|
|
2017-04-28 22:04:32 +02:00
|
|
|
// This is an inexpensive check.
|
2017-07-08 04:31:11 +02:00
|
|
|
stream_name_error.pre_validate(stream_name);
|
2017-04-22 22:22:25 +02:00
|
|
|
});
|
|
|
|
|
2019-02-20 18:36:46 +01:00
|
|
|
// Do not allow the user to enter newline characters while typing out the
|
|
|
|
// stream's description during it's creation.
|
2022-01-25 11:36:19 +01:00
|
|
|
$container.on("keydown", "#create_stream_description", (e) => {
|
2022-09-28 08:27:24 +02:00
|
|
|
if (keydown_util.is_enter_event(e)) {
|
2019-02-20 18:36:46 +01:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2022-12-30 10:55:10 +01:00
|
|
|
|
2023-10-10 19:40:26 +02:00
|
|
|
stream_settings_components.new_stream_can_remove_subscribers_group_widget.setup();
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|