use crate::controllers::HttpResult; use crate::extractors::matrix_client_extractor::MatrixClientExtractor; use crate::matrix_connection::matrix_manager::MatrixManagerMsg; use actix_web::{HttpResponse, web}; use ractor::ActorRef; /// Start sync thread pub async fn start_sync( client: MatrixClientExtractor, manager: web::Data>, ) -> HttpResult { match ractor::cast!( manager, MatrixManagerMsg::StartSyncThread(client.auth.user.email.clone()) ) { Ok(_) => Ok(HttpResponse::Accepted().finish()), Err(e) => { log::error!("Failed to start sync: {e}"); Ok(HttpResponse::InternalServerError().finish()) } } } /// Stop sync thread pub async fn stop_sync( client: MatrixClientExtractor, manager: web::Data>, ) -> HttpResult { match ractor::cast!( manager, MatrixManagerMsg::StopSyncThread(client.auth.user.email.clone()) ) { Ok(_) => Ok(HttpResponse::Accepted().finish()), Err(e) => { log::error!("Failed to stop sync thread: {e}"); Ok(HttpResponse::InternalServerError().finish()) } } } #[derive(serde::Serialize)] struct GetSyncStatusResponse { started: bool, } /// Get sync thread status pub async fn status( client: MatrixClientExtractor, manager: web::Data>, ) -> HttpResult { let started = ractor::call!( manager.as_ref(), MatrixManagerMsg::SyncThreadGetStatus, client.auth.user.email ) .expect("RPC to Matrix Manager failed"); Ok(HttpResponse::Ok().json(GetSyncStatusResponse { started })) }