Calling Logic
This commit is contained in:
parent
b9208c190e
commit
0d8890122b
4 changed files with 35 additions and 26 deletions
|
|
@ -355,22 +355,22 @@ impl CommunicationValue {
|
|||
object! {
|
||||
id: self.id.to_string(),
|
||||
type: format!("{:?}", self.comm_type),
|
||||
sender: self.sender.to_string(),
|
||||
receiver: self.receiver.to_string(),
|
||||
sender: self.sender,
|
||||
receiver: self.receiver,
|
||||
data: jdata
|
||||
}
|
||||
} else if self.sender > 0 {
|
||||
object! {
|
||||
id: self.id.to_string(),
|
||||
type: format!("{:?}", self.comm_type),
|
||||
sender: self.sender.to_string(),
|
||||
sender: self.sender,
|
||||
data: jdata
|
||||
}
|
||||
} else if self.receiver > 0 {
|
||||
object! {
|
||||
id: self.id.to_string(),
|
||||
type: format!("{:?}", self.comm_type),
|
||||
receiver: self.receiver.to_string(),
|
||||
receiver: self.receiver,
|
||||
data: jdata
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -357,9 +357,8 @@ impl ClientConnection {
|
|||
|
||||
/// Forward message to Iota
|
||||
async fn forward_to_iota(&self, cv: CommunicationValue) {
|
||||
let user_id = self.get_user_id().await;
|
||||
if let Some(rho_conn) = self.get_rho_connection().await {
|
||||
let updated_cv = cv.with_sender(user_id);
|
||||
let updated_cv = cv.with_sender(self.get_user_id().await);
|
||||
rho_conn.message_to_iota(updated_cv).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use std::{
|
|||
use tokio::sync::RwLock;
|
||||
use tokio_util::compat::Compat;
|
||||
use tungstenite::Utf8Bytes;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{rho_connection::RhoConnection, rho_manager};
|
||||
use crate::{
|
||||
|
|
@ -273,21 +272,35 @@ impl IotaConnection {
|
|||
async fn handle_forward_message(&self, cv: CommunicationValue) {
|
||||
let receiver_id = cv.get_receiver();
|
||||
let sender_id = cv.get_sender();
|
||||
if !self.get_user_ids().await.contains(&sender_id) {
|
||||
self.send_message(CommunicationValue::new(
|
||||
CommunicationType::error_invalid_user_id,
|
||||
))
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(target_rho) = rho_manager::get_rho_con_for_user(receiver_id).await {
|
||||
target_rho.message_to_iota(cv).await;
|
||||
if self.get_user_ids().await.contains(&receiver_id) {
|
||||
if let Some(target_rho) = self.get_rho_connection().await {
|
||||
target_rho.message_to_iota(cv).await;
|
||||
} else {
|
||||
let error = CommunicationValue::new(CommunicationType::error)
|
||||
.with_id(cv.get_id())
|
||||
.with_sender(cv.get_sender());
|
||||
self.send_message(error).await;
|
||||
}
|
||||
} else if self.get_user_ids().await.contains(&sender_id) {
|
||||
if let Some(target_rho) = rho_manager::get_rho_con_for_user(receiver_id).await {
|
||||
target_rho.message_to_iota(cv).await;
|
||||
} else {
|
||||
let error = CommunicationValue::new(CommunicationType::error_no_iota)
|
||||
.with_id(cv.get_id())
|
||||
.with_sender(cv.get_sender());
|
||||
self.send_message(error).await;
|
||||
}
|
||||
} else {
|
||||
let error = CommunicationValue::new(CommunicationType::error_no_iota)
|
||||
.with_id(cv.get_id())
|
||||
.with_sender(cv.get_sender());
|
||||
self.send_message(error).await;
|
||||
self.send_message(
|
||||
CommunicationValue::new(CommunicationType::error_invalid_user_id).add_data(
|
||||
DataTypes::error_type,
|
||||
JsonValue::String(
|
||||
"You are sending to another User without authority.".to_string(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,15 +126,12 @@ impl RhoConnection {
|
|||
pub async fn message_to_client(&self, cv: CommunicationValue) {
|
||||
let connections = self.client_connections.read().await;
|
||||
for connection in connections.iter() {
|
||||
connection.send_message(&cv).await;
|
||||
if connection.get_user_id().await == cv.receiver {
|
||||
connection.send_message(&cv).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Send message to Iota as string
|
||||
pub async fn message_to_iota_str(&self, message: &str) {
|
||||
self.iota_connection.send_message_str(message).await;
|
||||
}
|
||||
|
||||
/// Send message to Iota
|
||||
pub async fn message_to_iota(&self, cv: CommunicationValue) {
|
||||
self.iota_connection.send_message(cv).await;
|
||||
|
|
|
|||
Loading…
Reference in a new issue