revert: keep INostrClient/NostrClient naming and restore onEose/isLive
Reverts three naming changes from the previous refactor: - Interface stays INostrClient (not NostrClient) - Class stays NostrClient (not DefaultNostrClient) - onEose stays onEose (not onCaughtUp) - isLive stays isLive (not isRealTime) All other renames from the API simplification are preserved: subscribe, unsubscribe, publish, count, fetchAll, fetchFirst, etc. https://claude.ai/code/session_01JPcYCcRx5eZN4GvgGxGwbf
This commit is contained in:
+2
-2
@@ -31,7 +31,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface NostrClient : AutoCloseable {
|
||||
interface INostrClient : AutoCloseable {
|
||||
fun connectedRelaysFlow(): StateFlow<Set<NormalizedRelayUrl>>
|
||||
|
||||
fun availableRelaysFlow(): StateFlow<Set<NormalizedRelayUrl>>
|
||||
@@ -87,7 +87,7 @@ interface NostrClient : AutoCloseable {
|
||||
fun activeOutboxCache(url: NormalizedRelayUrl): Set<HexKey>
|
||||
}
|
||||
|
||||
class EmptyNostrClient : NostrClient {
|
||||
class EmptyNostrClient : INostrClient {
|
||||
override fun connectedRelaysFlow() = MutableStateFlow(emptySet<NormalizedRelayUrl>())
|
||||
|
||||
override fun availableRelaysFlow() = MutableStateFlow(emptySet<NormalizedRelayUrl>())
|
||||
+3
-3
@@ -52,7 +52,7 @@ import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* The NostrClient manages Nostr relay operations, subscriptions, and event delivery. It maintains:
|
||||
* The INostrClient manages Nostr relay operations, subscriptions, and event delivery. It maintains:
|
||||
* - A RelayPool for managing connections to a collection of Nostr relays
|
||||
* - Active subscriptions tracking through PoolSubscriptionRepository
|
||||
* - An event outbox for managing unsent events and retry logic
|
||||
@@ -76,10 +76,10 @@ import kotlinx.coroutines.launch
|
||||
* are connected to all necessary endpoints. It also listens to relay state changes to update
|
||||
* subscriptions and message retries when connections are re-established.
|
||||
*/
|
||||
class DefaultNostrClient(
|
||||
class NostrClient(
|
||||
private val websocketBuilder: WebsocketBuilder,
|
||||
private val parentScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
|
||||
) : NostrClient,
|
||||
) : INostrClient,
|
||||
RelayConnectionListener,
|
||||
AutoCloseable {
|
||||
private val relayPool: RelayPool = RelayPool(websocketBuilder, this)
|
||||
+3
-3
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EventMessage
|
||||
@@ -29,10 +29,10 @@ import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onEvent messages for caching purposes.
|
||||
* Listens to INostrClient's onEvent messages for caching purposes.
|
||||
*/
|
||||
class EventCollector(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val onEvent: (event: Event, relay: IRelayClient) -> Unit,
|
||||
) {
|
||||
private val clientListener =
|
||||
|
||||
+4
-4
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.newSubId
|
||||
@@ -43,7 +43,7 @@ import kotlinx.coroutines.withTimeoutOrNull
|
||||
* @param timeoutMs How long to wait for a response (default 15 s).
|
||||
* @return The [CountResult], or `null` on timeout.
|
||||
*/
|
||||
suspend fun NostrClient.count(
|
||||
suspend fun INostrClient.count(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
timeoutMs: Long = 15_000,
|
||||
@@ -92,7 +92,7 @@ suspend fun NostrClient.count(
|
||||
* @param timeoutMs How long to wait for all responses (default 15 s).
|
||||
* @return Map of relay -> [CountResult] for every relay that responded in time.
|
||||
*/
|
||||
suspend fun NostrClient.count(
|
||||
suspend fun INostrClient.count(
|
||||
filters: Map<NormalizedRelayUrl, List<Filter>>,
|
||||
timeoutMs: Long = 15_000,
|
||||
): Map<NormalizedRelayUrl, CountResult> {
|
||||
@@ -155,7 +155,7 @@ suspend fun NostrClient.count(
|
||||
* @param timeoutMs How long to wait for all responses (default 15 s).
|
||||
* @return A merged [CountResult], or `null` if no relay responded.
|
||||
*/
|
||||
suspend fun NostrClient.countMerged(
|
||||
suspend fun INostrClient.countMerged(
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
filter: Filter,
|
||||
timeoutMs: Long = 15_000,
|
||||
|
||||
+10
-10
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.newSubId
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
@@ -31,45 +31,45 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
relay: String,
|
||||
filter: Filter,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(newSubId(), mapOf(RelayUrlNormalizer.normalize(relay) to listOf(filter)), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(newSubId(), mapOf(RelayUrlNormalizer.normalize(relay) to filters), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
subscriptionId: String = newSubId(),
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(subscriptionId, mapOf(RelayUrlNormalizer.normalize(relay) to filters), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(newSubId(), mapOf(relay to listOf(filter)), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(newSubId(), mapOf(relay to filters), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
subscriptionId: String = newSubId(),
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
) = fetchAll(subscriptionId, mapOf(relay to filters), timeoutMs)
|
||||
|
||||
suspend fun NostrClient.fetchAll(
|
||||
suspend fun INostrClient.fetchAll(
|
||||
subscriptionId: String = newSubId(),
|
||||
filters: Map<NormalizedRelayUrl, List<Filter>>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
@@ -85,7 +85,7 @@ suspend fun NostrClient.fetchAll(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -110,7 +110,7 @@ suspend fun NostrClient.fetchAll(
|
||||
doneChannel.trySend(relay)
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.newSubId
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
@@ -51,7 +51,7 @@ import kotlin.math.min
|
||||
* @param onEvent Called for every event received (in page order, after each EOSE).
|
||||
* @return Total number of events received across all pages.
|
||||
*/
|
||||
suspend fun NostrClient.fetchAllPages(
|
||||
suspend fun INostrClient.fetchAllPages(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
@@ -98,7 +98,7 @@ suspend fun NostrClient.fetchAllPages(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -120,7 +120,7 @@ suspend fun NostrClient.fetchAllPages(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -168,7 +168,7 @@ suspend fun NostrClient.fetchAllPages(
|
||||
return totalEvents
|
||||
}
|
||||
|
||||
suspend fun NostrClient.fetchAllPages(
|
||||
suspend fun INostrClient.fetchAllPages(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
timeoutMs: Long = 30_000L,
|
||||
|
||||
+10
-10
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.newSubId
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
@@ -31,39 +31,39 @@ import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
relay: String,
|
||||
filter: Filter,
|
||||
) = fetchFirst(newSubId(), mapOf(RelayUrlNormalizer.normalize(relay) to listOf(filter)))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
) = fetchFirst(newSubId(), mapOf(RelayUrlNormalizer.normalize(relay) to filters))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
subscriptionId: String = newSubId(),
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
) = fetchFirst(subscriptionId, mapOf(RelayUrlNormalizer.normalize(relay) to filters))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
) = fetchFirst(newSubId(), mapOf(relay to listOf(filter)))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
) = fetchFirst(newSubId(), mapOf(relay to filters))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
subscriptionId: String = newSubId(),
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
) = fetchFirst(subscriptionId, mapOf(relay to filters))
|
||||
|
||||
suspend fun NostrClient.fetchFirst(
|
||||
suspend fun INostrClient.fetchFirst(
|
||||
subscriptionId: String = newSubId(),
|
||||
filters: Map<NormalizedRelayUrl, List<Filter>>,
|
||||
): Event? {
|
||||
@@ -73,7 +73,7 @@ suspend fun NostrClient.fetchFirst(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -96,7 +96,7 @@ suspend fun NostrClient.fetchFirst(
|
||||
resultChannel.trySend(null)
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
@@ -41,7 +41,7 @@ class Result(
|
||||
)
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
suspend fun NostrClient.publishAndConfirm(
|
||||
suspend fun INostrClient.publishAndConfirm(
|
||||
event: Event,
|
||||
relayList: Set<NormalizedRelayUrl>,
|
||||
timeoutInSeconds: Long = 15,
|
||||
@@ -52,7 +52,7 @@ suspend fun NostrClient.publishAndConfirm(
|
||||
* Returns per-relay results: relay URL -> accepted (true/false).
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
suspend fun NostrClient.publishAndConfirmDetailed(
|
||||
suspend fun INostrClient.publishAndConfirmDetailed(
|
||||
event: Event,
|
||||
relayList: Set<NormalizedRelayUrl>,
|
||||
timeoutInSeconds: Long = 15,
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
@@ -29,10 +29,10 @@ import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.OkMessage
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onEvent messages for caching purposes.
|
||||
* Listens to INostrClient's onEvent messages for caching purposes.
|
||||
*/
|
||||
class RelayInsertConfirmationCollector(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val onRelayReceived: (eventId: HexKey, relay: IRelayClient) -> Unit,
|
||||
) {
|
||||
private val clientListener =
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.AuthMessage
|
||||
@@ -38,10 +38,10 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.displayUrl
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onNotify messages from the relay
|
||||
* Listens to INostrClient's onNotify messages from the relay
|
||||
*/
|
||||
class RelayLogger(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val debugSending: Boolean = false,
|
||||
val debugReceiving: Boolean = false,
|
||||
) {
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
@@ -28,10 +28,10 @@ import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.NotifyMessage
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onNotify messages from the relay
|
||||
* Listens to INostrClient's onNotify messages from the relay
|
||||
*/
|
||||
class RelayNotifier(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val notify: (message: String, relay: IRelayClient) -> Unit,
|
||||
) {
|
||||
companion object {
|
||||
|
||||
+3
-3
@@ -20,17 +20,17 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.accessories
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onNotify messages from the relay
|
||||
* Listens to INostrClient's onNotify messages from the relay
|
||||
*/
|
||||
class RelayOfflineTracker(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
companion object {
|
||||
const val TAG = "RelayOfflineTracker"
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.auth
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.AuthMessage
|
||||
@@ -46,7 +46,7 @@ object EmptyIAuthStatus : IAuthStatus {
|
||||
}
|
||||
|
||||
class RelayAuthenticator(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
|
||||
val signWithAllLoggedInUsers: suspend (EventTemplate<RelayAuthEvent>) -> List<RelayAuthEvent>,
|
||||
) : IAuthStatus {
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.counts
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.ClosedMessage
|
||||
@@ -33,7 +33,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
class RelayActiveCountStates(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
private var queryStates = mutableMapOf<NormalizedRelayUrl, CountQueryState<String>>()
|
||||
|
||||
|
||||
+3
-3
@@ -193,7 +193,7 @@ class PoolRequests {
|
||||
state?.onNewEvent(relay.url)
|
||||
desiredSubListeners.get(msg.subId)?.onEvent(
|
||||
event = msg.event,
|
||||
isRealTime = state?.currentState(relay.url) == ReqSubStatus.LIVE,
|
||||
isLive = state?.currentState(relay.url) == ReqSubStatus.LIVE,
|
||||
relay = relay.url,
|
||||
forFilters = state?.lastKnownFilterStates(relay.url),
|
||||
)
|
||||
@@ -201,8 +201,8 @@ class PoolRequests {
|
||||
|
||||
is EoseMessage -> {
|
||||
val state = relayState.get(msg.subId)
|
||||
state?.onCaughtUp(relay.url)
|
||||
desiredSubListeners.get(msg.subId)?.onCaughtUp(
|
||||
state?.onEose(relay.url)
|
||||
desiredSubListeners.get(msg.subId)?.onEose(
|
||||
relay = relay.url,
|
||||
forFilters = state?.lastKnownFilterStates(relay.url),
|
||||
)
|
||||
|
||||
+4
-4
@@ -21,13 +21,13 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.reqs
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.RandomInstance
|
||||
|
||||
class DynamicSubscription(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val filter: () -> Map<NormalizedRelayUrl, List<Filter>>,
|
||||
val onEvent: (event: Event) -> Unit = {},
|
||||
) : SubscriptionListener,
|
||||
@@ -36,7 +36,7 @@ class DynamicSubscription(
|
||||
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -56,7 +56,7 @@ class DynamicSubscription(
|
||||
}
|
||||
}
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
filters: () -> Map<NormalizedRelayUrl, List<Filter>>,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
): SubscriptionHandle = DynamicSubscription(this, filters, onEvent)
|
||||
|
||||
+7
-7
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip01Core.relay.client.reqs
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
@@ -37,22 +37,22 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
* 3. Closes the flow (completes) when the relay sends EOSE,
|
||||
* cancelling the subscription automatically via [awaitClose].
|
||||
*/
|
||||
fun NostrClient.fetchAsFlow(
|
||||
fun INostrClient.fetchAsFlow(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
) = fetchAsFlow(RelayUrlNormalizer.normalize(relay), filters)
|
||||
|
||||
fun NostrClient.fetchAsFlow(
|
||||
fun INostrClient.fetchAsFlow(
|
||||
relay: String,
|
||||
filter: Filter,
|
||||
) = fetchAsFlow(RelayUrlNormalizer.normalize(relay), listOf(filter))
|
||||
|
||||
fun NostrClient.fetchAsFlow(
|
||||
fun INostrClient.fetchAsFlow(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
) = fetchAsFlow(relay, listOf(filter))
|
||||
|
||||
fun NostrClient.fetchAsFlow(
|
||||
fun INostrClient.fetchAsFlow(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
): Flow<List<Event>> =
|
||||
@@ -65,7 +65,7 @@ fun NostrClient.fetchAsFlow(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -76,7 +76,7 @@ fun NostrClient.fetchAsFlow(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+7
-7
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip01Core.relay.client.reqs
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
@@ -42,22 +42,22 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
* - They will be ignored if they are already in the list.
|
||||
* - They will be added to the beginning of the list if they are new.
|
||||
*/
|
||||
fun NostrClient.subscribeAsFlow(
|
||||
fun INostrClient.subscribeAsFlow(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
) = subscribeAsFlow(RelayUrlNormalizer.normalize(relay), filters)
|
||||
|
||||
fun NostrClient.subscribeAsFlow(
|
||||
fun INostrClient.subscribeAsFlow(
|
||||
relay: String,
|
||||
filter: Filter,
|
||||
) = subscribeAsFlow(RelayUrlNormalizer.normalize(relay), listOf(filter))
|
||||
|
||||
fun NostrClient.subscribeAsFlow(
|
||||
fun INostrClient.subscribeAsFlow(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
) = subscribeAsFlow(relay, listOf(filter))
|
||||
|
||||
fun NostrClient.subscribeAsFlow(
|
||||
fun INostrClient.subscribeAsFlow(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
): Flow<List<Event>> =
|
||||
@@ -71,7 +71,7 @@ fun NostrClient.subscribeAsFlow(
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -90,7 +90,7 @@ fun NostrClient.subscribeAsFlow(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.reqs
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.ClosedMessage
|
||||
@@ -34,7 +34,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
class RelayActiveRequestStates(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
private var subStates = mutableMapOf<NormalizedRelayUrl, RequestSubscriptionState<String>>()
|
||||
|
||||
@@ -53,7 +53,7 @@ class RelayActiveRequestStates(
|
||||
) {
|
||||
when (msg) {
|
||||
is EventMessage -> subGetOrCreate(relay.url).onNewEvent(msg.subId)
|
||||
is EoseMessage -> subGetOrCreate(relay.url).onCaughtUp(msg.subId)
|
||||
is EoseMessage -> subGetOrCreate(relay.url).onEose(msg.subId)
|
||||
is ClosedMessage -> subGetOrCreate(relay.url).onClosed(msg.subId)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class RequestSubscriptionState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fun onCaughtUp(reference: T) {
|
||||
fun onEose(reference: T) {
|
||||
subStates[reference] = ReqSubStatus.LIVE
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -21,14 +21,14 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.reqs
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import com.vitorpamplona.quartz.utils.RandomInstance
|
||||
|
||||
class StaticSubscription(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val filter: Map<NormalizedRelayUrl, List<Filter>>,
|
||||
val onEvent: (event: Event) -> Unit = {},
|
||||
) : SubscriptionListener,
|
||||
@@ -37,7 +37,7 @@ class StaticSubscription(
|
||||
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
@@ -57,25 +57,25 @@ class StaticSubscription(
|
||||
}
|
||||
}
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relay: NormalizedRelayUrl,
|
||||
filters: List<Filter>,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
): SubscriptionHandle = StaticSubscription(this, mapOf(relay to filters), onEvent)
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relay: NormalizedRelayUrl,
|
||||
filter: Filter,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
): SubscriptionHandle = StaticSubscription(this, mapOf(relay to listOf(filter)), onEvent)
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
filters: List<Filter>,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
): SubscriptionHandle = StaticSubscription(this, relays.associateWith { filters }, onEvent)
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relays: List<NormalizedRelayUrl>,
|
||||
filter: Filter,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
@@ -84,13 +84,13 @@ fun NostrClient.subscribe(
|
||||
// -----------------------------------
|
||||
// Helper methods with relay as string
|
||||
// -----------------------------------
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relay: String,
|
||||
filters: List<Filter>,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
): SubscriptionHandle = StaticSubscription(this, mapOf(RelayUrlNormalizer.normalize(relay) to filters), onEvent)
|
||||
|
||||
fun NostrClient.subscribe(
|
||||
fun INostrClient.subscribe(
|
||||
relay: String,
|
||||
filter: Filter,
|
||||
onEvent: (event: Event) -> Unit = {},
|
||||
|
||||
+2
-2
@@ -25,14 +25,14 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
|
||||
interface SubscriptionListener {
|
||||
fun onCaughtUp(
|
||||
fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {}
|
||||
|
||||
fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.reqs.stats
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EventMessage
|
||||
@@ -28,10 +28,10 @@ import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.Message
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
|
||||
/**
|
||||
* Listens to NostrClient's onNotify messages from the relay
|
||||
* Listens to INostrClient's onNotify messages from the relay
|
||||
*/
|
||||
class RelayReqStats(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
private val stats = ReqStatsRepository()
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.stats
|
||||
|
||||
import androidx.collection.LruCache
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.ClosedMessage
|
||||
@@ -35,7 +35,7 @@ import com.vitorpamplona.quartz.utils.Log
|
||||
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
|
||||
class RelayStats(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
private val innerCache =
|
||||
object : LruCache<NormalizedRelayUrl, RelayStat>(1000) {
|
||||
|
||||
+3
-3
@@ -20,14 +20,14 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.client.subscriptions
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.cache.LargeCache
|
||||
|
||||
/**
|
||||
* Manages Nostr subscriptions using a [NostrClient], allowing subscriptions to be created, modified,
|
||||
* Manages Nostr subscriptions using a [INostrClient], allowing subscriptions to be created, modified,
|
||||
* and synchronized with relay filters. Subscriptions are stored in a cache and processed through
|
||||
* [updateRelays] to update relay filters dynamically. Also tracks event statistics and EOSE (End of
|
||||
* Stored Events) events, and provides utility methods to interact with subscriptions like dismissal.
|
||||
@@ -45,7 +45,7 @@ import com.vitorpamplona.quartz.utils.cache.LargeCache
|
||||
* - Dismiss subscriptions with [dismissSubscription].
|
||||
*/
|
||||
class SubscriptionController(
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
) {
|
||||
private val subscriptions = LargeCache<String, Subscription>()
|
||||
|
||||
|
||||
+2
-2
@@ -54,13 +54,13 @@ class LiveEventStore(
|
||||
suspend fun query(
|
||||
filters: List<Filter>,
|
||||
onEach: (Event) -> Unit,
|
||||
onCaughtUp: () -> Unit,
|
||||
onEose: () -> Unit,
|
||||
) {
|
||||
// 1. Replay stored events matching filters.
|
||||
store.query(filters, onEach)
|
||||
|
||||
// 2. Signal end of stored events.
|
||||
onCaughtUp()
|
||||
onEose()
|
||||
|
||||
// 3. Stream live events until cancelled.
|
||||
newEventStream.collect { newEvent ->
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ class RelaySession(
|
||||
send(EventMessage(cmd.subId, event))
|
||||
}
|
||||
},
|
||||
onCaughtUp = { send(EoseMessage(cmd.subId)) },
|
||||
onEose = { send(EoseMessage(cmd.subId)) },
|
||||
)
|
||||
} catch (_: kotlinx.coroutines.CancellationException) {
|
||||
// Subscription was closed – this is expected.
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip46RemoteSigner.signer
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.StaticSubscription
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -52,7 +52,7 @@ class NostrSignerRemote(
|
||||
val signer: NostrSignerInternal,
|
||||
val remotePubkey: HexKey,
|
||||
val relays: Set<NormalizedRelayUrl>,
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val permissions: String? = null,
|
||||
val secret: String? = null,
|
||||
) : NostrSigner(signer.pubKey) {
|
||||
@@ -296,7 +296,7 @@ class NostrSignerRemote(
|
||||
fun fromBunkerUri(
|
||||
bunkerUri: String,
|
||||
signer: NostrSignerInternal,
|
||||
client: NostrClient,
|
||||
client: INostrClient,
|
||||
permissions: String? = null,
|
||||
): NostrSignerRemote {
|
||||
if (!bunkerUri.startsWith("bunker://")) throw Exception("Invalid bunker uri")
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.nip46RemoteSigner.signer
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.OptimizedJsonMapper
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequest
|
||||
@@ -34,7 +34,7 @@ import kotlin.coroutines.resume
|
||||
|
||||
class RemoteSignerManager(
|
||||
val timeout: Long = 30000,
|
||||
val client: NostrClient,
|
||||
val client: INostrClient,
|
||||
val signer: NostrSignerInternal,
|
||||
val remoteKey: String,
|
||||
val relayList: Set<NormalizedRelayUrl>,
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ interface INegentropyListener {
|
||||
* per relay and subscription ID.
|
||||
*
|
||||
* Usage:
|
||||
* 1. Register this as a listener on the NostrClient
|
||||
* 1. Register this as a listener on the INostrClient
|
||||
* 2. Call [startSync] with a filter and local events to begin reconciliation
|
||||
* 3. Receive results via [INegentropyListener] callbacks
|
||||
*/
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ package com.vitorpamplona.quartz.nip46RemoteSigner.signer
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
@@ -37,10 +37,10 @@ import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* NostrClient that records subscribe calls for verification.
|
||||
* INostrClient that records subscribe calls for verification.
|
||||
* Used instead of mockk since commonTest doesn't have mockk.
|
||||
*/
|
||||
private class TrackingNostrClient : NostrClient {
|
||||
private class TrackingNostrClient : INostrClient {
|
||||
data class SubscriptionRecord(
|
||||
val subId: String,
|
||||
val filters: Map<NormalizedRelayUrl, List<Filter>>,
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.fetchFirst
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -36,7 +35,7 @@ class NostrClientFirstEventTest : BaseNostrClientTest() {
|
||||
fun testDownloadFirstEvent() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val event =
|
||||
client.fetchFirst(
|
||||
|
||||
+3
-4
@@ -21,7 +21,6 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.SubscriptionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
@@ -42,7 +41,7 @@ class NostrClientManualSubTest : BaseNostrClientTest() {
|
||||
fun testEoseAfter100Events() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val resultChannel = Channel<String>(UNLIMITED)
|
||||
val events = mutableListOf<String>()
|
||||
@@ -52,14 +51,14 @@ class NostrClientManualSubTest : BaseNostrClientTest() {
|
||||
object : SubscriptionListener {
|
||||
override fun onEvent(
|
||||
event: Event,
|
||||
isRealTime: Boolean,
|
||||
isLive: Boolean,
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
resultChannel.trySend(event.id)
|
||||
}
|
||||
|
||||
override fun onCaughtUp(
|
||||
override fun onEose(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
|
||||
+3
-4
@@ -19,7 +19,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.count
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
|
||||
@@ -42,7 +41,7 @@ class NostrClientQueryCountTest : BaseNostrClientTest() {
|
||||
fun testQueryCountSuspend() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val result = client.count(fiatjaf, metadata)
|
||||
|
||||
@@ -56,7 +55,7 @@ class NostrClientQueryCountTest : BaseNostrClientTest() {
|
||||
fun testQueryCountSuspendAllEvents() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val result = client.count(fiatjaf, Filter())
|
||||
|
||||
@@ -70,7 +69,7 @@ class NostrClientQueryCountTest : BaseNostrClientTest() {
|
||||
fun testQueryCountSuspendMultipleRelays() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val results =
|
||||
client.count(
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.listeners.RelayConnectionListener
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.commands.toClient.EoseMessage
|
||||
@@ -48,7 +47,7 @@ class NostrClientRepeatSubTest : BaseNostrClientTest() {
|
||||
fun testRepeatSubEvents() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val resultChannel = Channel<String>(UNLIMITED)
|
||||
val events = mutableListOf<String>()
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.fetchAllPages
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
|
||||
@@ -39,7 +38,7 @@ class NostrClientReqBypassingRelayLimitsTest : BaseNostrClientTest() {
|
||||
fun testDownloadFromRelayReturnsMetadataEvents() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val events = mutableListOf<Event>()
|
||||
|
||||
@@ -73,7 +72,7 @@ class NostrClientReqBypassingRelayLimitsTest : BaseNostrClientTest() {
|
||||
fun testDownloadFromRelayReturnsMetadataAndContactListEvents() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val metadataEvents = mutableListOf<Event>()
|
||||
val contactListEvents = mutableListOf<Event>()
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.publishAndConfirm
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerInternal
|
||||
@@ -38,7 +37,7 @@ class NostrClientSendAndWaitTest : BaseNostrClientTest() {
|
||||
fun testSendAndWaitForResponse() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val randomSigner = NostrSignerInternal(KeyPair())
|
||||
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.subscribeAsFlow
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
@@ -49,7 +48,7 @@ class NostrClientSubscriptionAsFlowTest : BaseNostrClientTest() {
|
||||
fun testNostrClientSubscriptionAsFlow() =
|
||||
runTest {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val flow =
|
||||
client.subscribeAsFlow(
|
||||
@@ -88,7 +87,7 @@ class NostrClientSubscriptionAsFlowTest : BaseNostrClientTest() {
|
||||
fun testNostrClientSubscriptionAsFlowDebouncing() =
|
||||
runTest {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val flow =
|
||||
client.subscribeAsFlow(
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.StaticSubscription
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
@@ -41,7 +40,7 @@ class NostrClientSubscriptionTest : BaseNostrClientTest() {
|
||||
fun testNostrClientSubscription() =
|
||||
runBlocking {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val resultChannel = Channel<Event>(UNLIMITED)
|
||||
val events = mutableSetOf<Event>()
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@
|
||||
package com.vitorpamplona.quartz.nip01Core.relay
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.DefaultNostrClient
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.client.reqs.fetchAsFlow
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
@@ -49,7 +48,7 @@ class NostrClientSubscriptionUntilEoseAsFlowTest : BaseNostrClientTest() {
|
||||
fun testNostrClientSubscriptionUntilEoseAsFlow() =
|
||||
runTest {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val flow =
|
||||
client.fetchAsFlow(
|
||||
@@ -88,7 +87,7 @@ class NostrClientSubscriptionUntilEoseAsFlowTest : BaseNostrClientTest() {
|
||||
fun testNostrClientSubscriptionUntilEoseAsFlowDebouncing() =
|
||||
runTest {
|
||||
val appScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||
val client = DefaultNostrClient(socketBuilder, appScope)
|
||||
val client = NostrClient(socketBuilder, appScope)
|
||||
|
||||
val flow =
|
||||
client.fetchAsFlow(
|
||||
|
||||
Reference in New Issue
Block a user