fix and update

This commit is contained in:
lendry
2026-06-29 21:22:20 +03:00
parent 7233e8b70a
commit 8369abb023
7 changed files with 98 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
'use client';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useAuth } from '@/components/id/auth-provider';
import { ChatMessage, ChatRoom, fetchUserE2EPublicKey, setUserE2EPublicKey } from '@/lib/api';
import { ensureE2EKeyPair } from '@/lib/e2e-crypto';
import {
@@ -51,6 +52,7 @@ export function useE2EChat(options: {
userId?: string;
token?: string | null;
}) {
const { isLoading } = useAuth();
const isE2E = options.room?.type === 'E2E';
const peerUserId = useMemo(
() => resolveChatPeerUserId(options.room, options.userId),
@@ -63,7 +65,7 @@ export function useE2EChat(options: {
const [e2eErrors, setE2eErrors] = useState<Record<string, string>>({});
useEffect(() => {
if (!options.userId || !options.token) return;
if (!options.userId || !options.token || isLoading) return;
void (async () => {
try {
const { publicKey } = await ensureE2EKeyPair(options.userId!);
@@ -72,7 +74,7 @@ export function useE2EChat(options: {
// фоновая инициализация E2E
}
})();
}, [options.token, options.userId]);
}, [isLoading, options.token, options.userId]);
useEffect(() => {
if (!isE2E || !peerUserId || !options.token) {