[Feat] load anonymous user data

This commit is contained in:
Alex Emmet 2026-01-21 14:02:04 +01:00
commit 163e789379
4 changed files with 72 additions and 1 deletions

View file

@ -71,6 +71,10 @@ impl AnonymousClientConnection {
self.display_name.read().await.clone() self.display_name.read().await.clone()
} }
pub async fn set_display_name(&self, display: String) {
*self.display_name.write().await = display;
}
/// Get the avatar /// Get the avatar
pub async fn get_avatar(&self) -> String { pub async fn get_avatar(&self) -> String {
self.avatar.read().await.clone() self.avatar.read().await.clone()
@ -260,7 +264,14 @@ impl AnonymousClientConnection {
} }
if cv.is_type(CommunicationType::change_user_data) { if cv.is_type(CommunicationType::change_user_data) {
// TODO if let Some(display_name) = cv
.get_data(DataTypes::display)
.unwrap_or(&JsonValue::Null)
.as_str()
{
let _ = self.set_display_name(display_name.to_string()).await;
}
return; return;
} }

View file

@ -19,3 +19,18 @@ pub async fn remove_anonymous_user(user_id: i64) {
pub async fn get_anonymous_user(user_id: i64) -> Option<Arc<AnonymousClientConnection>> { pub async fn get_anonymous_user(user_id: i64) -> Option<Arc<AnonymousClientConnection>> {
ANONYMOUS_USERS.get(&user_id).map(|c| c.clone()) ANONYMOUS_USERS.get(&user_id).map(|c| c.clone())
} }
pub async fn get_anonymous_user_by_name(
username: String,
) -> Option<Arc<AnonymousClientConnection>> {
for user_conn in ANONYMOUS_USERS
.iter()
.map(|ref_multi| ref_multi.value().clone())
{
if user_conn.get_user_name().await == username {
return Some(user_conn);
}
}
return None;
}

View file

@ -112,6 +112,7 @@ impl DataTypes {
#[allow(non_camel_case_types, dead_code)] #[allow(non_camel_case_types, dead_code)]
pub enum CommunicationType { pub enum CommunicationType {
error, error,
error_anonymous,
error_internal, error_internal,
error_invalid_data, error_invalid_data,
error_invalid_user_id, error_invalid_user_id,

View file

@ -13,6 +13,7 @@ use tungstenite::Utf8Bytes;
use uuid::Uuid; use uuid::Uuid;
use super::{rho_connection::RhoConnection, rho_manager}; use super::{rho_connection::RhoConnection, rho_manager};
use crate::anonymous_clients::anonymous_manager;
use crate::calls::call_manager; use crate::calls::call_manager;
use crate::omega::omega_connection::{WAITING_TASKS, get_omega_connection}; use crate::omega::omega_connection::{WAITING_TASKS, get_omega_connection};
use crate::util::crypto_helper::{load_public_key, public_key_to_base64}; use crate::util::crypto_helper::{load_public_key, public_key_to_base64};
@ -305,6 +306,40 @@ impl ClientConnection {
self.handle_call_set_anonymous_joining(cv).await; self.handle_call_set_anonymous_joining(cv).await;
return; return;
} }
if cv.is_type(CommunicationType::get_user_data) {
if let Some(anonymous) = {
if let Some(user_id) = cv
.get_data(DataTypes::user_id)
.unwrap_or(&JsonValue::Null)
.as_i64()
{
anonymous_manager::get_anonymous_user(user_id).await
} else if let Some(username) = cv
.get_data(DataTypes::username)
.unwrap_or(&JsonValue::Null)
.as_str()
{
anonymous_manager::get_anonymous_user_by_name(username.to_string()).await
} else {
None
}
} {
let response = CommunicationValue::new(CommunicationType::get_user_data)
.with_id(cv.get_id())
.add_data_str(DataTypes::username, anonymous.get_user_name().await)
.add_data(
DataTypes::user_id,
JsonValue::Number(Number::from(anonymous.get_user_id().await)),
)
.add_data_str(DataTypes::display, anonymous.get_display_name().await)
.add_data_str(DataTypes::user_state, "online".to_string())
.add_data_str(DataTypes::avatar, anonymous.get_avatar().await);
self.send_message(&response).await;
return;
}
}
if cv.is_type(CommunicationType::change_user_data) if cv.is_type(CommunicationType::change_user_data)
|| cv.is_type(CommunicationType::get_user_data) || cv.is_type(CommunicationType::get_user_data)
@ -583,6 +618,15 @@ impl ClientConnection {
.unwrap_or("") .unwrap_or("")
.to_string(); .to_string();
if anonymous_manager::get_anonymous_user_by_name(chat_partner_name.to_string())
.await
.is_some()
{
self.send_error_response(&cv.get_id(), CommunicationType::error_anonymous)
.await;
return;
}
let load_uuid_response = get_omega_connection() let load_uuid_response = get_omega_connection()
.await_response( .await_response(
&CommunicationValue::new(CommunicationType::get_user_data) &CommunicationValue::new(CommunicationType::get_user_data)