Revamp chat UI and add V2 encrypted messaging support
Major update to chat page with new conversation list, message thread view, and support for V2 end-to-end encrypted messaging using DIDs. Adds chat lock state, message sending, conversation deletion, and improved polling. Updates user API and types to include DID and chatPublicKey. Fixes race conditions in feed loading, adds message button to user profile, and improves crypto and identity hooks for better locked/unlocked state detection.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback, useRef } from 'react';
|
||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||
import {
|
||||
unlockChatStorage,
|
||||
loadDeviceKeys,
|
||||
@@ -40,6 +40,44 @@ export function useChatEncryption() {
|
||||
// Session Cache (In-Memory)
|
||||
const sessionsRef = useRef<Map<string, RatchetState>>(new Map());
|
||||
|
||||
const [isLocked, setIsLocked] = useState(false);
|
||||
|
||||
// Auto-detect if storage is unlocked (by AuthContext)
|
||||
useEffect(() => {
|
||||
if (isReady) {
|
||||
setIsLocked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const check = async () => {
|
||||
const unlocked = isStorageUnlocked();
|
||||
setIsLocked(!unlocked);
|
||||
|
||||
if (unlocked) {
|
||||
try {
|
||||
// If storage is open, verify keys exist
|
||||
// If so, we are ready.
|
||||
// If not, we might need ensureReady to generate, but usually they exist.
|
||||
const keys = await loadDeviceKeys();
|
||||
if (keys) {
|
||||
setIsReady(true);
|
||||
setStatus('ready');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Auto-ready check failed", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
check(); // Checks immediately
|
||||
const interval = setInterval(check, 1000); // And polls
|
||||
return () => clearInterval(interval);
|
||||
}, [isReady]);
|
||||
|
||||
// ... (ensureReady, sendMessage, decryptMessage) ...
|
||||
|
||||
|
||||
|
||||
const ensureReady = useCallback(async (password: string, userId: string) => {
|
||||
setStatus('initializing');
|
||||
try {
|
||||
@@ -279,6 +317,7 @@ export function useChatEncryption() {
|
||||
|
||||
return {
|
||||
isReady,
|
||||
isLocked,
|
||||
status,
|
||||
ensureReady,
|
||||
sendMessage,
|
||||
|
||||
Reference in New Issue
Block a user