From 60f38c778c4561dae910ab422aa8a3c0fbf297ff Mon Sep 17 00:00:00 2001 From: Rizky Date: Thu, 26 Oct 2023 11:22:55 +0700 Subject: [PATCH] fix --- app/srv/ws/sync/actions/activity.ts | 2 +- app/srv/ws/sync/sync-handler.ts | 3 +++ app/srv/ws/sync/type.ts | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/srv/ws/sync/actions/activity.ts b/app/srv/ws/sync/actions/activity.ts index 008fc787..2d77c9e9 100644 --- a/app/srv/ws/sync/actions/activity.ts +++ b/app/srv/ws/sync/actions/activity.ts @@ -1,7 +1,7 @@ import { validate } from "uuid"; import { SAction } from "../actions"; -import { SyncConnection } from "../type"; import { actstore, broadcastActivity } from "../entity/actstore"; +import { SyncConnection } from "../type"; export const activity: SAction["activity"] = async function ( this: SyncConnection, diff --git a/app/srv/ws/sync/sync-handler.ts b/app/srv/ws/sync/sync-handler.ts index e9d48252..e40f89de 100644 --- a/app/srv/ws/sync/sync-handler.ts +++ b/app/srv/ws/sync/sync-handler.ts @@ -21,6 +21,7 @@ export const syncHandler: WebSocketHandler = { const client_id = createId(); conns.set(client_id, { user_id: "", + user: null, client_id, ws, msg: { pending: {}, resolve: {} }, @@ -58,7 +59,9 @@ export const syncHandler: WebSocketHandler = { const msg = packr.unpack(Buffer.from(raw)); if (msg.type === SyncType.UserID) { const { user_id, page_id, site_id } = msg; + conn.user_id = user_id; + conn.user = await db.user.findFirst({ where: { id: user_id } }); let conf = await user.conf.getOrCreate(user_id); if (site_id) { diff --git a/app/srv/ws/sync/type.ts b/app/srv/ws/sync/type.ts index 29bb2162..133ecc39 100644 --- a/app/srv/ws/sync/type.ts +++ b/app/srv/ws/sync/type.ts @@ -1,6 +1,7 @@ import { ServerWebSocket } from "bun"; import { UserConf } from "./entity/user"; import { WSData } from "../../../../pkgs/core/server/create"; +import { user } from "../../../db/db"; export enum SyncType { ClientID, @@ -12,6 +13,7 @@ export enum SyncType { export type SyncConnection = { user_id: string; + user: null | user; client_id: string; conf?: UserConf & { toJSON: () => UserConf }; ws: ServerWebSocket;