mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-15 16:50:16 +01:00
modify AppendUnique so it matches only the first two items.
This commit is contained in:
10
tags.go
10
tags.go
@@ -99,9 +99,15 @@ func (tags Tags) FilterOut(tagPrefix []string) Tags {
|
|||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendUnique appends a tag if it doesn't exist yet, otherwise does nothing
|
// AppendUnique appends a tag if it doesn't exist yet, otherwise does nothing.
|
||||||
|
// the uniqueness comparison is done based only on the first 2 elements of the tag.
|
||||||
func (tags Tags) AppendUnique(tag Tag) Tags {
|
func (tags Tags) AppendUnique(tag Tag) Tags {
|
||||||
if tags.GetFirst(tag) == nil {
|
n := len(tag)
|
||||||
|
if n > 2 {
|
||||||
|
n = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if tags.GetFirst(tag[:n]) == nil {
|
||||||
return append(tags, tag)
|
return append(tags, tag)
|
||||||
} else {
|
} else {
|
||||||
return tags
|
return tags
|
||||||
|
|||||||
Reference in New Issue
Block a user