diff --git a/src/app/app.ts b/src/app/app.ts index dab6286..5c572e9 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -44,6 +44,14 @@ export default class Enclave

{ 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

{ 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

{ this.forceRender(); } - - public getClientSecretKey() { - if (!this.accounts) return null; - - const account = this.getAccount(); - - return account ? base58.decode(account.privateKey) : null; - } } diff --git a/src/app/protocol.ts b/src/app/protocol.ts index 23c206f..b509425 100644 --- a/src/app/protocol.ts +++ b/src/app/protocol.ts @@ -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[] }; diff --git a/src/app/server.ts b/src/app/server.ts index 8410579..0ebfcd4 100644 --- a/src/app/server.ts +++ b/src/app/server.ts @@ -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; diff --git a/src/lib/accounts.ts b/src/lib/accounts.ts index f9ff4ac..6278ec4 100644 --- a/src/lib/accounts.ts +++ b/src/lib/accounts.ts @@ -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; } diff --git a/src/lib/serverList.ts b/src/lib/serverList.ts index 18e1f81..0517bc6 100644 --- a/src/lib/serverList.ts +++ b/src/lib/serverList.ts @@ -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; diff --git a/src/lib/types.ts b/src/lib/types.ts new file mode 100644 index 0000000..1c77ea6 --- /dev/null +++ b/src/lib/types.ts @@ -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[] };