diff --git a/src/app/api/chat/receive/route.ts b/src/app/api/chat/receive/route.ts index 2a18d68..be83141 100644 --- a/src/app/api/chat/receive/route.ts +++ b/src/app/api/chat/receive/route.ts @@ -1,7 +1,7 @@ import { NextRequest, NextResponse } from 'next/server'; import { db } from '@/db'; -import { chatConversations, chatMessages, users } from '@/db/schema'; +import { chatConversations, chatMessages, users, handleRegistry } from '@/db/schema'; import { eq, and } from 'drizzle-orm'; /** @@ -93,6 +93,20 @@ export async function POST(request: NextRequest) { }) .where(eq(chatConversations.id, conversation.id)); + // 5. Upsert sender into HandleRegistry ensures we can reply/fetch keys later + await db.insert(handleRegistry).values({ + handle: finalSenderHandle, // user@domain + did: senderDid, + nodeDomain: senderNodeDomain + }).onConflictDoUpdate({ + target: handleRegistry.handle, + set: { + did: senderDid, + nodeDomain: senderNodeDomain, + lastSeenAt: new Date() + } + }); + return NextResponse.json({ success: true }); } catch (error: any) {