refactor: extend channel to carry voice note bytes

This commit is contained in:
Lewis Wynne 2026-04-10 02:17:05 +01:00
parent d66e004b0d
commit 54764935c2
3 changed files with 6 additions and 6 deletions

View file

@ -18,7 +18,7 @@ async fn main() {
std::fs::create_dir_all(&entries_dir).ok(); std::fs::create_dir_all(&entries_dir).ok();
let (tx, rx) = tokio::sync::mpsc::channel::<(entries::Entry, Option<Vec<u8>>)>(32); let (tx, rx) = tokio::sync::mpsc::channel::<(entries::Entry, Option<Vec<u8>>, Option<Vec<u8>>)>(32);
// Spawn telegram tasks if configured // Spawn telegram tasks if configured
match (&config.telegram_bot_token, config.telegram_chat_id) { match (&config.telegram_bot_token, config.telegram_chat_id) {

View file

@ -18,8 +18,8 @@ async fn notify(bot: &Bot, chat_id: ChatId, entry: &Entry) {
} }
/// Listen for new entries on the channel and send Telegram notifications. /// Listen for new entries on the channel and send Telegram notifications.
pub async fn notification_task(bot: Bot, chat_id: ChatId, mut rx: Receiver<(Entry, Option<Vec<u8>>)>) { pub async fn notification_task(bot: Bot, chat_id: ChatId, mut rx: Receiver<(Entry, Option<Vec<u8>>, Option<Vec<u8>>)>) {
while let Some((entry, drawing_bytes)) = rx.recv().await { while let Some((entry, drawing_bytes, _voice_bytes)) = rx.recv().await {
notify(&bot, chat_id, &entry).await; notify(&bot, chat_id, &entry).await;
if let Some(bytes) = drawing_bytes { if let Some(bytes) = drawing_bytes {
if let Err(e) = bot.send_photo( if let Err(e) = bot.send_photo(

View file

@ -18,7 +18,7 @@ use crate::render::{self, DEFAULT_TEMPLATE, render_error_page, render_success_pa
pub struct AppState { pub struct AppState {
pub config: Config, pub config: Config,
pub tx: tokio::sync::mpsc::Sender<(Entry, Option<Vec<u8>>)>, pub tx: tokio::sync::mpsc::Sender<(Entry, Option<Vec<u8>>, Option<Vec<u8>>)>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -228,7 +228,7 @@ async fn submit(
} }
// Notify telegram task // Notify telegram task
let _ = state.tx.send((entry, drawing_bytes)).await; let _ = state.tx.send((entry, drawing_bytes, None)).await;
Html(render_success_page(&state.config)) Html(render_success_page(&state.config))
} }
@ -283,7 +283,7 @@ mod tests {
} }
} }
fn test_app(config: Config) -> (Router, tokio::sync::mpsc::Receiver<(Entry, Option<Vec<u8>>)>) { fn test_app(config: Config) -> (Router, tokio::sync::mpsc::Receiver<(Entry, Option<Vec<u8>>, Option<Vec<u8>>)>) {
let (tx, rx) = tokio::sync::mpsc::channel(32); let (tx, rx) = tokio::sync::mpsc::channel(32);
let state = Arc::new(AppState { config, tx }); let state = Arc::new(AppState { config, tx });
(router(state), rx) (router(state), rx)