refactor(urls): fold the cache-hit caption branch into one call

caption_from_fields already returns truncate_caption(built_in) for an empty
format, which is exactly what the if-branch did; passing cached.caption as
built_in makes both paths one call. The format path is unmoved -- built_in is
read only when the format is empty.
This commit is contained in:
2026-09-21 17:06:46 +08:00
parent 9aed6f4a24
commit b9dd1f4d08
+12 -14
View File
@@ -643,20 +643,18 @@ async fn url_media_inner(
.get(site)
.cloned()
.unwrap_or_default();
let caption = if format.is_empty() {
x_media::site::truncate_caption(&cached.caption)
} else {
x_media::site::caption_from_fields(
&format,
"",
&cached.url,
&cached.author,
&cached.author_url,
&cached.title,
&cached.content,
&cached.tags,
)
};
// One call for both: `caption_from_fields` returns the truncated
// built-in caption itself when the chat has no format for this site.
let caption = x_media::site::caption_from_fields(
&format,
&cached.caption,
&cached.url,
&cached.author,
&cached.author_url,
&cached.title,
&cached.content,
&cached.tags,
);
let items: Vec<MediaItemPayload> = cached
.media
.iter()