From 998a1bcf4a5073559824c31eb1123be7472ecf71 Mon Sep 17 00:00:00 2001 From: Christomatt Date: Tue, 27 Jan 2026 01:54:59 +0100 Subject: [PATCH] feat(chat): Improve recipient handle parsing for swarm messaging - Strip leading @ symbol from recipient handle before normalization - Replace simple split() with substring-based parsing for more robust handle@domain extraction - Add clarifying comments explaining handle format expectations (handle@domain) - Prevent potential issues with malformed recipient handles containing multiple @ symbols - Ensure consistent handle normalization across local and remote recipients --- src/app/api/swarm/chat/send/route.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/api/swarm/chat/send/route.ts b/src/app/api/swarm/chat/send/route.ts index dce64c6..bf13de4 100644 --- a/src/app/api/swarm/chat/send/route.ts +++ b/src/app/api/swarm/chat/send/route.ts @@ -60,7 +60,8 @@ export async function POST(request: NextRequest) { console.log('[Chat Send] Sender retrieved:', sender.handle); // Parse recipient handle (could be local or remote) - const recipientHandle = data.recipientHandle.toLowerCase(); + // Strip leading @ if present, then normalize + const recipientHandle = data.recipientHandle.toLowerCase().replace(/^@/, ''); const isRemote = recipientHandle.includes('@'); let recipientUser: typeof users.$inferSelect | undefined; @@ -69,7 +70,10 @@ export async function POST(request: NextRequest) { if (isRemote) { // Remote user - need to fetch their public key - const [handle, domain] = recipientHandle.split('@'); + // Format: handle@domain (e.g., matterbator@batorbros.bond) + const atIndex = recipientHandle.indexOf('@'); + const handle = recipientHandle.substring(0, atIndex); + const domain = recipientHandle.substring(atIndex + 1); recipientNodeDomain = domain; console.log('[Chat Send] Processing remote recipient:', handle, '@', domain);