mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Can toggle incognito mode
This commit is contained in:
@ -19,4 +19,5 @@ pub mod movies_controller;
|
||||
pub mod virtual_directory_controller;
|
||||
pub mod web_app_controller;
|
||||
pub mod calls_controller;
|
||||
pub mod user_ws_routes;
|
||||
pub mod user_ws_routes;
|
||||
pub mod user_ws_actions;
|
15
src/controllers/user_ws_actions.rs
Normal file
15
src/controllers/user_ws_actions.rs
Normal file
@ -0,0 +1,15 @@
|
||||
//! # User WebSocket actions
|
||||
//!
|
||||
//! This module contains all the base action that can be executed by the WebSocket
|
||||
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::error::Res;
|
||||
use crate::data::user_ws_request_handler::UserWsRequestHandler;
|
||||
|
||||
/// Update incognito status of the connection
|
||||
pub fn set_incognito(r: &mut UserWsRequestHandler) -> Res {
|
||||
let new_state = r.post_bool("enable")?;
|
||||
r.update_conn(|c| c.incognito = new_state)?;
|
||||
|
||||
r.success("Updated.")
|
||||
}
|
@ -23,7 +23,7 @@ use crate::data::error::{ExecError, Res, ResultBoxError};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_ws_message::UserWsMessage;
|
||||
use crate::data::user_ws_request_handler::{WsRequestHandler, WsResponseType};
|
||||
use crate::data::user_ws_request_handler::{UserWsRequestHandler, UserWsResponseType};
|
||||
use crate::utils::crypt_utils::rand_str;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
@ -106,12 +106,37 @@ mod ws_connections_list {
|
||||
use crate::controllers::user_ws_controller::WsSession;
|
||||
use crate::data::user::UserID;
|
||||
|
||||
/// This structure contains information about an active connection
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WsConnection {
|
||||
pub user_id: UserID,
|
||||
pub client_id: u32,
|
||||
pub remote_ip: String,
|
||||
pub session: actix::Addr<WsSession>,
|
||||
pub incognito: bool,
|
||||
}
|
||||
|
||||
impl WsConnection {
|
||||
/// Change some of the properties of the connection
|
||||
pub fn replace<H>(mut self, do_update: H) -> Self where H: FnOnce(&mut Self) {
|
||||
let list = get_ws_connections_list();
|
||||
let mut list = list.lock().unwrap();
|
||||
|
||||
for i in 0..list.len() {
|
||||
if !list[i].session.eq(&self.session) {
|
||||
continue;
|
||||
}
|
||||
|
||||
do_update(&mut self);
|
||||
list[i] = self.clone();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
drop(list);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
@ -176,6 +201,8 @@ pub fn get_token(r: &mut HttpRequestHandler) -> ResultBoxError {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WsSession {
|
||||
// NOTE : apart from hb, the values here won't change !
|
||||
|
||||
user_id: UserID,
|
||||
|
||||
// Client used for the connection
|
||||
@ -231,7 +258,7 @@ impl WsSession {
|
||||
});
|
||||
}
|
||||
|
||||
let mut handler = WsRequestHandler::new(
|
||||
let mut handler = UserWsRequestHandler::new(
|
||||
&find_connection(ctx.address()).ok_or(ExecError::boxed_new("Connection not found!"))?,
|
||||
args,
|
||||
);
|
||||
@ -260,8 +287,8 @@ impl WsSession {
|
||||
Ok(UserWsMessage {
|
||||
id: incoming_msg.id,
|
||||
title: match response.r#type {
|
||||
WsResponseType::SUCCESS => "success".to_string(),
|
||||
WsResponseType::ERROR => "error".to_string(),
|
||||
UserWsResponseType::SUCCESS => "success".to_string(),
|
||||
UserWsResponseType::ERROR => "error".to_string(),
|
||||
},
|
||||
data: response.content,
|
||||
})
|
||||
@ -281,6 +308,7 @@ impl Actor for WsSession {
|
||||
client_id: self.client_id,
|
||||
remote_ip: self.remote_ip.clone(),
|
||||
session: ctx.address(),
|
||||
incognito: self.incognito,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::controllers::likes_controller;
|
||||
use crate::controllers::{likes_controller, user_ws_actions};
|
||||
use crate::data::error::Res;
|
||||
use crate::data::user_ws_request_handler::WsRequestHandler;
|
||||
use crate::data::user_ws_request_handler::UserWsRequestHandler;
|
||||
|
||||
pub type WsRequestProcess = Box<dyn Fn(&mut WsRequestHandler) -> Res>;
|
||||
pub type WsRequestProcess = Box<dyn Fn(&mut UserWsRequestHandler) -> Res>;
|
||||
|
||||
/// WebSocket route
|
||||
pub struct UserWsRoute {
|
||||
@ -16,7 +16,7 @@ pub struct UserWsRoute {
|
||||
|
||||
impl UserWsRoute {
|
||||
pub fn new<H>(route: &str, handler: H) -> UserWsRoute
|
||||
where H: 'static + Fn(&mut WsRequestHandler) -> Res {
|
||||
where H: 'static + Fn(&mut UserWsRequestHandler) -> Res {
|
||||
UserWsRoute {
|
||||
route: route.to_string(),
|
||||
handler: Box::new(handler),
|
||||
@ -27,6 +27,9 @@ impl UserWsRoute {
|
||||
/// Get the list of available WebSocket routes
|
||||
pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
|
||||
vec![
|
||||
// Main controller
|
||||
UserWsRoute::new("$main/set_incognito", user_ws_actions::set_incognito),
|
||||
|
||||
// Likes controller
|
||||
UserWsRoute::new("likes/update", likes_controller::update)
|
||||
]
|
||||
|
Reference in New Issue
Block a user