compose: Prevent duplicate group mention warning banners.

We now use `data-user-group-id` to check if a banner for the same
group already exists, preventing duplicate warnings when the same
group is mentioned multiple times.

(cherry picked from commit 35289dfe51)
This commit is contained in:
Kartikay5849
2025-03-19 00:06:35 +05:30
committed by Tim Abbott
parent 7efac715a8
commit 558ed44d4b

View File

@@ -337,6 +337,7 @@ export function warn_if_mentioning_unsubscribed_user(
} }
} }
} }
export function warn_if_mentioning_unsubscribed_group( export function warn_if_mentioning_unsubscribed_group(
mentioned_group: UserGroup, mentioned_group: UserGroup,
$textarea: JQuery<HTMLTextAreaElement>, $textarea: JQuery<HTMLTextAreaElement>,
@@ -348,9 +349,6 @@ export function warn_if_mentioning_unsubscribed_group(
const stream_id = get_stream_id_for_textarea($textarea); const stream_id = get_stream_id_for_textarea($textarea);
if (!stream_id) { if (!stream_id) {
// One could imagine doing something with DMs here, but given
// all DMs are given the same notification prevalence as
// mentions, it doesn't seem useful.
return; return;
} }
@@ -370,15 +368,13 @@ export function warn_if_mentioning_unsubscribed_group(
} }
const $banner_container = compose_banner.get_compose_banner_container($textarea); const $banner_container = compose_banner.get_compose_banner_container($textarea);
if (
$banner_container.find( // Check if a banner for this specific group already exists
`.${CSS.escape(compose_banner.CLASSNAMES.group_entirely_not_subscribed)}`, const $existing_banners = $banner_container.find(
).length > 0 `.${CSS.escape(compose_banner.CLASSNAMES.group_entirely_not_subscribed)} a[data-user-group-id="${mentioned_group.id}"]`,
) { );
// Don't add a second banner if one is already present. if ($existing_banners.length > 0) {
// TODO: This should work like warn_if_mentioning_unsubscribed_user, return; // Avoid duplicate banners
// where we actually check if it's the same group.
return;
} }
const context = { const context = {
@@ -390,6 +386,7 @@ export function warn_if_mentioning_unsubscribed_group(
const new_row_html = render_compose_mention_group_warning(context); const new_row_html = render_compose_mention_group_warning(context);
compose_banner.append_compose_banner_to_banner_list($(new_row_html), $banner_container); compose_banner.append_compose_banner_to_banner_list($(new_row_html), $banner_container);
} }
// Called when clearing the compose box and similar contexts to clear // Called when clearing the compose box and similar contexts to clear
// the warning for composing to a resolved topic, if present. Also clears // the warning for composing to a resolved topic, if present. Also clears
// the state for whether this warning has already been shown in the // the state for whether this warning has already been shown in the