Start Matrix client authentication

This commit is contained in:
2025-11-05 16:30:06 +01:00
parent a44327ddb0
commit 3dab9f41d2
13 changed files with 2960 additions and 10 deletions

View File

@@ -0,0 +1,62 @@
use crate::matrix_connection::matrix_client::MatrixClient;
use crate::users::UserEmail;
use ractor::{Actor, ActorProcessingErr, ActorRef, RpcReplyPort};
use std::collections::HashMap;
pub struct MatrixManagerState {
pub clients: HashMap<UserEmail, MatrixClient>,
}
pub enum MatrixManagerMsg {
GetClient(UserEmail, RpcReplyPort<anyhow::Result<MatrixClient>>),
}
pub struct MatrixManagerActor;
impl Actor for MatrixManagerActor {
type Msg = MatrixManagerMsg;
type State = MatrixManagerState;
type Arguments = ();
async fn pre_start(
&self,
_myself: ActorRef<Self::Msg>,
_args: Self::Arguments,
) -> Result<Self::State, ActorProcessingErr> {
Ok(MatrixManagerState {
clients: HashMap::new(),
})
}
async fn handle(
&self,
_myself: ActorRef<Self::Msg>,
message: Self::Msg,
state: &mut Self::State,
) -> Result<(), ActorProcessingErr> {
match message {
// Get client information
MatrixManagerMsg::GetClient(email, port) => {
let res = port.send(match state.clients.get(&email) {
None => {
// Generate client if required
log::info!("Building new client for {:?}", &email);
match MatrixClient::build_client(&email).await {
Ok(c) => {
state.clients.insert(email.clone(), c.clone());
Ok(c)
}
Err(e) => Err(e),
}
}
Some(c) => Ok(c.clone()),
});
if let Err(e) = res {
log::warn!("Failed to send client information: {e}")
}
}
}
Ok(())
}
}