[Add] Structure
This commit is contained in:
parent
a642afce5a
commit
c363ea48d0
27 changed files with 1730 additions and 1400 deletions
25
src/services/routing_service.rs
Normal file
25
src/services/routing_service.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use mtp::codec::CommunicationValue;
|
||||
|
||||
use crate::{app_state::AppState, rho::rho_connection::RhoConnection};
|
||||
|
||||
pub struct RoutingService {
|
||||
state: Arc<AppState>,
|
||||
}
|
||||
|
||||
impl RoutingService {
|
||||
pub fn new(state: Arc<AppState>) -> Self {
|
||||
Self { state }
|
||||
}
|
||||
|
||||
pub async fn route_to_user(&self, user_id: i64, message: CommunicationValue) {
|
||||
if let Some(connection) = self.state.rho.get_for_user(user_id).await {
|
||||
connection.message_to_iota(message).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn connection_for_user(&self, user_id: i64) -> Option<Arc<RhoConnection>> {
|
||||
self.state.rho.get_for_user(user_id).await
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue