Upsert sender into HandleRegistry on message receive
Adds logic to upsert the sender's handle, DID, and node domain into the HandleRegistry when a chat message is received. This ensures the sender's information is available for future replies or key retrieval.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user