Ready to implement sync client manager

This commit is contained in:
2025-02-11 22:20:23 +01:00
parent bb1e412d36
commit 17e086b43c
6 changed files with 39 additions and 20 deletions

View File

@@ -1,6 +1,5 @@
use crate::app_config::AppConfig;
use crate::constants::{STATE_KEY, USER_SESSION_KEY};
use crate::server::api::ws::WsMessage;
use crate::server::{HttpFailure, HttpResult};
use crate::user::{APIClient, APIClientID, User, UserConfig, UserID};
use crate::utils;
@@ -11,6 +10,7 @@ use ipnet::IpNet;
use light_openid::primitives::OpenIDConfig;
use std::str::FromStr;
use tokio::sync::broadcast;
use crate::broadcast_messages::BroadcastMessage;
/// Static assets
#[derive(rust_embed::Embed)]
@@ -65,7 +65,7 @@ pub struct FormRequest {
pub async fn home(
session: Session,
form_req: Option<web::Form<FormRequest>>,
tx: web::Data<broadcast::Sender<WsMessage>>,
tx: web::Data<broadcast::Sender<BroadcastMessage>>,
) -> HttpResult {
// Get user information, requesting authentication if information is missing
let Some(user): Option<User> = session.get(USER_SESSION_KEY)? else {
@@ -103,8 +103,10 @@ pub async fn home(
config.save().await?;
success_message = Some("Matrix token was successfully updated!".to_string());
// TODO : stop user sync thread
// Invalidate all Ws connections
if let Err(e) = tx.send(WsMessage::CloseAllUserSessions(user.id.clone())) {
if let Err(e) = tx.send(BroadcastMessage::CloseAllUserSessions(user.id.clone())) {
log::error!("Failed to send CloseAllUserSessions: {}", e);
}
}
@@ -139,7 +141,7 @@ pub async fn home(
config.save().await?;
success_message = Some("The client was successfully deleted!".to_string());
if let Err(e) = tx.send(WsMessage::CloseClientSession(delete_client_id)) {
if let Err(e) = tx.send(BroadcastMessage::CloseClientSession(delete_client_id)) {
log::error!("Failed to send CloseClientSession: {}", e);
}
}