This commit is contained in:
2026-08-22 12:25:23 +02:00
parent 8ab3d140fe
commit 1a910d4bd3
6 changed files with 111 additions and 1 deletions
+13
View File
@@ -9,6 +9,7 @@ use crate::{data::messages::StoredMessage, server::Server, types::ClientMeta};
pub mod initialize;
pub mod message;
pub mod user;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "method")]
@@ -25,6 +26,10 @@ pub enum ClientMethod {
messages: HashMap<String, Vec<StoredMessage>>,
},
Users {
users: HashMap<String, ClientMeta>,
},
Error {
error: Cow<'static, str>,
},
@@ -53,6 +58,10 @@ pub enum ServerMethod {
Meta(ClientMeta),
GetUsers {
pubkeys: Vec<String>,
},
Error {
error: String,
},
@@ -93,6 +102,10 @@ pub async fn read_loop(
ServerMethod::GetMessages { channel_id, chunk } => {
message::get_messages(server, verifying_key, socket, channel_id, chunk).await?;
}
ServerMethod::GetUsers { pubkeys } => {
user::get_users(server, verifying_key, socket, pubkeys).await?;
}
}
socket_lock = socket.lock().await;
+23
View File
@@ -0,0 +1,23 @@
use std::sync::Arc;
use axum::extract::ws::WebSocket;
use ed25519_dalek::VerifyingKey;
use tokio::sync::Mutex;
use crate::{
protocol::{ClientMethod, send_socket},
server::Server,
};
pub async fn get_users(
server: &Arc<Server>,
_verifying_key: VerifyingKey,
socket: &Arc<Mutex<WebSocket>>,
pubkeys: Vec<String>,
) -> anyhow::Result<()> {
let users = server.user_store.get_users(&pubkeys).await?;
send_socket(&mut *socket.lock().await, &ClientMethod::Users { users }).await?;
Ok(())
}