mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-11 07:56:50 +02:00
fix: NIP-10 adapter delegates to NIP-22 for non-kind-1 events
When NIP-10 adapter encounters a non-kind-1 event (e.g., kind 9735 zap), it now gracefully delegates to NIP-22 comment adapter instead of throwing an error. This enables seamless chat on any event type. Also changed menu label from "Comments" to "Chat" for all event types.
This commit is contained in:
@@ -278,7 +278,7 @@ export function EventMenu({ event }: { event: NostrEvent }) {
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={openChatWindow}>
|
||||
<MessageSquare className="size-4 mr-2" />
|
||||
{event.kind === 1 ? "Chat" : "Comments"}
|
||||
Chat
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={copyEventId}>
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
eventToMessage,
|
||||
AGGREGATOR_RELAYS,
|
||||
} from "../utils";
|
||||
import { Nip22Adapter } from "./nip-22-adapter";
|
||||
|
||||
const LOG_PREFIX = "[NIP-10]";
|
||||
|
||||
@@ -122,8 +123,24 @@ export class Nip10Adapter extends ChatProtocolAdapter {
|
||||
throw new Error("Event not found");
|
||||
}
|
||||
|
||||
// If not kind 1, delegate to NIP-22 comment adapter
|
||||
if (providedEvent.kind !== 1) {
|
||||
throw new Error(`Expected kind 1 note, got kind ${providedEvent.kind}`);
|
||||
console.log(
|
||||
`${LOG_PREFIX} Event is kind ${providedEvent.kind}, delegating to NIP-22`,
|
||||
);
|
||||
const nip22Adapter = new Nip22Adapter();
|
||||
// Build a comment identifier from the event
|
||||
const commentIdentifier = {
|
||||
type: "comment" as const,
|
||||
value: {
|
||||
id: providedEvent.id,
|
||||
relays: relayHints,
|
||||
author: providedEvent.pubkey,
|
||||
kind: providedEvent.kind,
|
||||
},
|
||||
relays: relayHints,
|
||||
};
|
||||
return nip22Adapter.resolveConversation(commentIdentifier);
|
||||
}
|
||||
|
||||
// 2. Parse NIP-10 references to find root
|
||||
|
||||
Reference in New Issue
Block a user