modify AppendUnique so it matches only the first two items.

This commit is contained in:
fiatjaf
2023-02-05 17:04:15 -03:00
parent a3e3b25dd9
commit 4aee139f6c

10
tags.go
View File

@@ -99,9 +99,15 @@ func (tags Tags) FilterOut(tagPrefix []string) Tags {
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 {
if tags.GetFirst(tag) == nil {
n := len(tag)
if n > 2 {
n = 2
}
if tags.GetFirst(tag[:n]) == nil {
return append(tags, tag)
} else {
return tags