Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
banner: Make banner about automatic follow/unmute topics one-time only.
Prakhar Pratyushbbfcb2dcb3bb
diff --git a/web/src/compose.js b/web/src/compose.jsindex 574c613f0e4..ab3a0a6368a 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -19,6 +19,7 @@ import {$t_html} from "./i18n";import * as loading from "./loading";import * as markdown from "./markdown";import * as message_events from "./message_events";+import * as onboarding_steps from "./onboarding_steps";import {page_params} from "./page_params";import * as people from "./people";import * as rendered_markdown from "./rendered_markdown";@@ -133,9 +134,13 @@ export function send_message_success(request, data) {if (request.type === "stream") {if (data.automatic_new_visibility_policy) {+ if (!onboarding_steps.ONE_TIME_NOTICES_TO_DISPLAY.has("visibility_policy_banner")) {+ return;+ }// topic has been automatically unmuted or followed. No need to// suggest the user to unmute. Show the banner and return.compose_notifications.notify_automatic_new_visibility_policy(request, data);+ onboarding_steps.post_onboarding_step_as_read("visibility_policy_banner");return;}diff --git a/web/src/onboarding_steps.js b/web/src/onboarding_steps.jsindex 85bf2578840..3d2f1b90953 100644--- a/web/src/onboarding_steps.js+++ b/web/src/onboarding_steps.js@@ -1,5 +1,8 @@import * as blueslip from "./blueslip";import * as channel from "./channel";+import {page_params} from "./page_params";++export const ONE_TIME_NOTICES_TO_DISPLAY = new Set();export function post_onboarding_step_as_read(onboarding_step_name) {channel.post({@@ -20,3 +23,17 @@ export function post_onboarding_step_as_read(onboarding_step_name) {export function filter_new_hotspots(onboarding_steps) {return onboarding_steps.filter((onboarding_step) => onboarding_step.type === "hotspot");}++export function update_notice_to_display(onboarding_steps) {+ ONE_TIME_NOTICES_TO_DISPLAY.clear();++ for (const onboarding_step of onboarding_steps) {+ if (onboarding_step.type === "one_time_notice") {+ ONE_TIME_NOTICES_TO_DISPLAY.add(onboarding_step.name);+ }+ }+}++export function initialize() {+ update_notice_to_display(page_params.onboarding_steps);+}diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.jsindex b54796aeb7e..e3e51b88abb 100644--- a/web/src/server_events_dispatch.js+++ b/web/src/server_events_dispatch.js@@ -145,6 +145,7 @@ export function dispatch_normal_event(event) {case "onboarding_steps":hotspots.load_new(onboarding_steps.filter_new_hotspots(event.onboarding_steps));+ onboarding_steps.update_notice_to_display(event.onboarding_steps);page_params.onboarding_steps = page_params.onboarding_steps? [...page_params.onboarding_steps, ...event.onboarding_steps]: event.onboarding_steps;diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex 555564b972b..b7281ee0baf 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -75,6 +75,7 @@ import * as narrow_title from "./narrow_title";import * as navbar_alerts from "./navbar_alerts";import * as navbar_help_menu from "./navbar_help_menu";import * as navigate from "./navigate";+import * as onboarding_steps from "./onboarding_steps";import * as overlays from "./overlays";import {page_params} from "./page_params";import * as people from "./people";@@ -692,6 +693,7 @@ export function initialize_everything() {});drafts.initialize();drafts_overlay_ui.initialize();+ onboarding_steps.initialize();hotspots.initialize();typing.initialize();starred_messages_ui.initialize();diff --git a/web/tests/compose.test.js b/web/tests/compose.test.jsindex f277c2ffcde..886552b10b0 100644--- a/web/tests/compose.test.js+++ b/web/tests/compose.test.js@@ -50,6 +50,7 @@ const sent_messages = mock_esm("../src/sent_messages");const server_events = mock_esm("../src/server_events");const transmit = mock_esm("../src/transmit");const upload = mock_esm("../src/upload");+const onboarding_steps = mock_esm("../src/onboarding_steps");const compose_ui = zrequire("compose_ui");const compose_banner = zrequire("compose_banner");@@ -147,6 +148,12 @@ test_ui("send_message_success", ({override, override_rewire}) => {reify_message_id_checked = true;});+ override(+ onboarding_steps,+ "ONE_TIME_NOTICES_TO_DISPLAY",+ new Set(["visibility_policy_banner"]),+ );+override(compose_notifications, "notify_automatic_new_visibility_policy", (message, data) => {assert.equal(message.type, "stream");assert.equal(message.stream_id, 1);@@ -155,6 +162,10 @@ test_ui("send_message_success", ({override, override_rewire}) => {assert.equal(data.automatic_new_visibility_policy, 2);});+ override(onboarding_steps, "post_onboarding_step_as_read", (onboarding_step_name) => {+ assert.equal(onboarding_step_name, "visibility_policy_banner");+ });+let request = {locally_echoed: false,local_id: "1001",diff --git a/zerver/lib/hotspots.py b/zerver/lib/hotspots.pyindex 810e27bc6d9..df173d9ce15 100644--- a/zerver/lib/hotspots.py+++ b/zerver/lib/hotspots.py@@ -79,7 +79,11 @@ class OneTimeNotice:}-ONE_TIME_NOTICES: List[OneTimeNotice] = []+ONE_TIME_NOTICES: List[OneTimeNotice] = [+ OneTimeNotice(+ name="visibility_policy_banner",+ ),+]# We would most likely implement new hotspots in the future that aren't# a part of the initial tutorial. To that end, classifying them intodiff --git a/zerver/tests/test_hotspots.py b/zerver/tests/test_hotspots.pyindex b5d7579c01f..8c12554d281 100644--- a/zerver/tests/test_hotspots.py+++ b/zerver/tests/test_hotspots.py@@ -38,8 +38,9 @@ class TestGetNextOnboardingSteps(ZulipTestCase):do_mark_onboarding_step_as_read(self.user, "intro_streams")do_mark_onboarding_step_as_read(self.user, "intro_compose")onboarding_steps = get_next_onboarding_steps(self.user)- self.assert_length(onboarding_steps, 1)- self.assertEqual(onboarding_steps[0]["name"], "intro_topics")+ self.assert_length(onboarding_steps, 2)+ self.assertEqual(onboarding_steps[0]["name"], "visibility_policy_banner")+ self.assertEqual(onboarding_steps[1]["name"], "intro_topics")def test_all_onboarding_steps_done(self) -> None:with self.settings(TUTORIAL_ENABLED=True):