use std::collections::HashMap;
use chrono::Utc;
use crate::types::{ChatId, SessionState};
pub struct SessionStore {
sessions: HashMap<ChatId, SessionState>,
}
impl SessionStore {
pub fn new() -> Self {
Self {
sessions: HashMap::new(),
}
}
pub fn mark_active(&mut self, chat_id: &ChatId) {
let state = self.sessions.entry(chat_id.clone()).or_default();
state.is_active = true;
state.last_activity = Utc::now();
}
pub fn reset(&mut self, chat_id: &ChatId) {
self.sessions.remove(chat_id);
}
pub fn get(&self, chat_id: &ChatId) -> SessionState {
self.sessions
.get(chat_id)
.cloned()
.unwrap_or_else(SessionState::new)
}
}
impl Default for SessionStore {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
#[path = "tests/session_test.rs"]
mod tests;