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! {
|
object! {
|
||||||
id: self.id.to_string(),
|
id: self.id.to_string(),
|
||||||
type: format!("{:?}", self.comm_type),
|
type: format!("{:?}", self.comm_type),
|
||||||
sender: self.sender.to_string(),
|
sender: self.sender,
|
||||||
receiver: self.receiver.to_string(),
|
receiver: self.receiver,
|
||||||
data: jdata
|
data: jdata
|
||||||
}
|
}
|
||||||
} else if self.sender > 0 {
|
} else if self.sender > 0 {
|
||||||
object! {
|
object! {
|
||||||
id: self.id.to_string(),
|
id: self.id.to_string(),
|
||||||
type: format!("{:?}", self.comm_type),
|
type: format!("{:?}", self.comm_type),
|
||||||
sender: self.sender.to_string(),
|
sender: self.sender,
|
||||||
data: jdata
|
data: jdata
|
||||||
}
|
}
|
||||||
} else if self.receiver > 0 {
|
} else if self.receiver > 0 {
|
||||||
object! {
|
object! {
|
||||||
id: self.id.to_string(),
|
id: self.id.to_string(),
|
||||||
type: format!("{:?}", self.comm_type),
|
type: format!("{:?}", self.comm_type),
|
||||||
receiver: self.receiver.to_string(),
|
receiver: self.receiver,
|
||||||
data: jdata
|
data: jdata
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -357,9 +357,8 @@ impl ClientConnection {
|
||||||
|
|
||||||
/// Forward message to Iota
|
/// Forward message to Iota
|
||||||
async fn forward_to_iota(&self, cv: CommunicationValue) {
|
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 {
|
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;
|
rho_conn.message_to_iota(updated_cv).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ use std::{
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio_util::compat::Compat;
|
use tokio_util::compat::Compat;
|
||||||
use tungstenite::Utf8Bytes;
|
use tungstenite::Utf8Bytes;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::{rho_connection::RhoConnection, rho_manager};
|
use super::{rho_connection::RhoConnection, rho_manager};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -273,21 +272,35 @@ impl IotaConnection {
|
||||||
async fn handle_forward_message(&self, cv: CommunicationValue) {
|
async fn handle_forward_message(&self, cv: CommunicationValue) {
|
||||||
let receiver_id = cv.get_receiver();
|
let receiver_id = cv.get_receiver();
|
||||||
let sender_id = cv.get_sender();
|
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 {
|
if self.get_user_ids().await.contains(&receiver_id) {
|
||||||
target_rho.message_to_iota(cv).await;
|
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 {
|
} else {
|
||||||
let error = CommunicationValue::new(CommunicationType::error_no_iota)
|
self.send_message(
|
||||||
.with_id(cv.get_id())
|
CommunicationValue::new(CommunicationType::error_invalid_user_id).add_data(
|
||||||
.with_sender(cv.get_sender());
|
DataTypes::error_type,
|
||||||
self.send_message(error).await;
|
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) {
|
pub async fn message_to_client(&self, cv: CommunicationValue) {
|
||||||
let connections = self.client_connections.read().await;
|
let connections = self.client_connections.read().await;
|
||||||
for connection in connections.iter() {
|
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
|
/// Send message to Iota
|
||||||
pub async fn message_to_iota(&self, cv: CommunicationValue) {
|
pub async fn message_to_iota(&self, cv: CommunicationValue) {
|
||||||
self.iota_connection.send_message(cv).await;
|
self.iota_connection.send_message(cv).await;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue