From 770d7671065f0a86932079a25bc6b248c2d67809 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:09:59 -0500 Subject: [PATCH] refactor: move WsId out from loaded settings --- crates/plugin-chat/src/server_only.rs | 2 +- crates/plugin-chat/src/server_only/plugin_impl.rs | 15 ++++++++++++--- crates/plugin-chat/src/server_only/server.rs | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/plugin-chat/src/server_only.rs b/crates/plugin-chat/src/server_only.rs index 6247eb1..4aaa70d 100644 --- a/crates/plugin-chat/src/server_only.rs +++ b/crates/plugin-chat/src/server_only.rs @@ -5,4 +5,4 @@ mod plugin_impl; mod server; pub use connections::{chat_get_token, chat_ws_start_session}; -pub use plugin_impl::{ChatPlugin, ChatSettings}; +pub use plugin_impl::{ChatPlugin, ChatPluginConfig, ChatSettings}; diff --git a/crates/plugin-chat/src/server_only/plugin_impl.rs b/crates/plugin-chat/src/server_only/plugin_impl.rs index 5a069bc..427a766 100644 --- a/crates/plugin-chat/src/server_only/plugin_impl.rs +++ b/crates/plugin-chat/src/server_only/plugin_impl.rs @@ -9,13 +9,17 @@ use super::server::{ChatServer, ChatServerHandle}; #[derive(serde::Deserialize, Clone)] pub struct ChatSettings { pub heartbeat_interval_secs: u8, +} + +pub struct ChatPluginConfig { pub ws_id: WsId, + pub settings: ChatSettings, } pub struct ChatPlugin; impl ServerPlugin for ChatPlugin { - type Config = ChatSettings; + type Config = ChatPluginConfig; type Task = ChatServer; @@ -28,8 +32,13 @@ impl ServerPlugin for ChatPlugin { ws_config: &wykies_server::WebSocketSettings, ) -> anyhow::Result> { - let (chat_server, chat_server_handle) = - ChatServer::new(config, ws_config, db_pool, cancellation_token); + let (chat_server, chat_server_handle) = ChatServer::new( + &config.settings, + config.ws_id, + ws_config, + db_pool, + cancellation_token, + ); Ok(ServerPluginArtifacts { task: chat_server, handle: Arc::new(chat_server_handle), diff --git a/crates/plugin-chat/src/server_only/server.rs b/crates/plugin-chat/src/server_only/server.rs index 609d0f8..72007e8 100644 --- a/crates/plugin-chat/src/server_only/server.rs +++ b/crates/plugin-chat/src/server_only/server.rs @@ -70,6 +70,7 @@ pub struct ChatServerHandle { impl ChatServer { pub fn new( config: &ChatSettings, + ws_id: WsId, ws_config: &WebSocketSettings, db_pool: DbPool, cancellation_token: TrackedCancellationToken, @@ -97,7 +98,7 @@ impl ChatServer { ChatServerHandle { cmd_tx, heartbeat_config, - ws_id: config.ws_id, + ws_id, }, ) }