mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-28 00:02:12 +00:00
refactor(send): media_from reads the thumbnail off the item itself
All three callers passed item.thumbnail_url() as the fourth argument — a parameter that could never vary without defeating its own purpose, and only the video arm ever reads it. The function takes the item already; it asks the item. Three call sites lose an argument.
This commit is contained in:
@@ -51,7 +51,6 @@ pub(super) fn media_from(
|
|||||||
item: &MediaItemPayload,
|
item: &MediaItemPayload,
|
||||||
file: InputFile,
|
file: InputFile,
|
||||||
caption: Option<&str>,
|
caption: Option<&str>,
|
||||||
thumbnail: Option<&str>,
|
|
||||||
) -> Result<InputMedia, String> {
|
) -> Result<InputMedia, String> {
|
||||||
let media = match item {
|
let media = match item {
|
||||||
MediaItemPayload::Photo { has_spoiler, .. } => {
|
MediaItemPayload::Photo { has_spoiler, .. } => {
|
||||||
@@ -85,7 +84,10 @@ pub(super) fn media_from(
|
|||||||
InputMedia::Animation(media)
|
InputMedia::Animation(media)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match (thumbnail, media) {
|
// The thumbnail comes off the item itself — every caller passed exactly
|
||||||
|
// that, and only a video uses it (Telegram takes it as a separate
|
||||||
|
// upload/URL).
|
||||||
|
match (item.thumbnail_url(), media) {
|
||||||
(Some(thumb), InputMedia::Video(video)) => {
|
(Some(thumb), InputMedia::Video(video)) => {
|
||||||
Ok(InputMedia::Video(video.thumbnail(input_file_for(thumb)?)))
|
Ok(InputMedia::Video(video.thumbnail(input_file_for(thumb)?)))
|
||||||
}
|
}
|
||||||
@@ -104,7 +106,7 @@ pub(super) fn build_media_group(
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, item)| {
|
.map(|(i, item)| {
|
||||||
let item_caption = if i == 0 { caption } else { None };
|
let item_caption = if i == 0 { caption } else { None };
|
||||||
media_from(item, item.input_file()?, item_caption, item.thumbnail_url())
|
media_from(item, item.input_file()?, item_caption)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ fn media_from_file(
|
|||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
caption: Option<&str>,
|
caption: Option<&str>,
|
||||||
) -> Result<InputMedia, String> {
|
) -> Result<InputMedia, String> {
|
||||||
media_from(item, InputFile::file(path), caption, item.thumbnail_url())
|
media_from(item, InputFile::file(path), caption)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the media group item from a (smaller) URL.
|
/// Builds the media group item from a (smaller) URL.
|
||||||
@@ -198,7 +198,7 @@ fn media_from_url(
|
|||||||
url: &str,
|
url: &str,
|
||||||
caption: Option<&str>,
|
caption: Option<&str>,
|
||||||
) -> Result<InputMedia, String> {
|
) -> Result<InputMedia, String> {
|
||||||
media_from(item, input_file_for(url)?, caption, item.thumbnail_url())
|
media_from(item, input_file_for(url)?, caption)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One item prepared for the upload fallback: the ready-to-send media plus
|
/// One item prepared for the upload fallback: the ready-to-send media plus
|
||||||
|
|||||||
Reference in New Issue
Block a user