feat: Implement a new chat widget with enhanced encryption handling and supporting utility scripts, replacing the old chat page.

This commit is contained in:
Christomatt
2026-01-27 08:07:32 +01:00
parent f758421748
commit 75a2d87d9a
12 changed files with 739 additions and 854 deletions
+4 -3
View File
@@ -52,7 +52,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: 'Invalid input', details: parseResult.error.issues }, { status: 400 });
}
const data = parseResult.data;
console.log('[Chat Send] Input validated. Recipient:', data.recipientHandle);
console.log('[Chat Send] Input validated. Recipient:', data.recipientHandle, 'Has senderPublicKey:', !!data.senderPublicKey);
// Get sender info
const sender = await db.query.users.findFirst({
@@ -207,7 +207,7 @@ export async function POST(request: NextRequest) {
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost';
const swarmMessageId = `swarm:${nodeDomain}:${messageId}`;
console.log('[Chat Send] Inserting message into DB');
console.log('[Chat Send] Inserting message into DB, senderPublicKey from client:', !!data.senderPublicKey, 'from DB:', !!sender.chatPublicKey);
const [newMessage] = await db.insert(chatMessages).values({
conversationId: conversation.id,
senderHandle: sender.handle,
@@ -216,7 +216,8 @@ export async function POST(request: NextRequest) {
senderNodeDomain: null, // Local sender
encryptedContent,
senderEncryptedContent,
senderChatPublicKey: data.senderPublicKey || sender.chatPublicKey, // For E2E decryption
// Use client-provided key first, fall back to database
senderChatPublicKey: data.senderPublicKey || sender.chatPublicKey,
swarmMessageId,
deliveredAt: isRemote ? null : new Date(), // Delivered immediately if local
readAt: null,