tag helpers in a separate file and nip10 helpers.

This commit is contained in:
fiatjaf
2022-11-17 06:15:30 -03:00
parent 69ccfbaa08
commit 381ee2cc01
3 changed files with 167 additions and 116 deletions

24
nip10/nip10.go Normal file
View File

@ -0,0 +1,24 @@
package nip10
import "github.com/nbd-wtf/go-nostr"
func GetThreadRoot(tags nostr.Tags) *nostr.Tag {
for _, tag := range tags {
if len(tag) >= 4 && tag[0] == "e" && tag[3] == "root" {
return &tag
}
}
return tags.GetFirst([]string{"e", ""})
}
func GetImmediateReply(tags nostr.Tags) *nostr.Tag {
for i := len(tags) - 1; i >= 0; i-- {
tag := tags[i]
if len(tag) >= 4 && tag[0] == "e" && tag[3] == "reply" {
return &tag
}
}
return tags.GetLast([]string{"e", ""})
}