Makes sure quotes only happen once in events.
This commit is contained in:
+9
@@ -72,6 +72,15 @@ class TagArrayBuilder<T : IEvent> {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addUniqueValueIfNew(tag: Array<String>): TagArrayBuilder<T> {
|
||||||
|
if (tag.has(1) || tag[0].isEmpty() || tag[1].isEmpty()) return this
|
||||||
|
val list = tagList.getOrPut(tag[0], ::mutableListOf)
|
||||||
|
if (list.none { it.valueOrNull() == tag[1] }) {
|
||||||
|
list.add(tag)
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
fun addAll(tag: List<Array<String>>): TagArrayBuilder<T> {
|
fun addAll(tag: List<Array<String>>): TagArrayBuilder<T> {
|
||||||
tag.forEach(::add)
|
tag.forEach(::add)
|
||||||
return this
|
return this
|
||||||
|
|||||||
+6
-6
@@ -37,12 +37,12 @@ fun <T : Event> TagArrayBuilder<T>.quotes(tag: List<QTag>) = addAll(tag.map { it
|
|||||||
|
|
||||||
fun <T : Event> TagArrayBuilder<T>.quote(entity: Entity) =
|
fun <T : Event> TagArrayBuilder<T>.quote(entity: Entity) =
|
||||||
when (entity) {
|
when (entity) {
|
||||||
is NNote -> add(entity.toQuoteTagArray())
|
is NNote -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
is NEvent -> add(entity.toQuoteTagArray())
|
is NEvent -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
is NAddress -> add(entity.toQuoteTagArray())
|
is NAddress -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
is NEmbed -> add(entity.toQuoteTagArray())
|
is NEmbed -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
is NPub -> add(entity.toQuoteTagArray())
|
is NPub -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
is NProfile -> add(entity.toQuoteTagArray())
|
is NProfile -> addUniqueValueIfNew(entity.toQuoteTagArray())
|
||||||
else -> this
|
else -> this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user