From 558ed44d4bb529793c8fb5d68fc35333ebf95f16 Mon Sep 17 00:00:00 2001 From: Kartikay5849 Date: Wed, 19 Mar 2025 00:06:35 +0530 Subject: [PATCH] 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 35289dfe51084641be4a26809362cd9291e103c9) --- web/src/compose_validate.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/web/src/compose_validate.ts b/web/src/compose_validate.ts index b096da4a01..73fc2d90c7 100644 --- a/web/src/compose_validate.ts +++ b/web/src/compose_validate.ts @@ -337,6 +337,7 @@ export function warn_if_mentioning_unsubscribed_user( } } } + export function warn_if_mentioning_unsubscribed_group( mentioned_group: UserGroup, $textarea: JQuery, @@ -348,9 +349,6 @@ export function warn_if_mentioning_unsubscribed_group( const stream_id = get_stream_id_for_textarea($textarea); 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; } @@ -370,15 +368,13 @@ export function warn_if_mentioning_unsubscribed_group( } const $banner_container = compose_banner.get_compose_banner_container($textarea); - if ( - $banner_container.find( - `.${CSS.escape(compose_banner.CLASSNAMES.group_entirely_not_subscribed)}`, - ).length > 0 - ) { - // Don't add a second banner if one is already present. - // TODO: This should work like warn_if_mentioning_unsubscribed_user, - // where we actually check if it's the same group. - return; + + // Check if a banner for this specific group already exists + const $existing_banners = $banner_container.find( + `.${CSS.escape(compose_banner.CLASSNAMES.group_entirely_not_subscribed)} a[data-user-group-id="${mentioned_group.id}"]`, + ); + if ($existing_banners.length > 0) { + return; // Avoid duplicate banners } const context = { @@ -390,6 +386,7 @@ export function warn_if_mentioning_unsubscribed_group( const new_row_html = render_compose_mention_group_warning(context); compose_banner.append_compose_banner_to_banner_list($(new_row_html), $banner_container); } + // Called when clearing the compose box and similar contexts to clear // the warning for composing to a resolved topic, if present. Also clears // the state for whether this warning has already been shown in the