1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-09-25 22:29:45 +00:00

Can toggle incognito mode

This commit is contained in:
2021-02-05 14:24:00 +01:00
parent b25628454a
commit 35a77a729e
5 changed files with 77 additions and 23 deletions

View File

@@ -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,
})
}