Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Add UI for per-stream push notification default.
Aadyot1ae588277afd8
diff --git a/starlight_help/astro.config.mjs b/starlight_help/astro.config.mjsindex 1f7871092b9..955c92b87df 100644--- a/starlight_help/astro.config.mjs+++ b/starlight_help/astro.config.mjs@@ -601,6 +601,7 @@ export default defineConfig({"change-the-channel-description","pin-information","change-the-privacy-of-a-channel",+ "enable-mobile-notifications-by-default",{label: "Delete or archive a channel",link: "/archive-a-channel",diff --git a/starlight_help/src/content/docs/channel-notifications.mdx b/starlight_help/src/content/docs/channel-notifications.mdxindex 3b28552ff73..544831a1913 100644--- a/starlight_help/src/content/docs/channel-notifications.mdx+++ b/starlight_help/src/content/docs/channel-notifications.mdx@@ -15,6 +15,10 @@ import ResetIcon from "~icons/zulip-icon/reset";You can configure desktop, mobile, and email notifications on a channel bychannel basis.+Organization administrators can [enable mobile+notifications](/help/enable-mobile-notifications-by-default), per channel,+as a default for new subscribers.+## Configure notifications for a single channelThese settings will override any default channel notification settings. In [muteddiff --git a/starlight_help/src/content/docs/create-channels.mdx b/starlight_help/src/content/docs/create-channels.mdxindex 8afa1cc55bb..92edd054551 100644--- a/starlight_help/src/content/docs/create-channels.mdx+++ b/starlight_help/src/content/docs/create-channels.mdx@@ -30,6 +30,9 @@ import CreateChannelsIntro from "../include/_CreateChannelsIntro.mdx";members** for new members to introduce themselves and be welcomed,and **#help** so that there's a clear place users stopping by withjust a single question can post.+* For channels where it's important that everyone stays on top of new messages,+ organization administrators can [enable mobile notifications](/help/enable-mobile-notifications-by-default)+ as a default for new subscribers.## Related articlesdiff --git a/starlight_help/src/content/docs/enable-mobile-notifications-by-default.mdx b/starlight_help/src/content/docs/enable-mobile-notifications-by-default.mdxnew file mode 100644index 00000000000..92fc9bdced6--- /dev/null+++ b/starlight_help/src/content/docs/enable-mobile-notifications-by-default.mdx@@ -0,0 +1,47 @@+---+title: Enable mobile notifications by default+---++import FlattenedSteps from "../../components/FlattenedSteps.astro";+import NavigationSteps from "../../components/NavigationSteps.astro";+import AdminOnly from "../include/_AdminOnly.mdx";+import ChannelSettingsNavbarTip from "../include/_ChannelSettingsNavbarTip.mdx";+import SaveChanges from "../include/_SaveChanges.mdx";+import SelectChannelViewGeneral from "../include/_SelectChannelViewGeneral.mdx";++<AdminOnly />++Users can configure [mobile push notifications](/help/mobile-notifications)+on a [channel by channel](/help/channel-notifications) basis. For channels+where it's important that everyone stays on top of new messages, such as a+channel for urgent announcements, organization administrators can enable+mobile notifications by default for new subscribers.++Enabling mobile notifications by default does not change the notification+settings of anyone who is already subscribed to the channel, and users can+always [adjust their notification+settings](/help/channel-notifications#configure-notifications-for-a-single-channel)+for any channel.++## Enable mobile notifications by default for a channel++<FlattenedSteps>+ <NavigationSteps target="relative/channel/all" />++ 1. Select a channel.++ <SelectChannelViewGeneral />++ 1. Toggle **Mobile push notifications enabled by default**.++ <SaveChanges />+</FlattenedSteps>++<ChannelSettingsNavbarTip />++## Related articles++* [Channel notifications](/help/channel-notifications)+* [Mobile notifications](/help/mobile-notifications)+* [Set default channels for new users](/help/set-default-channels-for-new-users)+* [Configure who can administer a channel](/help/configure-who-can-administer-a-channel)diff --git a/starlight_help/src/content/docs/mobile-notifications.mdx b/starlight_help/src/content/docs/mobile-notifications.mdxindex ea50efccdd3..be605ca14e1 100644--- a/starlight_help/src/content/docs/mobile-notifications.mdx+++ b/starlight_help/src/content/docs/mobile-notifications.mdx@@ -15,6 +15,10 @@ alerts](/help/dm-mention-alert-notifications), as well as [channelmessages](/help/channel-notifications) and [followedtopics](/help/follow-a-topic#configure-notifications-for-followed-topics).+Organization administrators can [enable mobile+notifications](/help/enable-mobile-notifications-by-default), per channel,+as a default for new subscribers.+<Tabs><TabItem label="Desktop/Web"><FlattenedSteps>diff --git a/starlight_help/src/content/docs/set-default-channels-for-new-users.mdx b/starlight_help/src/content/docs/set-default-channels-for-new-users.mdxindex 8fbfbf70c68..ef9bc81931c 100644--- a/starlight_help/src/content/docs/set-default-channels-for-new-users.mdx+++ b/starlight_help/src/content/docs/set-default-channels-for-new-users.mdx@@ -49,4 +49,5 @@ to invite new users can subscribe them to any combination of default channels.* [User roles](/help/user-roles)* [User groups](/help/user-groups)* [Channel permissions](/help/channel-permissions)+* [Enable channel notifications for new subscribers](/help/enable-mobile-notifications-by-default)* [Create channels for a new organization](/help/create-channels)diff --git a/starlight_help/src/content/include/_ChannelAdminPermissions.mdx b/starlight_help/src/content/include/_ChannelAdminPermissions.mdxindex 1bb1e304e6f..013977d2424 100644--- a/starlight_help/src/content/include/_ChannelAdminPermissions.mdx+++ b/starlight_help/src/content/include/_ChannelAdminPermissions.mdx@@ -25,3 +25,6 @@ However, the following actions require specific permissions.users](/help/configure-who-can-invite-to-channels)* Modifying settings that affect content access (e.g., making a channelpublic, or changing who can add subscribers).+* Modifying settings that affect notifications (e.g., [enabling mobile+ notifications for new subscribers](/help/enable-mobile-notifications-by-default)):+ Restricted to organization administrators.diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.jsindex 65cf4194fa8..eb15c3a5352 100644--- a/web/src/server_events_dispatch.js+++ b/web/src/server_events_dispatch.js@@ -850,7 +850,12 @@ export function dispatch_normal_event(event) {for (const rec of event.subscriptions) {const sub = sub_store.get(rec.stream_id);if (sub) {- stream_events.mark_subscribed(sub, rec.subscribers, rec.color);+ stream_events.mark_subscribed(+ sub,+ rec.subscribers,+ rec.color,+ rec.push_notifications,+ );} else {blueslip.error("Subscribing to unknown stream", {stream_id: rec.stream_id,diff --git a/web/src/stream_create.ts b/web/src/stream_create.tsindex 29b1f3e9375..3887e9ffb6d 100644--- a/web/src/stream_create.ts+++ b/web/src/stream_create.ts@@ -388,6 +388,14 @@ function create_stream(): void {...group_setting_values,};+ // Only present for admins, so guard against it being absent.+ const $default_push_notifications = $<HTMLInputElement>("#id_new_default_push_notifications");+ if ($default_push_notifications.length > 0) {+ data["default_push_notifications"] = JSON.stringify(+ $default_push_notifications.prop("checked"),+ );+ }+assert(folder_widget !== undefined);const folder_id = folder_widget.value();if (folder_id !== settings_config.no_folder_selected) {diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex dd35da8a83c..b93ad2843d0 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -498,6 +498,13 @@ export function update_topics_policy_setting(sub.topics_policy = topics_policy;}+export function update_default_push_notifications(+ sub: StreamSubscription,+ default_push_notifications: boolean,+): void {+ sub.default_push_notifications = default_push_notifications;+}+export function update_stream_permission_group_setting(setting_name: StreamPermissionGroupSetting,sub: StreamSubscription,diff --git a/web/src/stream_edit.ts b/web/src/stream_edit.tsindex a5189bcc15c..a9ca8ce724f 100644--- a/web/src/stream_edit.ts+++ b/web/src/stream_edit.ts@@ -462,6 +462,16 @@ export function set_up_channel_privacy_dropdown_widget(return channel_privacy_widget;}+function get_push_notifications_tooltip(): string | undefined {+ if (!realm.realm_push_notifications_enabled) {+ return $t({defaultMessage: "Mobile push notifications are not enabled on this server."});+ }+ if (!current_user.is_admin) {+ return $t({defaultMessage: "Only organization administrators can edit this setting."});+ }+ return undefined;+}+export function show_settings_for(node: HTMLElement): void {// Hide any tooltips or popovers before we rerender / change// currently displayed stream settings.@@ -493,6 +503,7 @@ export function show_settings_for(node: HTMLElement): void {is_business_type_org:realm.realm_org_type === settings_config.all_org_type_values.business.code,is_admin: current_user.is_admin,+ push_notifications_tooltip: get_push_notifications_tooltip(),org_level_message_retention_setting: get_display_text_for_realm_message_retention_setting(),group_setting_labels: settings_config.all_group_setting_labels.stream,has_billing_access: settings_data.user_has_billing_access(),@@ -1056,8 +1067,10 @@ export function initialize(): void {$subsection,sub,);- if ($subsection.attr("id") === "channel-subscription-permissions") {- assert(sub !== undefined);+ if (+ $subsection.attr("id") === "channel-subscription-permissions" &&+ sub !== undefined+ ) {stream_ui_updates.update_can_create_topic_group_on_history_public_to_subscribers_change(sub,);diff --git a/web/src/stream_events.ts b/web/src/stream_events.tsindex e6964b3abad..ad2144dbb53 100644--- a/web/src/stream_events.ts+++ b/web/src/stream_events.ts@@ -195,6 +195,10 @@ export function update_property<P extends keyof UpdatableStreamProperties>(message_retention_days(value) {stream_settings_ui.update_message_retention_setting(sub, value);},+ default_push_notifications(value) {+ sub.default_push_notifications = value;+ stream_settings_ui.update_default_push_notifications_setting(sub, value);+ },topics_policy(value) {stream_settings_ui.update_topics_policy_setting(sub, value);compose_recipient.update_topic_inputbox_on_topics_policy_change();@@ -269,11 +273,15 @@ export function mark_subscribed(sub: StreamSubscription,subscribers: number[],color: string | undefined,+ push_notifications: boolean | null,): void {if (sub.subscribed) {return;}+ sub.push_notifications = push_notifications;+ update_property(sub.stream_id, "push_notifications", sub.push_notifications);+// If the backend sent us a color, use thatif (color !== undefined && sub.color !== color) {sub.color = color;diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.tsindex b716cd95a5f..1cbce140028 100644--- a/web/src/stream_settings_ui.ts+++ b/web/src/stream_settings_ui.ts@@ -237,6 +237,14 @@ export function update_topics_policy_setting(stream_ui_updates.update_setting_element(sub, "topics_policy");}+export function update_default_push_notifications_setting(+ sub: StreamSubscription,+ new_value: boolean,+): void {+ stream_data.update_default_push_notifications(sub, new_value);+ stream_ui_updates.update_setting_element(sub, "default_push_notifications");+}+export function update_stream_permission_group_setting(setting_name: StreamPermissionGroupSetting,sub: StreamSubscription,@@ -1041,6 +1049,10 @@ function setup_page(callback: () => void): void {realm_has_archived_channels,has_billing_access: settings_data.user_has_billing_access(),is_admin: current_user.is_admin,+ disable_push_notifications: !realm.realm_push_notifications_enabled,+ push_notifications_tooltip: realm.realm_push_notifications_enabled+ ? undefined+ : $t({defaultMessage: "Mobile push notifications are not enabled on this server."}),empty_string_topic_display_name: util.get_final_topic_display_name(""),};diff --git a/web/src/stream_types.ts b/web/src/stream_types.tsindex 070eab15342..85131059e3e 100644--- a/web/src/stream_types.ts+++ b/web/src/stream_types.ts@@ -48,6 +48,7 @@ export const stream_schema = z.object({can_subscribe_group: group_setting_value_schema,creator_id: z.nullable(z.number()),date_created: z.number(),+ default_push_notifications: z.boolean(),description: z.string(),first_message_id: z.nullable(z.number()),folder_id: z.nullable(z.number()),diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.tsindex f8d86cb1a1c..73681bb65d3 100644--- a/web/src/stream_ui_updates.ts+++ b/web/src/stream_ui_updates.ts@@ -355,6 +355,17 @@ export function enable_or_disable_permission_settings_in_edit_panel(.find(".channel-folder-widget-container button").prop("disabled", !sub.can_change_stream_permissions_requiring_metadata_access);+ const $default_push_notifications_setting = $stream_settings+ .find("input[name='default_push_notifications']")+ .closest(".settings-checkbox-wrapper");+ const disable_push_notifications =+ !realm.realm_push_notifications_enabled || !current_user.is_admin;+ $default_push_notifications_setting.toggleClass(+ "control-label-disabled",+ disable_push_notifications,+ );+ $default_push_notifications_setting.find("input").prop("disabled", disable_push_notifications);+if (!sub.can_change_stream_permissions_requiring_metadata_access) {settings_components.disable_group_permission_setting($permission_pill_container_elements);return;diff --git a/web/styles/subscriptions.css b/web/styles/subscriptions.cssindex d73973d57b4..fc4d373acbf 100644--- a/web/styles/subscriptions.css+++ b/web/styles/subscriptions.css@@ -1586,7 +1586,8 @@ h4.stream_setting_subsection_title {}#subscription_overlay .default-stream,-#subscription_overlay .history-public-to-subscribers {+#subscription_overlay .history-public-to-subscribers,+#subscription_overlay .default-push-notifications {width: fit-content;.inline {diff --git a/web/templates/stream_settings/channel_permissions.hbs b/web/templates/stream_settings/channel_permissions.hbsindex f0eee7767f9..7567efe4d82 100644--- a/web/templates/stream_settings/channel_permissions.hbs+++ b/web/templates/stream_settings/channel_permissions.hbs@@ -36,6 +36,21 @@setting_name="can_remove_subscribers_group"label=group_setting_labels.can_remove_subscribers_groupprefix=prefix }}++ {{#unless is_stream_edit}}+ {{#if is_admin}}+ <div class="default-push-notifications">+ {{> ../settings/settings_checkbox+ prefix=prefix+ setting_name="default_push_notifications"+ is_checked=false+ is_disabled=disable_push_notifications+ label=(t "Mobile push notifications enabled by default")+ tooltip_message=push_notifications_tooltip+ }}+ </div>+ {{/if}}+ {{/unless}}</div><div id="channel-messaging-permissions" class="settings-subsection-parent">diff --git a/web/templates/stream_settings/stream_settings.hbs b/web/templates/stream_settings/stream_settings.hbsindex bd1cd21304b..f1d0c051d55 100644--- a/web/templates/stream_settings/stream_settings.hbs+++ b/web/templates/stream_settings/stream_settings.hbs@@ -53,6 +53,16 @@channel_folder_widget_name="folder_id"}}+ <div class="default-push-notifications">+ {{> ../settings/settings_checkbox+ prefix="id_"+ setting_name="default_push_notifications"+ is_checked=(lookup sub "default_push_notifications")+ label=(t "Mobile push notifications enabled by default")+ tooltip_message=push_notifications_tooltip+ }}+ </div>+<div class="input-group stream-email-box"><label for="copy_stream_email_button" class="settings-field-label">{{t "Email address" }}diff --git a/web/tests/lib/events.cjs b/web/tests/lib/events.cjsindex c6458cefbed..497cb7ec2a1 100644--- a/web/tests/lib/events.cjs+++ b/web/tests/lib/events.cjs@@ -66,6 +66,7 @@ exports.test_streams = {can_send_message_group: 2,can_remove_subscribers_group: 2,is_recently_active: true,+ default_push_notifications: false,subscriber_count: 10,},test: {@@ -93,6 +94,7 @@ exports.test_streams = {can_send_message_group: 2,can_remove_subscribers_group: 2,is_recently_active: true,+ default_push_notifications: false,subscriber_count: 2,},};diff --git a/web/tests/stream_data.test.cjs b/web/tests/stream_data.test.cjsindex e74d4817b35..88e0fe89277 100644--- a/web/tests/stream_data.test.cjs+++ b/web/tests/stream_data.test.cjs@@ -796,6 +796,7 @@ test("stream_settings", ({override}) => {can_subscribe_group: admins_group.id,date_created: 1691057093,creator_id: null,+ default_push_notifications: false,};const blue = {@@ -887,6 +888,7 @@ test("stream_settings", ({override}) => {moderators_group.id,);stream_data.update_channel_folder(sub, 3);+ stream_data.update_default_push_notifications(sub, true);assert.equal(sub.invite_only, false);assert.equal(sub.history_public_to_subscribers, false);assert.equal(sub.message_retention_days, -1);@@ -894,6 +896,7 @@ test("stream_settings", ({override}) => {assert.equal(sub.can_remove_subscribers_group, moderators_group.id);assert.equal(sub.can_administer_channel_group, moderators_group.id);assert.equal(sub.folder_id, 3);+ assert.equal(sub.default_push_notifications, true);// For guest user only retrieve subscribed streamssub_rows = stream_settings_data.get_updated_unsorted_subs();diff --git a/web/tests/stream_events.test.cjs b/web/tests/stream_events.test.cjsindex fac4a7cc7b4..df2b5755bb4 100644--- a/web/tests/stream_events.test.cjs+++ b/web/tests/stream_events.test.cjs@@ -296,6 +296,17 @@ test("update_property", ({override, override_rewire}) => {assert.equal(args.val, "allow_topics_policy");}+ // Test stream default_push_notifications change event+ {+ const stub = make_stub();+ override(stream_settings_ui, "update_default_push_notifications_setting", stub.f);+ stream_events.update_property(stream_id, "default_push_notifications", false);+ assert.equal(stub.num_calls, 1);+ const args = stub.get_args("sub", "val");+ assert.equal(args.sub.stream_id, stream_id);+ assert.equal(args.val, false);+ }+// Test stream can_remove_subscribers_group change event{const stub = make_stub();@@ -510,7 +521,7 @@ test("marked_subscribed (normal)", ({override, override_rewire}) => {$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);override_rewire(stream_data, "set_max_channel_width_css_variable", noop);- stream_events.mark_subscribed(sub, [], "blue");+ stream_events.mark_subscribed(sub, [], "blue", true);const args = stream_list_stub.get_args("sub");assert.equal(args.sub.stream_id, sub.stream_id);@@ -525,6 +536,7 @@ test("marked_subscribed (normal)", ({override, override_rewire}) => {assert.equal(show_args.opts.trigger, "subscription confirmed refresh");assert.equal(sub.color, "blue");+ assert.equal(sub.push_notifications, true);message_lists.current = undefined;});@@ -554,7 +566,7 @@ test("marked_subscribed (color)", ({override, override_rewire}) => {const stub = make_stub();override(stream_settings_api, "set_color", stub.f);blueslip.expect("warn", "Frontend needed to pick a color in mark_subscribed");- stream_events.mark_subscribed(sub, [], undefined);+ stream_events.mark_subscribed(sub, [], undefined, null);assert.equal(stub.num_calls, 1);const args = stub.get_args("id", "color");assert.equal(args.id, sub.stream_id);@@ -584,7 +596,7 @@ test("marked_subscribed (emails)", ({override, override_rewire}) => {assert.ok(!stream_data.is_subscribed(sub.stream_id));const user_ids = [15, 20, 25, me.user_id];- stream_events.mark_subscribed(sub, user_ids, "");+ stream_events.mark_subscribed(sub, user_ids, "", null);assert.deepEqual(new Set(peer_data.get_subscriber_ids_assert_loaded(sub.stream_id)),new Set(user_ids),@@ -714,7 +726,7 @@ test("marked_subscribed (new channel creation)", ({override, override_rewire}) =const dialog_widget_stub = make_stub();override(dialog_widget, "launch", dialog_widget_stub.f);- stream_events.mark_subscribed(sub, [], "yellow");+ stream_events.mark_subscribed(sub, [], "yellow", null);// Verify that the creator is redirected to channel view// and the first_stream_created modal is displayed.