feat: basic chat flow

This commit is contained in:
reya
2024-07-24 14:22:51 +07:00
parent 9b1edf7f62
commit d9c4993b71
17 changed files with 828 additions and 80 deletions

View File

@@ -4,10 +4,7 @@
/** user-defined commands **/
export const commands = {
async getAccounts() : Promise<string[]> {
return await TAURI_INVOKE("get_accounts");
},
async login(id: string) : Promise<Result<null, string>> {
async login(id: string) : Promise<Result<string, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("login", { id }) };
} catch (e) {
@@ -15,13 +12,32 @@ try {
else return { status: "error", error: e as any };
}
},
async getProfile(id: string) : Promise<Result<string, null>> {
async getAccounts() : Promise<string[]> {
return await TAURI_INVOKE("get_accounts");
},
async getProfile(id: string) : Promise<Result<string, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_profile", { id }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getChats() : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_chats") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async getChatMessages(sender: string) : Promise<Result<string[], string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_chat_messages", { sender }) };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
}
}