Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose_banner: Add `update_or_append_banner` method in `compose_banner`.

Lalit407629b46c1d
diff --git a/web/src/compose_banner.ts b/web/src/compose_banner.ts
index a7565f33f35..5f5b61e0afe 100644
--- a/web/src/compose_banner.ts
+++ b/web/src/compose_banner.ts
@@ -67,6 +67,19 @@ export function append_compose_banner_to_banner_list(
scroll_util.get_content_element($list_container).append(banner);
}
+export function update_or_append_banner(
+ banner: HTMLElement | JQuery.htmlString,
+ banner_classname: string,
+ $list_container: JQuery,
+): void {
+ const $banner = $list_container.find(`.${CSS.escape(banner_classname)}`);
+ if ($banner.length === 0) {
+ append_compose_banner_to_banner_list(banner, $list_container);
+ } else {
+ $banner.replaceWith(banner);
+ }
+}
+
export function clear_message_sent_banners(include_unmute_banner = true): void {
for (const classname of Object.values(MESSAGE_SENT_CLASSNAMES)) {
$(`#compose_banners .${CSS.escape(classname)}`).remove();
diff --git a/web/src/compose_validate.js b/web/src/compose_validate.js
index e624c9c3a8b..ceddbde36a6 100644
--- a/web/src/compose_validate.js
+++ b/web/src/compose_validate.js
@@ -262,7 +262,11 @@ function show_wildcard_warnings(opts) {
);
} else {
// if there is already a banner, replace it with the new one
- opts.$banner_container.find(`.${CSS.escape(classname)}`).replaceWith(wildcard_template);
+ compose_banner.update_or_append_banner(
+ wildcard_template,
+ classname,
+ opts.$banner_container,
+ );
}
user_acknowledged_wildcard = false;
diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.js
index 88567cc2a7c..f0137131a39 100644
--- a/web/tests/compose_validate.test.js
+++ b/web/tests/compose_validate.test.js
@@ -389,6 +389,8 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
assert.equal(data.subscriber_count, 16);
});
+ compose_banner.update_or_append_banner = () => {};
+
override_rewire(compose_validate, "wildcard_mention_allowed", () => true);
compose_state.message_content("Hey @**all**");
assert.ok(!compose_validate.validate());