mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-31 15:44:05 +00:00 
			
		
		
		
	Rename structures & modules
This commit is contained in:
		| @@ -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; | ||||
| pub mod user_ws_routes; | ||||
| @@ -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<Self>, msg: &str) -> Res<WsMessage> { | ||||
|         let incoming_msg: WsMessage = serde_json::from_str(&msg)?; | ||||
|     fn handle_message(&self, ctx: &mut ws::WebsocketContext<Self>, msg: &str) -> Res<UserWsMessage> { | ||||
|         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<WsSession>, msg: &WsMessage) -> Res { | ||||
| fn send_message(session: Addr<WsSession>, 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<UserID>) -> Res { | ||||
| pub fn send_message_to_users(msg: &UserWsMessage, users: &Vec<UserID>) -> Res { | ||||
|     let connections = get_ws_connections_list() | ||||
|         .lock() | ||||
|         .unwrap() | ||||
|   | ||||
| @@ -8,15 +8,15 @@ use crate::data::user_ws_request_handler::WsRequestHandler; | ||||
| pub type WsRequestProcess = Box<dyn Fn(&mut WsRequestHandler) -> Res>; | ||||
| 
 | ||||
| /// WebSocket route
 | ||||
| pub struct WsRoute { | ||||
| pub struct UserWsRoute { | ||||
|     pub route: String, | ||||
|     pub handler: WsRequestProcess, | ||||
| } | ||||
| 
 | ||||
| impl WsRoute { | ||||
|     pub fn new<H>(route: &str, handler: H) -> WsRoute | ||||
| impl UserWsRoute { | ||||
|     pub fn new<H>(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<WsRoute> { | ||||
| pub fn get_user_ws_routes() -> Vec<UserWsRoute> { | ||||
|     vec![] | ||||
| } | ||||
| 
 | ||||
| /// Search for a route
 | ||||
| pub fn find_ws_route(uri: &str) -> Option<WsRoute> { | ||||
|     get_ws_routes().into_iter().find(|r| r.route == uri) | ||||
| pub fn find_user_ws_route(uri: &str) -> Option<UserWsRoute> { | ||||
|     get_user_ws_routes().into_iter().find(|r| r.route == uri) | ||||
| } | ||||
| @@ -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; | ||||
| pub mod user_ws_message; | ||||
| @@ -5,7 +5,7 @@ | ||||
| use serde::{Deserialize, Serialize}; | ||||
| 
 | ||||
| #[derive(Clone, Serialize, Deserialize)] | ||||
| pub struct WsMessage { | ||||
| pub struct UserWsMessage { | ||||
|     pub id: Option<String>, | ||||
|     pub title: String, | ||||
|     pub data: serde_json::Value, | ||||
		Reference in New Issue
	
	Block a user