From 40ab07882ddd2270fa72967c1c93559613e52c75 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 21 Sep 2026 17:35:07 +0800 Subject: [PATCH] fix(handlers): restore the group hint's link filter Replacing is_group(kind) with teloxide's predicates dropped the parentheses: && binds tighter than ||, so the branch read as is_group() OR (is_supergroup() AND has-link) -- a plain group got the hint for any link, supported or not. The e2e test only covered a group with a supported link (which is true either way); it now also covers an unsupported link in a group. --- crates/xmedia-bot/src/handlers/mod.rs | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/crates/xmedia-bot/src/handlers/mod.rs b/crates/xmedia-bot/src/handlers/mod.rs index b2a834d..bc8a2d4 100644 --- a/crates/xmedia-bot/src/handlers/mod.rs +++ b/crates/xmedia-bot/src/handlers/mod.rs @@ -265,11 +265,10 @@ pub(crate) async fn handle_message( break; } } - } else if message.chat.is_group() - || message.chat.is_supergroup() - && extract_urls(&message) - .iter() - .any(|url| x_media::site::cache_key(url).is_some()) + } else if (message.chat.is_group() || message.chat.is_supergroup()) + && extract_urls(&message) + .iter() + .any(|url| x_media::site::cache_key(url).is_some()) { // A supported link in a group used to be dropped in silence, which // reads as a broken bot (the command menu is registered globally, so @@ -470,5 +469,24 @@ mod tests { vec!["EditMessageCaption", "SendMessage"], "a channel must not get the group hint" ); + + // And an *unsupported* link in a group stays silent too: the hint is + // for links a site adapter claims (the branch's own filter). + let unsupported: Message = serde_json::from_value(serde_json::json!({ + "message_id": 4, + "date": 0, + "chat": { "id": -100, "type": "group", "title": "g" }, + "text": "https://example.com/x", + "entities": [{ "type": "url", "offset": 0, "length": 19 }], + })) + .expect("a minimal group message deserializes"); + + handle_message(&ctx, &bot, unsupported).await.unwrap(); + + assert_eq!( + api.methods(), + vec!["EditMessageCaption", "SendMessage"], + "an unsupported link must not get the hint" + ); } }