diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index a3b82091..dc31ae50 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -11,7 +11,7 @@ macro_rules! impl_request_reply_ext { fn reply_to(self, message_id: M) -> Self where M: Into, - Self: teloxide_core::requests::HasPayload + Sized, + Self: Sized, { self.reply_parameters(ReplyParameters::new(message_id.into())) } @@ -20,6 +20,28 @@ macro_rules! impl_request_reply_ext { }; } +macro_rules! impl_request_link_preview_ext { + ($($t:ty),*) => { + $( + impl RequestLinkPreviewExt for $t { + fn disable_link_preview(self) -> Self + where + Self: Sized + { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + self.link_preview_options(link_preview_options) + } + } + )* + }; +} + pub trait RequestReplyExt { fn reply_to(self, message_id: M) -> Self where @@ -27,10 +49,20 @@ pub trait RequestReplyExt { Self: Sized; } +pub trait RequestLinkPreviewExt { + fn disable_link_preview(self) -> Self + where + Self: Sized; +} + impl_request_reply_ext! { ::SendMessage } +impl_request_link_preview_ext! { + ::SendMessage +} + #[cfg(test)] mod tests { use std::ops::Deref; @@ -48,4 +80,21 @@ mod tests { assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) } + + #[test] + fn test_disable_link_preview() { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + let bot = Bot::new("TOKEN"); + let real_link_req = + bot.send_message(ChatId(1234), "test").link_preview_options(link_preview_options); + let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(); + + assert_eq!(real_link_req.deref(), sugar_link_req.deref()) + } }