synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use anyhow::Result;
use matrix_sdk::Client;
use matrix_sdk::ruma;

/// Check if the client has an active session.
pub fn is_logged_in(client: &Client) -> bool {
    client.user_id().is_some()
}

/// Get the current user ID from the client.
pub fn current_user_id(client: &Client) -> Option<ruma::OwnedUserId> {
    client.user_id().map(|u| u.to_owned())
}

/// Get the current device ID from the client.
pub fn current_device_id(client: &Client) -> Option<ruma::OwnedDeviceId> {
    client.device_id().map(|d| d.to_owned())
}

/// Perform server-side logout and clear local session data.
pub async fn logout(client: &Client) -> Result<()> {
    // Logout from the server via the Matrix auth API
    client.matrix_auth().logout().await?;

    // Clear persisted session
    crate::persistence::matrix_state::clear_session().await?;

    tracing::info!("Logged out successfully");
    Ok(())
}