deprecate all useless tag methods, implement Find() and friends.

This commit is contained in:
fiatjaf
2025-03-10 02:33:29 -03:00
parent 99b11ea3be
commit a52165fb7d
6 changed files with 90 additions and 75 deletions

View File

@@ -2,24 +2,27 @@ package nip10
import "github.com/nbd-wtf/go-nostr"
func GetThreadRoot(tags nostr.Tags) *nostr.Tag {
func GetThreadRoot(tags nostr.Tags) *nostr.EventPointer {
for _, tag := range tags {
if len(tag) >= 4 && tag[0] == "e" && tag[3] == "root" {
return &tag
p, _ := nostr.EventPointerFromTag(tag)
return &p
}
}
return tags.GetFirst([]string{"e", ""})
firstE := tags.Find("e")
if firstE != nil {
return &nostr.EventPointer{
ID: firstE[1],
}
}
return nil
}
// Deprecated: this was misnamed, use GetImmediateParent instead.
func GetImmediateReply(tags nostr.Tags) *nostr.Tag {
return GetImmediateParent(tags)
}
func GetImmediateParent(tags nostr.Tags) *nostr.Tag {
var root *nostr.Tag
var lastE *nostr.Tag
func GetImmediateParent(tags nostr.Tags) *nostr.EventPointer {
var parent nostr.Tag
var lastE nostr.Tag
for i := 0; i <= len(tags)-1; i++ {
tag := tags[i]