Meta and refactor
This commit is contained in:
+17
-8
@@ -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
@@ -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
@@ -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
@@ -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,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;
|
||||||
|
|||||||
@@ -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[] };
|
||||||
Reference in New Issue
Block a user