mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-29 17:19:16 +02:00
improve nip10.GetImmediateReply()
This commit is contained in:
parent
392013fa25
commit
7be5330d42
@ -13,12 +13,43 @@ func GetThreadRoot(tags nostr.Tags) *nostr.Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetImmediateReply(tags nostr.Tags) *nostr.Tag {
|
func GetImmediateReply(tags nostr.Tags) *nostr.Tag {
|
||||||
|
var root *nostr.Tag
|
||||||
|
var lastE *nostr.Tag
|
||||||
|
|
||||||
for i := len(tags) - 1; i >= 0; i-- {
|
for i := len(tags) - 1; i >= 0; i-- {
|
||||||
tag := tags[i]
|
tag := tags[i]
|
||||||
if len(tag) >= 4 && tag[0] == "e" && tag[3] == "reply" {
|
|
||||||
return &tag
|
if len(tag) < 2 {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
if tag[0] != "e" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tag) >= 4 {
|
||||||
|
if tag[3] == "reply" {
|
||||||
|
return &tag
|
||||||
|
}
|
||||||
|
if tag[3] == "root" {
|
||||||
|
// will be used as our first fallback
|
||||||
|
root = &tag
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if tag[3] == "mention" {
|
||||||
|
// this invalidates this tag as a second fallback mechanism (clients that don't add markers)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastE = &tag // will be used as our second fallback (clients that don't add markers)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tags.GetLast([]string{"e", ""})
|
// if we reached this point we don't have a "reply", but if we have a "root"
|
||||||
|
// that means this event is a direct reply to the root
|
||||||
|
if root != nil {
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we reached this point and we have at least one "e" we'll use that (the last)
|
||||||
|
return lastE
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user