From 05006980f7d6107b9b26ec6bcfbb64dad2c9f1ea Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Fri, 27 Mar 2026 00:26:37 +0100 Subject: [PATCH] [Fix] Add chats, propper rho selection --- Cargo.lock | 8 ++++---- src/omega/omega_connection.rs | 23 ++++++++++++++++++++++- src/rho/client_connection.rs | 2 +- src/rho/connection.rs | 17 ++++++++--------- src/rho/iota_connection.rs | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d195ce0..2345c15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -438,9 +438,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" dependencies = [ "cc", ] @@ -3131,7 +3131,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "ttp-core" version = "0.1.0" -source = "git+https://github.com/Tensamin/TTP.git#c127d196082401f37b51ca5417b341ecbdb74318" +source = "git+https://github.com/Tensamin/TTP.git#9c0ed7a5b6c8735e4b674d4503bd7b936ee3656b" dependencies = [ "base64 0.22.1", "byteorder", @@ -3143,7 +3143,7 @@ dependencies = [ [[package]] name = "ttp-native" version = "0.1.0" -source = "git+https://github.com/Tensamin/TTP.git#c127d196082401f37b51ca5417b341ecbdb74318" +source = "git+https://github.com/Tensamin/TTP.git#9c0ed7a5b6c8735e4b674d4503bd7b936ee3656b" dependencies = [ "quinn", "rustls", diff --git a/src/omega/omega_connection.rs b/src/omega/omega_connection.rs index e4cfa0f..ab84eb2 100644 --- a/src/omega/omega_connection.rs +++ b/src/omega/omega_connection.rs @@ -469,10 +469,31 @@ impl OmegaConnection { let msg_id = cv.get_id(); if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) { - if (task.task)(self.clone(), cv) { + if (task.task)(self.clone(), cv.clone()) { continue; } } + + if cv.is_type(CommunicationType::iota_user_data) { + if let DataValue::Array(users) = cv.get_data(DataTypes::user_ids) { + let mut user_ids: Vec = Vec::new(); + for value in users { + if let DataValue::Number(user_id) = value { + user_ids.push(*user_id as u64); + } + } + let connections = crate::rho::rho_manager::RHO_CONNECTIONS.read().await; + if let Some(iota_id) = cv.get_data(DataTypes::iota_id).as_number() { + if let Some(rho) = connections.get(&iota_id) { + rho.get_iota_connection().set_user_ids(user_ids).await; + } + } else { + for rho in connections.values() { + rho.get_iota_connection().set_user_ids(user_ids.clone()).await; + } + } + } + } } Err(e) => { log_err!(0, PrintType::Omega, "Receive error: {}", e); diff --git a/src/rho/client_connection.rs b/src/rho/client_connection.rs index ad3fc63..e2dca8c 100644 --- a/src/rho/client_connection.rs +++ b/src/rho/client_connection.rs @@ -412,7 +412,7 @@ impl ClientConnection { && cv .get_data(DataTypes::chat_partner_id) .as_number() - .is_some() + .is_none() { let chat_partner_name = cv .get_data(DataTypes::chat_partner_name) diff --git a/src/rho/connection.rs b/src/rho/connection.rs index a676321..2d09b85 100755 --- a/src/rho/connection.rs +++ b/src/rho/connection.rs @@ -270,6 +270,9 @@ impl GeneralConnection { let user_id = id as i64; + let client = ClientConnection::from_general(self.clone(), id).await; + client.clone().start(); + let mut rho = rho_manager::get_rho_con_for_user(user_id).await; if rho.is_none() { @@ -295,12 +298,10 @@ impl GeneralConnection { *self.rho_connection.write().await = rho.clone(); - let client = ClientConnection::from_general(self.clone(), id).await; - if let Some(rho_conn) = rho { // Make sure user is bound before the client starts forwarding rho_conn.bind_user_id(user_id).await; - rho_conn.add_client_connection(client.clone()).await; + rho_conn.add_client_connection(client).await; } else { log_err!( user_id, @@ -309,8 +310,6 @@ impl GeneralConnection { id ); } - - client.start(); } ConnectionKind::Iota => { let notify = CommunicationValue::new(CommunicationType::iota_connected) @@ -323,6 +322,10 @@ impl GeneralConnection { iota.set_rho_connection(rho.clone()).await; + rho_manager::add_rho(rho).await; + + iota.clone().start(); + let get_iota_msg = CommunicationValue::new(CommunicationType::get_iota_data) .add_data(DataTypes::iota_id, DataValue::Number(id as i64)); @@ -340,10 +343,6 @@ impl GeneralConnection { iota.set_user_ids(user_ids).await; } } - - rho_manager::add_rho(rho).await; - - iota.start(); } ConnectionKind::AnonymousClient => { let client = AnonymousClientConnection::from_general(self.clone(), id).await; diff --git a/src/rho/iota_connection.rs b/src/rho/iota_connection.rs index a52f8a2..9d4df3e 100755 --- a/src/rho/iota_connection.rs +++ b/src/rho/iota_connection.rs @@ -94,7 +94,7 @@ impl IotaConnection { if let Some(rho_conn) = self.get_rho_connection().await { let user_ids_i64: Vec = user_ids.into_iter().map(|u| u as i64).collect(); - rho_conn.set_user_ids(user_ids_i64); + rho_conn.set_user_ids(user_ids_i64).await; } }