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; 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) { public sendMessage(content: string, channelId: string) {
const clientSecretKey = this.getClientSecretKey(); const clientSecretKey = this.getClientSecretKey();
@@ -104,6 +112,15 @@ export default class Enclave<P = Page> {
return; 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( const metaResponse = await axios.get(
getHTTPUrl(hostname, isSecure, "/meta"), getHTTPUrl(hostname, isSecure, "/meta"),
); );
@@ -118,12 +135,4 @@ export default class Enclave<P = Page> {
this.forceRender(); 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 {} import { ClientMeta, MessageData } from "@/lib/types";
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 ClientMethod = export type ClientMethod =
| { | {
@@ -38,9 +21,9 @@ export type ServerMethod =
timestamp: number; timestamp: number;
hostname: string; hostname: string;
} }
| { | ({
method: "Meta"; method: "Meta";
} } & ClientMeta)
| { | {
method: "SendMessage"; method: "SendMessage";
channel_id: string; channel_id: string;
@@ -50,8 +33,3 @@ export type ServerMethod =
method: "Error"; method: "Error";
error: string; 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 EnclaveWebSocket from "./ws";
import { sha512 } from "@noble/hashes/sha2.js"; import { sha512 } from "@noble/hashes/sha2.js";
import { getWSUrl } from "@/lib/serverList"; import { getWSUrl } from "@/lib/serverList";
import { ServerMeta } from "./protocol"; import { ServerMeta } from "@/lib/types";
ed.hashes.sha512 = sha512; ed.hashes.sha512 = sha512;
+2 -2
View File
@@ -1,8 +1,8 @@
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { ClientMeta } from "./types";
export interface Account { export interface Account {
displayName: string; meta: ClientMeta;
avatar?: string;
privateKey: string; privateKey: string;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
import { ServerMeta } from "@/app/protocol";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { ServerMeta } from "./types";
export interface KnownServer { export interface KnownServer {
meta: ServerMeta; 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[] };