From 15f8df238627fca8c2acddef8ffe3297d46aebf5 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 5 Feb 2021 13:25:27 +0100 Subject: [PATCH] Rename structures & modules --- src/controllers/mod.rs | 2 +- src/controllers/user_ws_controller.rs | 16 ++++++++-------- .../{ws_routes.rs => user_ws_routes.rs} | 14 +++++++------- src/data/mod.rs | 2 +- src/data/{ws_message.rs => user_ws_message.rs} | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) rename src/controllers/{ws_routes.rs => user_ws_routes.rs} (64%) rename src/data/{ws_message.rs => user_ws_message.rs} (89%) diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index e3696f5..02bde37 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -19,4 +19,4 @@ pub mod movies_controller; pub mod virtual_directory_controller; pub mod web_app_controller; pub mod calls_controller; -pub mod ws_routes; \ No newline at end of file +pub mod user_ws_routes; \ No newline at end of file diff --git a/src/controllers/user_ws_controller.rs b/src/controllers/user_ws_controller.rs index 26d1be3..7503973 100644 --- a/src/controllers/user_ws_controller.rs +++ b/src/controllers/user_ws_controller.rs @@ -15,14 +15,14 @@ use crate::api_data::res_get_ws_token::ResGetWsToken; use crate::constants::WS_ACCESS_TOKEN_LENGTH; use crate::controllers::user_ws_controller::ws_connections_list::{add_connection, find_connection, get_ws_connections_list, remove_connection}; pub use crate::controllers::user_ws_controller::ws_connections_list::WsConnection; -use crate::controllers::ws_routes::find_ws_route; +use crate::controllers::user_ws_routes::find_user_ws_route; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::config::conf; use crate::data::error::{ExecError, Res, ResultBoxError}; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::user::UserID; use crate::data::user_ws_request_handler::{WsRequestHandler, WsResponseType}; -use crate::data::ws_message::WsMessage; +use crate::data::user_ws_message::UserWsMessage; use crate::utils::crypt_utils::rand_str; use crate::utils::date_utils::time; @@ -212,8 +212,8 @@ impl WsSession { } /// Handle incoming message - fn handle_message(&self, ctx: &mut ws::WebsocketContext, msg: &str) -> Res { - let incoming_msg: WsMessage = serde_json::from_str(&msg)?; + fn handle_message(&self, ctx: &mut ws::WebsocketContext, msg: &str) -> Res { + let incoming_msg: UserWsMessage = serde_json::from_str(&msg)?; let data = incoming_msg.data.as_object() .ok_or(ExecError::boxed_new("Could not parse values!"))?; @@ -234,7 +234,7 @@ impl WsSession { args, ); - let result = match find_ws_route(&incoming_msg.title) { + let result = match find_user_ws_route(&incoming_msg.title) { None => { handler.not_found("Route not found!".to_string()) } @@ -255,7 +255,7 @@ impl WsSession { let response = handler.response(); - Ok(WsMessage { + Ok(UserWsMessage { id: incoming_msg.id, title: match response.r#type { WsResponseType::SUCCESS => "success".to_string(), @@ -407,13 +407,13 @@ pub async fn ws_route( } /// Send a message to a specific connection -fn send_message(session: Addr, msg: &WsMessage) -> Res { +fn send_message(session: Addr, msg: &UserWsMessage) -> Res { session.do_send(WsQueuedMessage(serde_json::to_string(msg)?)); Ok(()) } /// Send a message to specific users -pub fn send_message_to_users(msg: &WsMessage, users: &Vec) -> Res { +pub fn send_message_to_users(msg: &UserWsMessage, users: &Vec) -> Res { let connections = get_ws_connections_list() .lock() .unwrap() diff --git a/src/controllers/ws_routes.rs b/src/controllers/user_ws_routes.rs similarity index 64% rename from src/controllers/ws_routes.rs rename to src/controllers/user_ws_routes.rs index 2f887e1..f0fff53 100644 --- a/src/controllers/ws_routes.rs +++ b/src/controllers/user_ws_routes.rs @@ -8,15 +8,15 @@ use crate::data::user_ws_request_handler::WsRequestHandler; pub type WsRequestProcess = Box Res>; /// WebSocket route -pub struct WsRoute { +pub struct UserWsRoute { pub route: String, pub handler: WsRequestProcess, } -impl WsRoute { - pub fn new(route: &str, handler: H) -> WsRoute +impl UserWsRoute { + pub fn new(route: &str, handler: H) -> UserWsRoute where H: 'static + Fn(&mut WsRequestHandler) -> Res { - WsRoute { + UserWsRoute { route: route.to_string(), handler: Box::new(handler), } @@ -24,11 +24,11 @@ impl WsRoute { } /// Get the list of available WebSocket routes -pub fn get_ws_routes() -> Vec { +pub fn get_user_ws_routes() -> Vec { vec![] } /// Search for a route -pub fn find_ws_route(uri: &str) -> Option { - get_ws_routes().into_iter().find(|r| r.route == uri) +pub fn find_user_ws_route(uri: &str) -> Option { + get_user_ws_routes().into_iter().find(|r| r.route == uri) } \ No newline at end of file diff --git a/src/data/mod.rs b/src/data/mod.rs index dfd8178..1385e28 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -36,4 +36,4 @@ pub mod general_settings; pub mod lang_settings; pub mod security_settings; pub mod new_custom_emoji; -pub mod ws_message; \ No newline at end of file +pub mod user_ws_message; \ No newline at end of file diff --git a/src/data/ws_message.rs b/src/data/user_ws_message.rs similarity index 89% rename from src/data/ws_message.rs rename to src/data/user_ws_message.rs index 47a81ee..01c1147 100644 --- a/src/data/ws_message.rs +++ b/src/data/user_ws_message.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Serialize, Deserialize)] -pub struct WsMessage { +pub struct UserWsMessage { pub id: Option, pub title: String, pub data: serde_json::Value,