Get users

This commit is contained in:
2026-08-22 12:14:11 +02:00
parent 78f5544952
commit 546670b9d2
3 changed files with 44 additions and 8 deletions
+13 -1
View File
@@ -3,7 +3,7 @@ import * as ed from "@noble/ed25519";
import EnclaveWebSocket from "./ws";
import { sha512 } from "@noble/hashes/sha2.js";
import { getWSUrl } from "@/lib/serverList";
import { ServerMeta, StoredMessage } from "@/lib/types";
import { ClientMeta, ServerMeta, StoredMessage } from "@/lib/types";
ed.hashes.sha512 = sha512;
@@ -30,11 +30,13 @@ export default class EnclaveServer {
public websocket?: EnclaveWebSocket;
public meta?: ServerMeta;
public messages: Record<string, Record<string, StoredMessage>>;
public users: Record<string, ClientMeta | null>;
public constructor(hostname: string, isSecure: boolean) {
this.hostname = hostname;
this.isSecure = isSecure;
this.messages = {};
this.users = {};
}
public disconnect() {
@@ -94,4 +96,14 @@ export default class EnclaveServer {
throw Error("Invalid signature");
}
}
public getUsers(pubkeys: string[]) {
const filteredPubkeys = pubkeys.filter((pubkey) => {
const exists = this.users[pubkey] !== undefined;
if (!exists) this.users[pubkey] = null;
return !exists;
});
this.websocket?.send({ method: "GetUsers", pubkeys: filteredPubkeys });
}
}