Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose_banner: Show banner when automatically follow or unmute topic.
Prakhar Pratyushd1f82c47fd08
diff --git a/web/src/compose.js b/web/src/compose.jsindex 40939ba55a9..773c60770f9 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -8,6 +8,7 @@ import render_success_message_scheduled_banner from "../templates/compose_bannerimport * as channel from "./channel";import * as compose_banner from "./compose_banner";+import * as compose_notifications from "./compose_notifications";import * as compose_state from "./compose_state";import * as compose_ui from "./compose_ui";import * as compose_validate from "./compose_validate";@@ -118,15 +119,29 @@ export function clear_compose_box() {scheduled_messages.reset_selected_schedule_timestamp();}-export function send_message_success(local_id, message_id, locally_echoed) {- if (!locally_echoed) {+export function send_message_success(request, data) {+ if (!request.locally_echoed) {if ($("#compose-textarea").data("draft-id")) {drafts.draft_model.deleteDraft($("#compose-textarea").data("draft-id"));}clear_compose_box();}- echo.reify_message_id(local_id, message_id);+ echo.reify_message_id(request.local_id, data.id);++ if (request.type === "stream") {+ if (data.automatic_new_visibility_policy) {+ // 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);+ return;+ }++ const muted_narrow = compose_notifications.get_muted_narrow(request);+ if (muted_narrow) {+ compose_notifications.notify_unmute(muted_narrow, request.stream_id, request.topic);+ }+ }}export function send_message(request = create_message_object()) {@@ -161,7 +176,7 @@ export function send_message(request = create_message_object()) {request.resend = false;function success(data) {- send_message_success(local_id, data.id, locally_echoed);+ send_message_success(request, data);}function error(response) {diff --git a/web/src/compose_banner.ts b/web/src/compose_banner.tsindex fa4d1251bf9..c46fb0a7de8 100644--- a/web/src/compose_banner.ts+++ b/web/src/compose_banner.ts@@ -13,11 +13,13 @@ export function set_scroll_to_message_banner_message_id(val: number | null): voi// banner typesexport const WARNING = "warning";export const ERROR = "error";+export const SUCCESS = "success";const MESSAGE_SENT_CLASSNAMES = {sent_scroll_to_view: "sent_scroll_to_view",narrow_to_recipient: "narrow_to_recipient",message_scheduled_success_compose_banner: "message_scheduled_success_compose_banner",+ automatic_new_visibility_policy: "automatic_new_visibility_policy",};// Technically, unmute_topic_notification is a message sent banner, but// it has distinct behavior / look - it has an associated action button,diff --git a/web/src/compose_notifications.js b/web/src/compose_notifications.jsindex 7bc282ab1f5..22cd17e28ac 100644--- a/web/src/compose_notifications.js+++ b/web/src/compose_notifications.js@@ -1,5 +1,6 @@import $ from "jquery";+import render_automatic_new_visibility_policy_banner from "../templates/compose_banner/automatic_new_visibility_policy_banner.hbs";import render_message_sent_banner from "../templates/compose_banner/message_sent_banner.hbs";import render_unmute_topic_banner from "../templates/compose_banner/unmute_topic_banner.hbs";@@ -13,7 +14,7 @@ import * as people from "./people";import * as stream_data from "./stream_data";import * as user_topics from "./user_topics";-function notify_unmute(muted_narrow, stream_id, topic_name) {+export function notify_unmute(muted_narrow, stream_id, topic_name) {const $unmute_notification = $(render_unmute_topic_banner({muted_narrow,@@ -53,6 +54,25 @@ export function notify_above_composebox(compose_banner.append_compose_banner_to_banner_list($notification, $("#compose_banners"));}+export function notify_automatic_new_visibility_policy(message, data) {+ const followed =+ data.automatic_new_visibility_policy === user_topics.all_visibility_policies.FOLLOWED;+ const stream_topic = get_message_header(message);+ const narrow_url = get_above_composebox_narrow_url(message);+ const $notification = $(+ render_automatic_new_visibility_policy_banner({+ banner_type: compose_banner.SUCCESS,+ classname: compose_banner.CLASSNAMES.automatic_new_visibility_policy,+ link_msg_id: data.id,+ stream_topic,+ narrow_url,+ followed,+ button_text: $t({defaultMessage: "Change setting"}),+ }),+ );+ compose_banner.append_compose_banner_to_banner_list($notification, $("#compose_banners"));+}+// Note that this returns values that are not HTML-escaped, for use in// Handlebars templates that will do further escaping.function get_message_header(message) {@@ -141,15 +161,6 @@ export function notify_local_mixes(messages, need_user_to_scroll) {continue;}- const muted_narrow = get_muted_narrow(message);- if (muted_narrow) {- notify_unmute(muted_narrow, message.stream_id, message.topic);- // We don't `continue` after showing the unmute banner, allowing multiple- // banners (at max 2 including the unmute banner) to be shown at once,- // as it's common for the unmute case to occur simultaneously with- // another banner's case, like sending a message to another narrow.- }-let banner_text = get_local_notify_mix_reason(message);const link_msg_id = message.id;@@ -244,7 +255,7 @@ export function reify_message_id(opts) {export function initialize({on_click_scroll_to_selected, on_narrow_to_recipient}) {$("#compose_banners").on("click",- ".narrow_to_recipient .above_compose_banner_action_link",+ ".narrow_to_recipient .above_compose_banner_action_link, .automatic_new_visibility_policy .above_compose_banner_action_link",(e) => {const message_id = $(e.currentTarget).data("message-id");on_narrow_to_recipient(message_id);diff --git a/web/src/compose_setup.js b/web/src/compose_setup.jsindex 149615d896c..87e2e5fe42b 100644--- a/web/src/compose_setup.js+++ b/web/src/compose_setup.js@@ -179,6 +179,17 @@ export function initialize() {},);+ $("body").on(+ "click",+ `.${CSS.escape(+ compose_banner.CLASSNAMES.automatic_new_visibility_policy,+ )} .main-view-banner-action-button`,+ (event) => {+ event.preventDefault();+ window.location.href = "/#settings/notifications";+ },+ );+$("body").on("click",`.${CSS.escape(diff --git a/web/src/echo.js b/web/src/echo.jsindex ea2f9316b76..bd337cf2885 100644--- a/web/src/echo.js+++ b/web/src/echo.js@@ -84,15 +84,13 @@ function resend_message(message, $row, {on_send_message_success, send_message})message.queue_id = page_params.queue_id;message.resend = true;- const local_id = message.local_id;-function on_success(data) {const message_id = data.id;- const locally_echoed = true;+ message.locally_echoed = true;hide_retry_spinner($row);- on_send_message_success(local_id, message_id, locally_echoed);+ on_send_message_success(message, data);// Resend succeeded, so mark as no longer failedfailed_message_success(message_id);diff --git a/web/src/transmit.js b/web/src/transmit.jsindex 29658fccfef..48efd18d079 100644--- a/web/src/transmit.js+++ b/web/src/transmit.js@@ -26,7 +26,8 @@ export function send_message(request, on_success, error) {data: request,success: function success(data) {// Call back to our callers to do things like closing the compose- // box and turning off spinners and reifying locally echoed messages.+ // box, turning off spinners, reifying locally echoed messages and+ // displaying visibility policy related compose banners.on_success(data);// Once everything is done, get ready to report times to the server.const state = sent_messages.get_message_state(request.local_id);diff --git a/web/templates/compose_banner/automatic_new_visibility_policy_banner.hbs b/web/templates/compose_banner/automatic_new_visibility_policy_banner.hbsnew file mode 100644index 00000000000..552d004edc6--- /dev/null+++ b/web/templates/compose_banner/automatic_new_visibility_policy_banner.hbs@@ -0,0 +1,10 @@+{{#> compose_banner }}+ <p class="banner_message">+ {{#if followed}}+ {{#tr}}Now following {{/tr}}+ {{else}}+ {{#tr}}Unmuted {{/tr}}+ {{/if}}+ <a class="above_compose_banner_action_link" href="{{narrow_url}}" data-message-id="{{link_msg_id}}">{{stream_topic}}</a>.+ </p>+{{/compose_banner}}diff --git a/web/tests/compose.test.js b/web/tests/compose.test.jsindex 8149d3777a6..e1a955d59eb 100644--- a/web/tests/compose.test.js+++ b/web/tests/compose.test.js@@ -39,6 +39,7 @@ const compose_actions = mock_esm("../src/compose_actions", {register_compose_box_clear_hook: noop,});const compose_fade = mock_esm("../src/compose_fade");+const compose_notifications = mock_esm("../src/compose_notifications");const compose_pm_pill = mock_esm("../src/compose_pm_pill");const loading = mock_esm("../src/loading");const markdown = mock_esm("../src/markdown");@@ -128,11 +129,16 @@ function initialize_handlers({override}) {compose_setup.initialize();}-test_ui("send_message_success", ({override_rewire}) => {+test_ui("send_message_success", ({override, override_rewire}) => {mock_banners();- $("#compose-textarea").val("foobarfoobar");- $("#compose-textarea").trigger("blur");- $(".compose-submit-button .loader").show();++ function reset() {+ $("#compose-textarea").val("foobarfoobar");+ $("#compose-textarea").trigger("blur");+ $(".compose-submit-button .loader").show();+ }++ reset();let reify_message_id_checked;override_rewire(echo, "reify_message_id", (local_id, message_id) => {@@ -141,12 +147,51 @@ test_ui("send_message_success", ({override_rewire}) => {reify_message_id_checked = true;});- compose.send_message_success("1001", 12, false);+ override(compose_notifications, "notify_automatic_new_visibility_policy", (message, data) => {+ assert.equal(message.type, "stream");+ assert.equal(message.stream_id, 1);+ assert.equal(message.topic, "test");+ assert.equal(data.id, 12);+ assert.equal(data.automatic_new_visibility_policy, 2);+ });++ let request = {+ locally_echoed: false,+ local_id: "1001",+ type: "stream",+ stream_id: 1,+ topic: "test",+ };+ let data = {id: 12, automatic_new_visibility_policy: 2};+ compose.send_message_success(request, data);assert.equal($("#compose-textarea").val(), "");assert.ok($("#compose-textarea").is_focused());assert.ok(!$(".compose-submit-button .loader").visible());+ assert.ok(reify_message_id_checked);++ reset();+ reify_message_id_checked = false;+ override(compose_notifications, "get_muted_narrow", (message) => {+ assert.equal(message.type, "stream");+ assert.equal(message.stream_id, 2);+ assert.equal(message.topic, "test");+ });++ request = {+ locally_echoed: false,+ local_id: "1001",+ type: "stream",+ stream_id: 2,+ topic: "test",+ };+ data = {id: 12};+ compose.send_message_success(request, data);++ assert.equal($("#compose-textarea").val(), "");+ assert.ok($("#compose-textarea").is_focused());+ assert.ok(!$(".compose-submit-button .loader").visible());assert.ok(reify_message_id_checked);});