Forum: e-mail notifications with a daily digest

Members choose per kind: replies to them (daily digest, instant or off),
new posts in followed threads (daily or off), private messages and
requests (instant or off). The forum service queues the instant e-mails
(none while online, at most one per thread an hour); the worker's new
forum task makes the evening digest of what is unread. Every forum e-mail
greets by the nickname and has a one-click unsubscribe (RFC 8058).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 10:59:29 +00:00
co-authored by Claude Opus 5.5
parent 4def9569b1
commit 7c768fccff
22 changed files with 938 additions and 27 deletions
+9 -4
View File
@@ -5,13 +5,15 @@
//! the database and the login: a session of the backend (`sf_session` cookie
//! or `Authorization: Bearer`) is valid here too.
//!
//! Configuration: `DATABASE_URL`; `BIND_ADDR` (default `0.0.0.0:8083`),
//! Configuration: `DATABASE_URL`, `PUBLIC_BASE_URL` (the site, for e-mail
//! links; default `http://localhost:3001`); `BIND_ADDR` (default `0.0.0.0:8083`),
//! `LOG_FORMAT`, `RUST_LOG`, `LOG_DIR`. Database migrations run at startup.
//!
//! `forum healthcheck` performs a local health check (for Docker).
mod auth;
mod error;
mod mail;
mod rank;
mod routes;
#[cfg(test)]
@@ -29,11 +31,13 @@ pub struct AppState {
pub db: PgPool,
/// Seconds a member waits between two posts (0 in the tests).
pub flood_secs: i32,
/// The site's address, for the links in e-mails (`PUBLIC_BASE_URL`).
pub base_url: String,
}
impl AppState {
pub fn new(db: PgPool) -> Self {
Self { db, flood_secs: 5 }
pub fn new(db: PgPool, base_url: String) -> Self {
Self { db, flood_secs: 5, base_url: base_url.trim_end_matches('/').to_string() }
}
}
@@ -47,7 +51,8 @@ async fn main() -> anyhow::Result<()> {
let url = std::env::var("DATABASE_URL").context("DATABASE_URL is not set")?;
let pool = db::connect(&url).await.context("connecting to the database")?;
db::migrate(&pool).await.context("running database migrations")?;
let app = routes::router(Arc::new(AppState::new(pool)));
let base_url = std::env::var("PUBLIC_BASE_URL").unwrap_or_else(|_| "http://localhost:3001".into());
let app = routes::router(Arc::new(AppState::new(pool, base_url)));
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;
tracing::info!(%addr, "listening");
axum::serve(listener, app).with_graceful_shutdown(service_kit::shutdown_signal()).await?;