refactor(state): add ChatData::format_for for the per-site caption format

Four call sites (cache hit, fresh fetch, startup refetch, /debug preview)
spelled out the same message_format.get(...).cloned().unwrap_or_default();
the accessor names the lookup and keeps the empty-format contract in one
place.
This commit is contained in:
2026-09-21 17:27:42 +08:00
parent 26581cfca1
commit dd98a90a45
3 changed files with 12 additions and 19 deletions
+1 -4
View File
@@ -626,10 +626,7 @@ pub(crate) async fn execute_command(
let format = CHAT_STORE
.get(message.chat.id.0)
.await
.message_format
.get(fetched.site_id)
.cloned()
.unwrap_or_default();
.format_for(fetched.site_id);
let caption = preview_caption(
&format,
&fetched.caption,
+3 -15
View File
@@ -638,11 +638,7 @@ async fn url_media_inner(
// Cache keys are prefixed with the site id ("twitter:…"), matching
// the value a fresh fetch would read from Fetched::site_id.
let site = x_media::site::site_id_from_key(&key);
let format = chat_data
.message_format
.get(site)
.cloned()
.unwrap_or_default();
let format = chat_data.format_for(site);
// 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(
@@ -713,11 +709,7 @@ async fn url_media_inner(
}
let chat_data = ctx.chat_store.get(chat_id).await;
// Per-site caption format override (empty -> built-in caption).
let format = chat_data
.message_format
.get(fetched.site_id)
.cloned()
.unwrap_or_default();
let format = chat_data.format_for(fetched.site_id);
let caption = fetched.caption_with(&format);
// Raw render data for the link cache; the send fills in the
// Telegram file ids and persists the entry.
@@ -862,11 +854,7 @@ async fn refetch(
return Ok(None);
}
let chat_data = ctx.chat_store.get(chat_id).await;
let format = chat_data
.message_format
.get(fetched.site_id)
.cloned()
.unwrap_or_default();
let format = chat_data.format_for(fetched.site_id);
let caption = fetched.caption_with(&format);
let cache_data = fetched
.render_fields()