This commit is contained in:
Alex Emmet 2026-01-29 12:11:00 +01:00
commit 0990ccd526
16 changed files with 139 additions and 393 deletions

View file

@ -20,10 +20,9 @@ use crate::util::crypto_helper::{load_public_key, public_key_to_base64};
use crate::util::crypto_util::{DataFormat, SecurePayload};
use crate::util::logger::PrintType;
use crate::{
// calls::call_manager::CallManager,
data::{
communication::{CommunicationType, CommunicationValue, DataTypes},
user::{User, UserStatus},
user::UserStatus,
},
omega::omega_connection::OmegaConnection,
};
@ -163,7 +162,7 @@ impl ClientConnection {
let pub_key = match load_public_key(base64_pub) {
Some(pk) => pk,
None => {
_ => {
self.clone()
.send_error_response(
&cv.get_id(),
@ -227,7 +226,7 @@ impl ClientConnection {
let rho_connection = match rho_manager::get_rho_con_for_user(user_id).await {
Some(rho) => rho,
None => {
_ => {
self.send_error_response(
&cv.get_id(),
CommunicationType::error_no_iota,
@ -432,7 +431,7 @@ impl ClientConnection {
return;
}
},
None => {
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error_no_call_id)
.await;
return;
@ -450,7 +449,7 @@ impl ClientConnection {
// Find target RhoConnection
let target_rho = match rho_manager::get_rho_con_for_user(receiver_id).await {
Some(rho) => rho,
None => {
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
.await;
return;
@ -487,7 +486,7 @@ impl ClientConnection {
return;
}
},
None => {
_ => {
self.send_error_response(&cv.get_id(), CommunicationType::error)
.await;
return;
@ -697,15 +696,12 @@ impl ClientConnection {
}
/// Check if interested in a user and send notification
pub async fn are_you_interested(self: Arc<Self>, user: &User) {
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
let interested_guard = self.clone().get_interested_users().await;
if interested_guard.contains(&user.user_id) {
if interested_guard.contains(&user_id) {
let notification = CommunicationValue::new(CommunicationType::client_changed)
.add_data_str(DataTypes::user_id, user.user_id.to_string())
.add_data_str(
DataTypes::user_state,
format!("{:?}", user.status.to_string()),
);
.add_data_str(DataTypes::user_id, user_id.to_string())
.add_data_str(DataTypes::user_state, format!("online"));
self.send_message(&notification).await;
}

View file

@ -189,7 +189,7 @@ impl IotaConnection {
let pub_key = match load_public_key(base64_pub) {
Some(pk) => pk,
None => {
_ => {
self.send_error_response(
&cv.get_id(),
CommunicationType::error_invalid_public_key,
@ -594,6 +594,7 @@ impl IotaConnection {
}
}
}
pub async fn await_response(
&self,
cv: &CommunicationValue,
@ -626,7 +627,7 @@ impl IotaConnection {
match tokio::time::timeout(timeout, rx.recv()).await {
Ok(Some(response_cv)) => Ok(response_cv),
Ok(None) => Err("Failed to receive response, channel was closed.".to_string()),
Ok(_) => Err("Failed to receive response, channel was closed.".to_string()),
Err(_) => {
self.waiting_tasks.remove(&msg_id);
Err(format!(

View file

@ -147,10 +147,10 @@ impl RhoConnection {
}
/// Check if clients are interested in a user
pub async fn are_they_interested(&self, user: &crate::data::user::User) {
pub async fn are_they_interested(&self, user_id: i64) {
let connections = self.client_connections.read().await;
for connection in connections.iter() {
connection.clone().are_you_interested(user).await;
connection.clone().are_you_interested(user_id).await;
}
}

View file

@ -50,12 +50,6 @@ pub async fn get_rho_by_iota(iota_id: i64) -> Option<Arc<RhoConnection>> {
connections.get(&iota_id).map(Arc::clone)
}
/// Get all active RhoConnections
pub async fn get_all_connections() -> Vec<Arc<RhoConnection>> {
let connections = RHO_CONNECTIONS.read().await;
connections.values().map(Arc::clone).collect()
}
/// Get the count of active connections
pub async fn connection_count() -> usize {
let connections = RHO_CONNECTIONS.read().await;