From 6087c71072a5e78d3339945516b6df3933cb503e Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 2 Jul 2026 00:18:30 -0300 Subject: [PATCH] publish: proper root/reply tags. --- publish.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/publish.go b/publish.go index 1f79a28..965bbcb 100644 --- a/publish.go +++ b/publish.go @@ -124,9 +124,39 @@ example: evt.Tags = append(evt.Tags, nostr.Tag{"K", fmt.Sprint(replyEvent.Kind)}) } - // add reply tags + // add reply tags per NIP-10 + rootID := "" + rootRelay := "" + for _, tag := range replyEvent.Tags { + if len(tag) >= 2 && tag[0] == "e" { + if len(tag) >= 4 && tag[3] == "root" { + rootID = tag[1] + if len(tag) >= 3 { + rootRelay = tag[2] + } + break + } + if rootID == "" { + rootID = tag[1] + if len(tag) >= 3 { + rootRelay = tag[2] + } + } + } + } + if rootID == "" { + // replying to root event + evt.Tags = append(evt.Tags, + nostr.Tag{"e", replyEvent.ID.Hex(), "", "root"}, + ) + } else { + // replying to a reply + evt.Tags = append(evt.Tags, + nostr.Tag{"e", rootID, rootRelay, "root"}, + nostr.Tag{"e", replyEvent.ID.Hex(), "", "reply"}, + ) + } evt.Tags = append(evt.Tags, - nostr.Tag{"e", replyEvent.ID.Hex(), "", "reply"}, nostr.Tag{"p", replyEvent.PubKey.Hex()}, )