From 449febf0366850ed30b4fa5533445ce98a71dd25 Mon Sep 17 00:00:00 2001 From: Ujjawal Modi Date: Wed, 22 Mar 2023 21:20:49 +0530 Subject: [PATCH] streams: Make stream settings and create stream UI more consistent. This commit make changes in create stream panel by moving announce stream option below stream description and adds a "Stream permissions" section heading just above "Who can access the stream?" and also rewords the text "Announce stream". Also now announce stream option is only shown if the user creating stream have access to the announcement stream name. When option is not shown, default behaviour is to announce public and web-public streams. Fixes #23327. --- docs/testing/manual-testing.md | 2 +- help/create-a-stream.md | 7 +++---- web/src/server_events_dispatch.js | 3 ++- web/src/stream_create.js | 15 ++++++++++++--- web/src/stream_settings_ui.js | 4 ++++ web/src/stream_ui_updates.js | 19 +++++++++++++++++++ .../announce_stream_checkbox.hbs | 13 +++++++++++++ .../stream_settings/stream_creation_form.hbs | 6 ++++++ .../stream_settings/stream_types.hbs | 11 ----------- 9 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 web/templates/stream_settings/announce_stream_checkbox.hbs diff --git a/docs/testing/manual-testing.md b/docs/testing/manual-testing.md index ef45ba289f..4e7f2b403a 100644 --- a/docs/testing/manual-testing.md +++ b/docs/testing/manual-testing.md @@ -437,7 +437,7 @@ Create new public stream "public1" and add Hamlet: - Type "public1" in the text box and then click "Create new stream." - Select "People must be invited" and then verify you can't - select "Announce stream". + select "Announce new stream in #[announcement stream]". - Select "Anyone can join" again to make it be public. - Check the checkbox for Hamlet. - Hit the "Create" button. diff --git a/help/create-a-stream.md b/help/create-a-stream.md index f851e3911d..e5c194da0d 100644 --- a/help/create-a-stream.md +++ b/help/create-a-stream.md @@ -36,11 +36,10 @@ There are several parameters you can set while creating a stream. All but * **Stream description**: Helps users decide whether to subscribe when they are browsing streams. -* **Who can access the stream?**: See [Stream permissions](/help/stream-permissions). +* **Announce new stream in the [stream configured by your organization](/help/configure-notification-bot#new-stream-announcements)**: + Posts a message in the "new streams" topic advertising the new stream. -* **Announce stream**: Posts a message to `#general` advertising the new - stream. Organization administrators can change the stream used for [stream - creation announcements](/help/configure-notification-bot#new-stream-announcements). +* **Who can access the stream?**: See [Stream permissions](/help/stream-permissions). * **Who can post to the stream?**: See [Stream permissions](/help/stream-permissions). diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index d85487e761..b0cca13a2d 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -64,6 +64,7 @@ import * as stream_events from "./stream_events"; import * as stream_list from "./stream_list"; import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_topic_history from "./stream_topic_history"; +import * as stream_ui_updates from "./stream_ui_updates"; import * as sub_store from "./sub_store"; import * as submessage from "./submessage"; import * as typing_events from "./typing_events"; @@ -219,7 +220,7 @@ export function dispatch_normal_event(event) { move_messages_between_streams_policy: noop, name: notifications.redraw_title, name_changes_disabled: settings_account.update_name_change_display, - notifications_stream_id: noop, + notifications_stream_id: stream_ui_updates.update_announce_stream_option, org_type: noop, private_message_policy: noop, send_welcome_emails: noop, diff --git a/web/src/stream_create.js b/web/src/stream_create.js index cdb51e0862..a9bad6152d 100644 --- a/web/src/stream_create.js +++ b/web/src/stream_create.js @@ -123,7 +123,7 @@ let stream_announce_previous_value = // Within the new stream modal... function update_announce_stream_state() { // If there is no notifications_stream, we simply hide the widget. - if (!stream_data.realm_has_notifications_stream()) { + if (stream_data.get_notifications_stream() === "") { $("#announce-new-stream").hide(); return; } @@ -235,9 +235,18 @@ function create_stream() { data.message_retention_days = JSON.stringify(message_retention_selection); - const announce = - stream_data.realm_has_notifications_stream() && + let announce = + stream_data.get_notifications_stream() !== "" && $("#announce-new-stream input").prop("checked"); + + if ( + stream_data.get_notifications_stream() === "" && + stream_data.realm_has_notifications_stream() && + !invite_only + ) { + announce = true; + } + data.announce = JSON.stringify(announce); // TODO: We can eliminate the user_ids -> principals conversion diff --git a/web/src/stream_settings_ui.js b/web/src/stream_settings_ui.js index 61f5aadf3f..63e9524850 100644 --- a/web/src/stream_settings_ui.js +++ b/web/src/stream_settings_ui.js @@ -677,7 +677,11 @@ export function setup_page(callback) { // TODO: Ideally we'd indicate in some way what stream types // the user can create, by showing other options as disabled. const stream_privacy_policy = stream_data.stream_privacy_policy_values.public.code; + const notifications_stream = stream_data.get_notifications_stream(); + const notifications_stream_sub = stream_data.get_sub_by_name(notifications_stream); + const template_data = { + notifications_stream_sub, ask_to_announce_stream: true, can_create_streams: settings_data.user_can_create_private_streams() || diff --git a/web/src/stream_ui_updates.js b/web/src/stream_ui_updates.js index e596f35f40..b4719eaab3 100644 --- a/web/src/stream_ui_updates.js +++ b/web/src/stream_ui_updates.js @@ -1,5 +1,6 @@ import $ from "jquery"; +import render_announce_stream_checkbox from "../templates/stream_settings/announce_stream_checkbox.hbs"; import render_stream_privacy_icon from "../templates/stream_settings/stream_privacy_icon.hbs"; import render_stream_settings_tip from "../templates/stream_settings/stream_settings_tip.hbs"; @@ -155,6 +156,24 @@ export function enable_or_disable_permission_settings_in_edit_panel(sub) { ); } +export function update_announce_stream_option() { + if (!hash_util.is_create_new_stream_narrow()) { + return; + } + if (stream_data.get_notifications_stream() === "") { + $("#announce-new-stream").hide(); + return; + } + $("#announce-new-stream").show(); + + const notifications_stream = stream_data.get_notifications_stream(); + const notifications_stream_sub = stream_data.get_sub_by_name(notifications_stream); + const rendered_announce_stream = render_announce_stream_checkbox({ + notifications_stream_sub, + }); + $("#announce-new-stream").expectOne().html(rendered_announce_stream); +} + export function update_stream_privacy_icon_in_settings(sub) { if (!hash_util.is_editing_stream(sub.stream_id)) { return; diff --git a/web/templates/stream_settings/announce_stream_checkbox.hbs b/web/templates/stream_settings/announce_stream_checkbox.hbs new file mode 100644 index 0000000000..9cd521969c --- /dev/null +++ b/web/templates/stream_settings/announce_stream_checkbox.hbs @@ -0,0 +1,13 @@ + diff --git a/web/templates/stream_settings/stream_creation_form.hbs b/web/templates/stream_settings/stream_creation_form.hbs index e5c7ec9c1d..571b4308e5 100644 --- a/web/templates/stream_settings/stream_creation_form.hbs +++ b/web/templates/stream_settings/stream_creation_form.hbs @@ -20,8 +20,14 @@ + {{#if ask_to_announce_stream}} +
+ {{>announce_stream_checkbox }} +
+ {{/if}}
+

{{t "Stream permissions" }}

{{> stream_types stream_post_policy=stream_post_policy_values.everyone.code is_stream_edit=false diff --git a/web/templates/stream_settings/stream_types.hbs b/web/templates/stream_settings/stream_types.hbs index 4628b9bfb4..1766d7b567 100644 --- a/web/templates/stream_settings/stream_types.hbs +++ b/web/templates/stream_settings/stream_types.hbs @@ -16,17 +16,6 @@
-{{#if ask_to_announce_stream}} -
- - -
-{{/if}} -