-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for selecting authors based on their Outbox relays when …
…searching for notes authored by them
- Loading branch information
1 parent
6f59097
commit a1aaec0
Showing
4 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...lite/src/main/java/com/vitorpamplona/ammolite/relays/filters/SinceAuthorPerRelayFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |