mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 07:07:37 +01:00
Adds support for selecting authors based on their Outbox relays when searching for notes authored by them
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.ammolite.relays
|
||||
|
||||
import com.vitorpamplona.ammolite.relays.filters.SinceAuthorPerRelayFilter
|
||||
import com.vitorpamplona.ammolite.relays.filters.SincePerRelayFilter
|
||||
import java.util.UUID
|
||||
|
||||
@@ -47,6 +48,10 @@ data class Subscription(
|
||||
return isDifferent(typedFilter.filter, otherFilter.filter)
|
||||
}
|
||||
|
||||
if (typedFilter.filter is SinceAuthorPerRelayFilter && otherFilter.filter is SinceAuthorPerRelayFilter) {
|
||||
return isDifferent(typedFilter.filter, otherFilter.filter)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -78,6 +83,37 @@ data class Subscription(
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun isDifferent(
|
||||
filter1: SinceAuthorPerRelayFilter,
|
||||
filter2: SinceAuthorPerRelayFilter,
|
||||
): Boolean {
|
||||
// Does not check SINCE on purpose. Avoids replacing the filter if SINCE was all that changed.
|
||||
// fast check
|
||||
if (filter1.authors?.size != filter2.authors?.size ||
|
||||
filter1.ids?.size != filter2.ids?.size ||
|
||||
filter1.tags?.size != filter2.tags?.size ||
|
||||
filter1.kinds?.size != filter2.kinds?.size ||
|
||||
filter1.limit != filter2.limit ||
|
||||
filter1.search?.length != filter2.search?.length ||
|
||||
filter1.until != filter2.until
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
// deep check
|
||||
if (filter1.ids != filter2.ids ||
|
||||
filter1.authors != filter2.authors ||
|
||||
filter1.tags != filter2.tags ||
|
||||
filter1.kinds != filter2.kinds ||
|
||||
filter1.search != filter2.search
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.ammolite.relays.filters
|
||||
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
|
||||
/**
|
||||
* This is a nostr filter with per-relay authors list and since parameters
|
||||
*/
|
||||
class SinceAuthorPerRelayFilter(
|
||||
val ids: List<String>? = null,
|
||||
val authors: Map<String, List<String>>? = null,
|
||||
val kinds: List<Int>? = null,
|
||||
val tags: Map<String, List<String>>? = null,
|
||||
val since: Map<String, EOSETime>? = null,
|
||||
val until: Long? = null,
|
||||
val limit: Int? = null,
|
||||
val search: String? = null,
|
||||
) : IPerRelayFilter {
|
||||
override fun toJson(forRelay: String) = FilterSerializer.toJson(ids, authors?.get(forRelay), kinds, tags, since?.get(forRelay)?.time, until, limit, search)
|
||||
|
||||
override fun match(
|
||||
event: Event,
|
||||
forRelay: String,
|
||||
) = FilterMatcher.match(event, ids, authors?.get(forRelay), kinds, tags, since?.get(forRelay)?.time, until)
|
||||
|
||||
override fun toDebugJson(): String {
|
||||
val factory = Event.mapper.nodeFactory
|
||||
val obj = FilterSerializer.toJsonObject(ids, null, kinds, tags, null, until, limit, search)
|
||||
authors?.run {
|
||||
if (isNotEmpty()) {
|
||||
val jsonObjectPerRelayAuthors = factory.objectNode()
|
||||
entries.forEach { relayAuthorPairs ->
|
||||
jsonObjectPerRelayAuthors.put(relayAuthorPairs.key, factory.arrayNode(relayAuthorPairs.value.size).apply { relayAuthorPairs.value.forEach { add(it) } })
|
||||
}
|
||||
obj.put("authors", jsonObjectPerRelayAuthors)
|
||||
}
|
||||
}
|
||||
|
||||
since?.run {
|
||||
if (isNotEmpty()) {
|
||||
val jsonObjectSince = factory.objectNode()
|
||||
entries.forEach { sincePairs ->
|
||||
jsonObjectSince.put(sincePairs.key, "${sincePairs.value}")
|
||||
}
|
||||
obj.put("since", jsonObjectSince)
|
||||
}
|
||||
}
|
||||
return Event.mapper.writeValueAsString(obj)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user