Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Add container parameter to functions.
Daniil Fadeev209e9edd9d4a
diff --git a/web/src/compose.js b/web/src/compose.jsindex e14fceea928..fd4af2e8d3d 100644--- a/web/src/compose.js+++ b/web/src/compose.js@@ -474,7 +474,8 @@ export function initialize() {`.${CSS.escape(compose_banner.CLASSNAMES.wildcard_warning)} .compose_banner_action_button`,(event) => {event.preventDefault();- compose_validate.clear_wildcard_warnings();+ const {$banner_container} = get_input_info(event);+ compose_validate.clear_wildcard_warnings($banner_container);compose_validate.set_user_acknowledged_wildcard_flag(true);finish();},diff --git a/web/src/compose_actions.js b/web/src/compose_actions.jsindex 1da45b15901..c81811f9186 100644--- a/web/src/compose_actions.js+++ b/web/src/compose_actions.js@@ -65,7 +65,7 @@ function clear_box() {// TODO: Better encapsulate at-mention warnings.compose_validate.clear_topic_resolved_warning();- compose_validate.clear_wildcard_warnings();+ compose_validate.clear_wildcard_warnings($("#compose_banners"));compose.clear_private_stream_alert();compose_validate.set_user_acknowledged_wildcard_flag(undefined);diff --git a/web/src/compose_validate.js b/web/src/compose_validate.jsindex 1c65b41ab20..101a7a3ffed 100644--- a/web/src/compose_validate.js+++ b/web/src/compose_validate.js@@ -230,34 +230,36 @@ export function warn_if_topic_resolved(topic_changed) {}}-function show_wildcard_warnings(stream_id) {+function show_wildcard_warnings(stream_id, $banner_container) {const subscriber_count = peer_data.get_subscriber_count(stream_id) || 0;+ const stream_name = stream_data.maybe_get_stream_name(stream_id);+ const is_edit_container = $banner_container.closest(".edit_form_banners").length > 0;+ const button_text = is_edit_container+ ? $t({defaultMessage: "Yes, save"})+ : $t({defaultMessage: "Yes, send"});const classname = compose_banner.CLASSNAMES.wildcard_warning;const wildcard_template = render_wildcard_warning({banner_type: compose_banner.WARNING,subscriber_count,- stream_name: compose_state.stream_name(),+ stream_name,wildcard_mention,- button_text: $t({defaultMessage: "Yes, send"}),+ button_text,hide_close_button: true,classname,});// only show one error for any number of @all or @everyone mentions- if ($(`#compose_banners .${CSS.escape(classname)}`).length === 0) {- compose_banner.append_compose_banner_to_banner_list(- wildcard_template,- $("#compose_banners"),- );+ if ($banner_container.find(`.${CSS.escape(classname)}`).length === 0) {+ compose_banner.append_compose_banner_to_banner_list(wildcard_template, $banner_container);}user_acknowledged_wildcard = false;}-export function clear_wildcard_warnings() {+export function clear_wildcard_warnings($banner_container) {const classname = compose_banner.CLASSNAMES.wildcard_warning;- $(`#compose_banners .${CSS.escape(classname)}`).remove();+ $banner_container.find(`.${CSS.escape(classname)}`).remove();}export function set_user_acknowledged_wildcard_flag(value) {@@ -355,7 +357,7 @@ export function set_wildcard_mention_large_stream_threshold(value) {wildcard_mention_large_stream_threshold = value;}-function validate_stream_message_mentions(stream_id) {+export function validate_stream_message_mentions(stream_id, $banner_container) {const subscriber_count = peer_data.get_subscriber_count(stream_id) || 0;// If the user is attempting to do a wildcard mention in a large@@ -368,16 +370,13 @@ function validate_stream_message_mentions(stream_id) {"You do not have permission to use wildcard mentions in this stream.",}),compose_banner.CLASSNAMES.wildcards_not_allowed,- // Since we don't trigger validation in edit mode, the only place where- // wildcard warnings will appear is the compose banners container.- $("#compose_banners"),+ $banner_container,);return false;}if (user_acknowledged_wildcard === undefined || user_acknowledged_wildcard === false) {- // user has not seen a warning message yet if undefined- show_wildcard_warnings(stream_id);+ show_wildcard_warnings(stream_id, $banner_container);$("#compose-send-button").prop("disabled", false);compose_ui.hide_compose_spinner();@@ -385,7 +384,7 @@ function validate_stream_message_mentions(stream_id) {}} else {// the message no longer contains @all or @everyone- clear_wildcard_warnings();+ clear_wildcard_warnings($banner_container);}// at this point, the user has either acknowledged the warning or removed @all / @everyoneuser_acknowledged_wildcard = undefined;@@ -496,7 +495,7 @@ function validate_stream_message() {if (!validate_stream_message_address_info(stream_name) ||- !validate_stream_message_mentions(sub.stream_id)+ !validate_stream_message_mentions(sub.stream_id, $banner_container)) {return false;}diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.jsindex 9e0e8264286..88567cc2a7c 100644--- a/web/tests/compose_validate.test.js+++ b/web/tests/compose_validate.test.js@@ -366,7 +366,6 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {// of execution should not be changed.mock_banners();override_rewire(compose_recipient, "on_compose_select_recipient_update", () => {});- $("#compose_banners .wildcard_warning").length = 0;page_params.user_id = me.user_id;page_params.realm_mandatory_topics = false;const sub = {diff --git a/web/tests/lib/compose_banner.js b/web/tests/lib/compose_banner.jsindex 75a28fe4126..b4de309cc66 100644--- a/web/tests/lib/compose_banner.js+++ b/web/tests/lib/compose_banner.js@@ -12,4 +12,23 @@ exports.mock_banners = () => {}$("#compose_banners .warning").remove = () => {};$("#compose_banners .error").remove = () => {};++ const $stub = $.create("stub_to_remove");+ const $cb = $("#compose_banners");++ $stub.remove = () => {};+ $stub.length = 0;++ $cb.closest = () => [];+ $cb.set_find_results(".no_post_permissions", $stub);+ $cb.set_find_results(".message_too_long", $stub);+ $cb.set_find_results(".wildcards_not_allowed", $stub);+ $cb.set_find_results(".wildcard_warning", $stub);+ $cb.set_find_results(".topic_missing", $stub);+ $cb.set_find_results(".missing_stream", $stub);+ $cb.set_find_results(".zephyr_not_running", $stub);+ $cb.set_find_results(".deactivated_user", $stub);+ $cb.set_find_results(".missing_private_message_recipient", $stub);+ $cb.set_find_results(".subscription_error", $stub);+ $cb.set_find_results(".generic_compose_error", $stub);};