Skip to content

Commit ca27bda

Browse files
AndrielFRLonami
authored andcommitted
refactor(types): simplify conversion from Article to InlineResult
Refactored the conversion from Article to InlineResult by introducing a new From<Article> implementation for tl::enums::InputBotInlineResult. This simplifies the conversion logic and improves code readability.
1 parent be92e5e commit ca27bda

File tree

1 file changed

+34
-30
lines changed
  • lib/grammers-client/src/types/inline

1 file changed

+34
-30
lines changed

lib/grammers-client/src/types/inline/query.rs

+34-30
Original file line numberDiff line numberDiff line change
@@ -209,36 +209,40 @@ impl Article {
209209

210210
impl From<Article> for InlineResult {
211211
fn from(article: Article) -> Self {
212-
Self(tl::enums::InputBotInlineResult::Result(
213-
tl::types::InputBotInlineResult {
214-
id: article
215-
.id
216-
.unwrap_or_else(|| generate_random_id().to_string()),
217-
r#type: "article".into(),
218-
title: Some(article.title),
219-
description: article.description,
220-
url: article.url,
221-
thumb: article.thumb_url.map(|url| {
222-
tl::enums::InputWebDocument::Document(tl::types::InputWebDocument {
223-
url,
224-
size: 0,
225-
mime_type: "image/jpeg".into(),
226-
attributes: vec![],
227-
})
228-
}),
229-
content: None,
230-
// TODO: also allow other types of messages than text
231-
send_message: tl::enums::InputBotInlineMessage::Text(
232-
tl::types::InputBotInlineMessageText {
233-
no_webpage: !article.input_message.link_preview,
234-
invert_media: article.input_message.invert_media,
235-
message: article.input_message.text,
236-
entities: Some(article.input_message.entities),
237-
reply_markup: article.input_message.reply_markup,
238-
},
239-
),
240-
},
241-
))
212+
Self(article.into())
213+
}
214+
}
215+
216+
impl From<Article> for tl::enums::InputBotInlineResult {
217+
fn from(article: Article) -> Self {
218+
tl::enums::InputBotInlineResult::Result(tl::types::InputBotInlineResult {
219+
id: article
220+
.id
221+
.unwrap_or_else(|| generate_random_id().to_string()),
222+
r#type: "article".into(),
223+
title: Some(article.title),
224+
description: article.description,
225+
url: article.url,
226+
thumb: article.thumb_url.map(|url| {
227+
tl::enums::InputWebDocument::Document(tl::types::InputWebDocument {
228+
url,
229+
size: 0,
230+
mime_type: "image/jpeg".into(),
231+
attributes: vec![],
232+
})
233+
}),
234+
content: None,
235+
// TODO: also allow other types of messages than text
236+
send_message: tl::enums::InputBotInlineMessage::Text(
237+
tl::types::InputBotInlineMessageText {
238+
no_webpage: !article.input_message.link_preview,
239+
invert_media: article.input_message.invert_media,
240+
message: article.input_message.text,
241+
entities: Some(article.input_message.entities),
242+
reply_markup: article.input_message.reply_markup,
243+
},
244+
),
245+
})
242246
}
243247
}
244248

0 commit comments

Comments
 (0)