use serde::Deserialize; #[derive(Clone, Debug, Deserialize)] #[serde(default)] pub struct ChatWsConfig { pub ticket_ttl_secs: u64, pub heartbeat_secs: u64, pub max_subscriptions: usize, pub max_frame_bytes: usize, pub history_limit: u64, } impl Default for ChatWsConfig { fn default() -> Self { Self { ticket_ttl_secs: 60, heartbeat_secs: 30, max_subscriptions: 64, max_frame_bytes: 262_144, history_limit: 200, } } } #[derive(Clone, Debug, Deserialize)] #[serde(default)] pub struct ChatUploadConfig { pub max_size: i64, pub presign_ttl_secs: u64, } impl Default for ChatUploadConfig { fn default() -> Self { Self { max_size: 104_857_600, presign_ttl_secs: 3600, } } } #[derive(Clone, Debug, Deserialize)] #[serde(default)] pub struct ChatConfig { pub max_pagination: u64, pub default_pagination: u64, pub max_message_len: usize, pub max_topic_len: usize, pub max_thread_name_len: usize, pub max_reaction_emoji_len: usize, pub max_emoji_name_len: usize, pub max_bookmark_title_len: usize, pub max_webhook_name_len: usize, pub max_mentions_per_message: usize, pub max_attachments_per_message: usize, pub max_members_per_add: usize, pub max_pending_attachments_per_user: i64, pub typing_ttl_secs: u64, pub presence_ttl_secs: u64, pub ws: ChatWsConfig, pub upload: ChatUploadConfig, } impl Default for ChatConfig { fn default() -> Self { Self { max_pagination: 200, default_pagination: 50, max_message_len: 4000, max_topic_len: 1024, max_thread_name_len: 255, max_reaction_emoji_len: 64, max_emoji_name_len: 64, max_bookmark_title_len: 255, max_webhook_name_len: 100, max_mentions_per_message: 20, max_attachments_per_message: 10, max_members_per_add: 50, max_pending_attachments_per_user: 200, typing_ttl_secs: 5, presence_ttl_secs: 300, ws: ChatWsConfig::default(), upload: ChatUploadConfig::default(), } } } impl ChatConfig { pub fn is_valid(&self) -> Result<(), String> { if self.max_pagination == 0 || self.default_pagination == 0 { return Err("chat pagination must be positive".to_string()); } if self.max_message_len == 0 { return Err("chat max_message_len must be positive".to_string()); } if self.ws.ticket_ttl_secs == 0 { return Err("chat ws ticket_ttl_secs must be positive".to_string()); } Ok(()) } }