chore(chat): tipar cliente Convex do desktop sem any
This commit is contained in:
parent
a8f5ff9d51
commit
f8a472ee46
1 changed files with 12 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { ConvexClient } from "convex/browser"
|
import { ConvexClient } from "convex/browser"
|
||||||
|
import type { FunctionReference } from "convex/server"
|
||||||
import { Store } from "@tauri-apps/plugin-store"
|
import { Store } from "@tauri-apps/plugin-store"
|
||||||
import { appLocalDataDir, join } from "@tauri-apps/api/path"
|
import { appLocalDataDir, join } from "@tauri-apps/api/path"
|
||||||
import type { ChatMessage } from "./types"
|
import type { ChatMessage } from "./types"
|
||||||
|
|
@ -33,6 +34,12 @@ type MachineUpdatePayload = {
|
||||||
totalUnread: number
|
totalUnread: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FN_CHECK_UPDATES = "liveChat.checkMachineUpdates" as const
|
||||||
|
const FN_LIST_MESSAGES = "liveChat.listMachineMessages" as const
|
||||||
|
const FN_POST_MESSAGE = "liveChat.postMachineMessage" as const
|
||||||
|
const FN_MARK_READ = "liveChat.markMachineMessagesRead" as const
|
||||||
|
const FN_UPLOAD_URL = "liveChat.generateMachineUploadUrl" as const
|
||||||
|
|
||||||
async function loadStore(): Promise<MachineStoreData> {
|
async function loadStore(): Promise<MachineStoreData> {
|
||||||
const appData = await appLocalDataDir()
|
const appData = await appLocalDataDir()
|
||||||
const storePath = await join(appData, STORE_FILENAME)
|
const storePath = await join(appData, STORE_FILENAME)
|
||||||
|
|
@ -86,7 +93,7 @@ export async function subscribeMachineUpdates(
|
||||||
): Promise<() => void> {
|
): Promise<() => void> {
|
||||||
const { client, token } = await ensureClient()
|
const { client, token } = await ensureClient()
|
||||||
const sub = client.onUpdate(
|
const sub = client.onUpdate(
|
||||||
FN_CHECK_UPDATES as any,
|
FN_CHECK_UPDATES as unknown as FunctionReference<"query">,
|
||||||
{ machineToken: token },
|
{ machineToken: token },
|
||||||
(value) => callback(value),
|
(value) => callback(value),
|
||||||
onError
|
onError
|
||||||
|
|
@ -101,7 +108,7 @@ export async function subscribeMachineMessages(
|
||||||
): Promise<() => void> {
|
): Promise<() => void> {
|
||||||
const { client, token } = await ensureClient()
|
const { client, token } = await ensureClient()
|
||||||
const sub = client.onUpdate(
|
const sub = client.onUpdate(
|
||||||
FN_LIST_MESSAGES as any,
|
FN_LIST_MESSAGES as unknown as FunctionReference<"query">,
|
||||||
{
|
{
|
||||||
machineToken: token,
|
machineToken: token,
|
||||||
ticketId,
|
ticketId,
|
||||||
|
|
@ -123,7 +130,7 @@ export async function sendMachineMessage(input: {
|
||||||
}>
|
}>
|
||||||
}) {
|
}) {
|
||||||
const { client, token } = await ensureClient()
|
const { client, token } = await ensureClient()
|
||||||
return client.mutation(FN_POST_MESSAGE as any, {
|
return client.mutation(FN_POST_MESSAGE as unknown as FunctionReference<"mutation">, {
|
||||||
machineToken: token,
|
machineToken: token,
|
||||||
ticketId: input.ticketId,
|
ticketId: input.ticketId,
|
||||||
body: input.body,
|
body: input.body,
|
||||||
|
|
@ -139,7 +146,7 @@ export async function sendMachineMessage(input: {
|
||||||
export async function markMachineMessagesRead(ticketId: string, messageIds: string[]) {
|
export async function markMachineMessagesRead(ticketId: string, messageIds: string[]) {
|
||||||
if (messageIds.length === 0) return
|
if (messageIds.length === 0) return
|
||||||
const { client, token } = await ensureClient()
|
const { client, token } = await ensureClient()
|
||||||
await client.mutation(FN_MARK_READ as any, {
|
await client.mutation(FN_MARK_READ as unknown as FunctionReference<"mutation">, {
|
||||||
machineToken: token,
|
machineToken: token,
|
||||||
ticketId,
|
ticketId,
|
||||||
messageIds,
|
messageIds,
|
||||||
|
|
@ -152,7 +159,7 @@ export async function generateMachineUploadUrl(opts: {
|
||||||
fileSize: number
|
fileSize: number
|
||||||
}) {
|
}) {
|
||||||
const { client, token } = await ensureClient()
|
const { client, token } = await ensureClient()
|
||||||
return client.action(FN_UPLOAD_URL as any, {
|
return client.action(FN_UPLOAD_URL as unknown as FunctionReference<"action">, {
|
||||||
machineToken: token,
|
machineToken: token,
|
||||||
fileName: opts.fileName,
|
fileName: opts.fileName,
|
||||||
fileType: opts.fileType,
|
fileType: opts.fileType,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue