auth middleware + message history

This commit is contained in:
2025-06-08 21:29:06 +02:00
parent 4f03cde9b5
commit 368ae7209c
12 changed files with 888 additions and 57 deletions

View File

@@ -1,22 +1,19 @@
use std::sync::Arc;
use tokio::sync::{Mutex, broadcast::Sender};
use sqlx::{Pool, Postgres};
use tokio::sync::broadcast::Sender;
use crate::message::ChatMessage;
#[derive(Debug, Clone)]
pub struct AppState {
pub messages: Arc<Mutex<Vec<ChatMessage>>>,
pub next_client_id: Arc<Mutex<u32>>,
pub broadcast_sender: Sender<ChatMessage>,
pub pg_pool: Pool<Postgres>,
}
impl AppState {
pub fn new(websocket_sender: Sender<ChatMessage>) -> Self {
pub fn new(websocket_sender: Sender<ChatMessage>, pool: Pool<Postgres>) -> Self {
Self {
messages: Arc::default(),
next_client_id: Arc::default(),
broadcast_sender: websocket_sender,
pg_pool: pool,
}
}
}