Meta and refactor

This commit is contained in:
2026-08-20 11:06:35 +02:00
parent 8bdae4ceb8
commit 9c448049bc
6 changed files with 50 additions and 37 deletions
+17 -8
View File
@@ -44,6 +44,14 @@ export default class Enclave<P = Page> {
return this.accounts?.accounts[this.accounts.activeAccount] || null;
}
public getClientSecretKey() {
if (!this.accounts) return null;
const account = this.getAccount();
return account ? base58.decode(account.privateKey) : null;
}
public sendMessage(content: string, channelId: string) {
const clientSecretKey = this.getClientSecretKey();
@@ -104,6 +112,15 @@ export default class Enclave<P = Page> {
return;
}
const account = this.getAccount();
if (!account) {
console.error("Failed to get account");
return;
}
this.server.websocket?.send({ method: "Meta", ...account.meta });
const metaResponse = await axios.get(
getHTTPUrl(hostname, isSecure, "/meta"),
);
@@ -118,12 +135,4 @@ export default class Enclave<P = Page> {
this.forceRender();
}
public getClientSecretKey() {
if (!this.accounts) return null;
const account = this.getAccount();
return account ? base58.decode(account.privateKey) : null;
}
}
+3 -25
View File
@@ -1,21 +1,4 @@
export interface ClientMeta {}
export interface ServerMeta {
name: string;
description: string;
channels: Channel[];
}
export interface MessageData {
content: string;
timestamp: number;
signature: string;
}
export interface StoredMessage extends MessageData {
id: string;
author: string;
}
import { ClientMeta, MessageData } from "@/lib/types";
export type ClientMethod =
| {
@@ -38,9 +21,9 @@ export type ServerMethod =
timestamp: number;
hostname: string;
}
| {
| ({
method: "Meta";
}
} & ClientMeta)
| {
method: "SendMessage";
channel_id: string;
@@ -50,8 +33,3 @@ export type ServerMethod =
method: "Error";
error: string;
};
export type Channel = { id: string; name: string } & ChannelKind;
export type ChannelKind =
{ kind: "text" } | { kind: "category"; channels: Channel[] };
+1 -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 } from "./protocol";
import { ServerMeta } from "@/lib/types";
ed.hashes.sha512 = sha512;
+2 -2
View File
@@ -1,8 +1,8 @@
import { invoke } from "@tauri-apps/api/core";
import { ClientMeta } from "./types";
export interface Account {
displayName: string;
avatar?: string;
meta: ClientMeta;
privateKey: string;
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { ServerMeta } from "@/app/protocol";
import { invoke } from "@tauri-apps/api/core";
import { ServerMeta } from "./types";
export interface KnownServer {
meta: ServerMeta;
+26
View File
@@ -0,0 +1,26 @@
export interface ClientMeta {
displayName: string;
avatar?: string;
}
export interface ServerMeta {
name: string;
description: string;
channels: Channel[];
}
export interface MessageData {
content: string;
timestamp: number;
signature: string;
}
export interface StoredMessage extends MessageData {
id: string;
author: string;
}
export type Channel = { id: string; name: string } & ChannelKind;
export type ChannelKind =
{ kind: "text" } | { kind: "category"; channels: Channel[] };