From e5eab70b6863ef9a3b3367ae93de33aac19a591e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 16:31:41 +0000 Subject: [PATCH] fix: add NIP-10 and NIP-22 support to chat command reconstructor The edit button in chat windows now correctly reconstructs commands for: - NIP-10 threads: chat nevent1... format - NIP-22 comments: chat nevent1... for event pointers, chat naddr1... for address pointers (e.g., articles) Previously only NIP-29 (groups) and NIP-53 (live activities) were supported. --- src/lib/command-reconstructor.ts | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/lib/command-reconstructor.ts b/src/lib/command-reconstructor.ts index 890de6f..5eb765b 100644 --- a/src/lib/command-reconstructor.ts +++ b/src/lib/command-reconstructor.ts @@ -204,6 +204,66 @@ export function reconstructCommand(window: WindowInstance): string { } } + // NIP-10 threads: chat nevent1... + if (protocol === "nip-10" && identifier.type === "thread") { + const { id, relays, author, kind } = identifier.value || {}; + + if (id) { + try { + const nevent = nip19.neventEncode({ + id, + relays, + author, + kind, + }); + return `chat ${nevent}`; + } catch { + // Fallback to raw ID + return `chat ${id}`; + } + } + } + + // NIP-22 comments: chat nevent1... or chat naddr1... + if (protocol === "nip-22" && identifier.type === "comment") { + const value = identifier.value; + + if (value) { + try { + // Event pointer (has id) + if ("id" in value) { + const nevent = nip19.neventEncode({ + id: value.id, + relays: value.relays, + author: value.author, + kind: value.kind, + }); + return `chat ${nevent}`; + } + + // Address pointer (has kind, pubkey, identifier) + if ( + "kind" in value && + "pubkey" in value && + "identifier" in value + ) { + const naddr = nip19.naddrEncode({ + kind: value.kind, + pubkey: value.pubkey, + identifier: value.identifier, + relays: identifier.relays, + }); + return `chat ${naddr}`; + } + } catch { + // Fallback if encoding fails + if ("id" in value) { + return `chat ${value.id}`; + } + } + } + } + return "chat"; }