feat: restructures module.nix opts
This commit is contained in:
parent
d26c289f66
commit
2044616aeb
5 changed files with 125 additions and 71 deletions
|
|
@ -18,7 +18,7 @@ async fn main() {
|
|||
|
||||
std::fs::create_dir_all(&entries_dir).ok();
|
||||
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
||||
let (tx, rx) = tokio::sync::mpsc::channel::<(entries::Entry, Option<Vec<u8>>)>(32);
|
||||
|
||||
// Spawn telegram tasks if configured
|
||||
match (&config.telegram_bot_token, config.telegram_chat_id) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,17 @@ async fn notify(bot: &Bot, chat_id: ChatId, entry: &Entry) {
|
|||
}
|
||||
|
||||
/// 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>) {
|
||||
while let Some(entry) = rx.recv().await {
|
||||
pub async fn notification_task(bot: Bot, chat_id: ChatId, mut rx: Receiver<(Entry, Option<Vec<u8>>)>) {
|
||||
while let Some((entry, drawing_bytes)) = rx.recv().await {
|
||||
notify(&bot, chat_id, &entry).await;
|
||||
if let Some(bytes) = drawing_bytes {
|
||||
if let Err(e) = bot.send_photo(
|
||||
chat_id,
|
||||
teloxide::types::InputFile::memory(bytes).file_name("drawing.png"),
|
||||
).await {
|
||||
tracing::error!("failed to send drawing photo: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use crate::render::{self, DEFAULT_TEMPLATE};
|
|||
|
||||
pub struct AppState {
|
||||
pub config: Config,
|
||||
pub tx: tokio::sync::mpsc::Sender<Entry>,
|
||||
pub tx: tokio::sync::mpsc::Sender<(Entry, Option<Vec<u8>>)>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -205,8 +205,6 @@ async fn submit(
|
|||
} else {
|
||||
String::new()
|
||||
};
|
||||
let _ = drawing_bytes;
|
||||
|
||||
let entry = Entry {
|
||||
id: filename.trim_end_matches(".txt").to_string(),
|
||||
meta: EntryMeta {
|
||||
|
|
@ -229,7 +227,7 @@ async fn submit(
|
|||
}
|
||||
|
||||
// Notify telegram task
|
||||
let _ = state.tx.send(entry).await;
|
||||
let _ = state.tx.send((entry, drawing_bytes)).await;
|
||||
|
||||
Html("Thanks! Your message is pending approval.".to_string())
|
||||
}
|
||||
|
|
@ -280,7 +278,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn test_app(config: Config) -> (Router, tokio::sync::mpsc::Receiver<Entry>) {
|
||||
fn test_app(config: Config) -> (Router, tokio::sync::mpsc::Receiver<(Entry, Option<Vec<u8>>)>) {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
||||
let state = Arc::new(AppState { config, tx });
|
||||
(router(state), rx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue