2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2022-03-25 20:41:10 +01:00
|
|
|
import tippy from "tippy.js";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2021-02-10 16:55:52 +01:00
|
|
|
import render_announce_stream_docs from "../templates/announce_stream_docs.hbs";
|
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";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
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";
|
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";
|
2021-07-09 15:51:31 +02:00
|
|
|
import * as stream_settings_ui from "./stream_settings_ui";
|
2021-02-28 00:58:55 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2022-03-25 20:41:10 +01:00
|
|
|
import {parse_html} from "./ui_util";
|
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
|
|
|
|
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(
|
2021-04-13 06:51:54 +02:00
|
|
|
$t({defaultMessage: "You cannot create a stream 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:
|
|
|
|
"You must be an organization administrator to create a stream without subscribing.",
|
|
|
|
}),
|
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(
|
|
|
|
$t({defaultMessage: "A stream with this name already exists"}),
|
|
|
|
);
|
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() {
|
2021-04-13 06:51:54 +02:00
|
|
|
$("#stream_name_error").text($t({defaultMessage: "A stream needs to have a name"}));
|
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.
|
|
|
|
let stream_announce_previous_value =
|
|
|
|
settings_data.user_can_create_public_streams() ||
|
|
|
|
settings_data.user_can_create_web_public_streams();
|
|
|
|
|
2017-04-22 22:22:25 +02:00
|
|
|
// Within the new stream modal...
|
|
|
|
function update_announce_stream_state() {
|
2017-05-16 18:34:36 +02:00
|
|
|
// If there is no notifications_stream, we simply hide the widget.
|
2020-04-15 18:29:26 +02:00
|
|
|
if (!stream_data.realm_has_notifications_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;
|
2020-07-15 01:29:15 +02:00
|
|
|
const privacy_type = $("input: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(
|
2021-04-13 05:18:25 +02:00
|
|
|
$t_html({defaultMessage: "The stream 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
|
|
|
|
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();
|
2020-06-15 17:00:00 +02:00
|
|
|
if (message_retention_selection === "retain_for_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);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const announce =
|
|
|
|
stream_data.realm_has_notifications_stream() &&
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#announce-new-stream input").prop("checked");
|
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
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
loading.make_indicator($("#stream_creating_indicator"), {
|
|
|
|
text: $t({defaultMessage: "Creating stream..."}),
|
|
|
|
});
|
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(
|
|
|
|
$t_html({defaultMessage: "Stream successfully created!"}),
|
|
|
|
$(".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) {
|
2020-02-08 06:45:49 +01:00
|
|
|
const msg = JSON.parse(xhr.responseText).msg;
|
2020-07-15 01:29:15 +02:00
|
|
|
if (msg.includes("access")) {
|
2020-02-08 06:45:49 +01:00
|
|
|
// If we can't access the stream, we can safely assume it's
|
|
|
|
// a duplicate stream that we are not invited to.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// "Error creating stream"?
|
|
|
|
stream_name_error.report_already_exists(stream_name);
|
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(
|
|
|
|
$t_html({defaultMessage: "Error creating stream"}),
|
|
|
|
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.
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.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();
|
2021-11-19 10:29:39 +01:00
|
|
|
stream_settings_ui.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);
|
2017-04-22 22:22:25 +02:00
|
|
|
// Make the options default to the same each time:
|
2021-11-25 12:13:46 +01:00
|
|
|
// "announce stream" on.
|
2020-06-15 17:00:00 +02:00
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").hide();
|
|
|
|
$("#stream_creation_form select[name=stream_message_retention_setting]").val("realm_default");
|
2017-05-16 18:34:36 +02:00
|
|
|
|
2021-11-23 18:59:19 +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 === "retain_for_period") {
|
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").show();
|
|
|
|
} else {
|
|
|
|
$("#stream_creation_form .stream-message-retention-days-input").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-22 23:40:09 +02:00
|
|
|
update_announce_stream_state();
|
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() {
|
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
|
|
|
|
2022-04-08 13:05:36 +02:00
|
|
|
$container.on("change", ".stream-privacy-values input", update_announce_stream_state);
|
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;
|
|
|
|
}
|
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 04:55:06 +01:00
|
|
|
if (!principals.includes(people.my_current_user_id()) && !page_params.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({
|
2020-07-20 22:18:43 +02:00
|
|
|
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,
|
|
|
|
on_click: () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-03-25 20:41:10 +01:00
|
|
|
tippy("#announce-stream-docs", {
|
|
|
|
content: () =>
|
|
|
|
parse_html(
|
|
|
|
render_announce_stream_docs({
|
|
|
|
notifications_stream: stream_data.get_notifications_stream(),
|
|
|
|
}),
|
|
|
|
),
|
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();
|
|
|
|
}
|
|
|
|
});
|
2021-02-10 16:55:52 +01:00
|
|
|
}
|