Sync chat public key to users table and fix handle formatting

The chat public key is now also updated in the users table during key publishing for profile discovery. Additionally, sender handles in chat receive are now fully qualified with domain when necessary to ensure consistency in conversation and message storage.
This commit is contained in:
Christopher
2026-01-28 07:43:05 -08:00
parent 93a587f185
commit 28f561f689
2 changed files with 18 additions and 6 deletions
+7 -3
View File
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/db';
import { chatDeviceBundles, handleRegistry, remoteIdentityCache } from '@/db/schema';
import { chatDeviceBundles, handleRegistry, remoteIdentityCache, users } from '@/db/schema';
import { requireAuth } from '@/lib/auth';
import { eq, and, gt } from 'drizzle-orm';
@@ -205,8 +205,7 @@ export async function POST(request: NextRequest) {
);
console.log('[Chat Keys POST] Updated existing key');
} else {
// Insert new bundle
console.log('[Chat Keys POST] Inserting new bundle...');
console.log('[Chat Keys POST] Inserted new key');
await db.insert(chatDeviceBundles).values({
userId: user.id,
did: user.did,
@@ -219,6 +218,11 @@ export async function POST(request: NextRequest) {
console.log('[Chat Keys POST] Inserted new key');
}
// Sync to users table too for profile discovery
await db.update(users)
.set({ chatPublicKey: publicKey })
.where(eq(users.id, user.id));
console.log('[Chat Keys POST] Key published successfully for', user.handle);
return NextResponse.json({ success: true });
} catch (error: any) {