This commit is contained in:
payacom
2026-09-09 10:19:27 +03:30
parent bf41ad4e0f
commit 2d5505065b
28 changed files with 872 additions and 88 deletions

View File

@@ -7,7 +7,7 @@ import {
joinUserRoom,
releaseChatSocket,
} from "@/lib/chat/socketClient";
import { ensureIdentityKeys } from "@/lib/e2ee";
import E2eeIdentityGate from "@/components/chat/E2eeIdentityGate";
export default function ChatSocketProvider({
children,
@@ -15,14 +15,12 @@ export default function ChatSocketProvider({
children: React.ReactNode;
}) {
const user = useUser();
const uid = user?._id ? String(user._id) : "";
useEffect(() => {
if (!user?._id) return;
if (!uid) return;
const socket = acquireChatSocket();
const uid = String(user._id);
void ensureIdentityKeys(uid);
const join = () => joinUserRoom(uid);
socket.on("connect", join);
@@ -32,7 +30,15 @@ export default function ChatSocketProvider({
socket.off("connect", join);
releaseChatSocket();
};
}, [user?._id]);
}, [uid]);
return children;
return (
<>
{/* ensureIdentityKeys اینجا (تویِ خودِ گیت) صدا زده می‌شه، نه اینجا مستقیم —
تا اگه هویتِ قبلی روی سرور هست و این دستگاه بهش دسترسی نداره، به‌جای
fail شدنِ بی‌صدا، از کاربر بازیابی/تاییدِ صریح خواسته بشه */}
{uid ? <E2eeIdentityGate userId={uid} /> : null}
{children}
</>
);
}