Simple refactoring for the name of the subscription cache

This commit is contained in:
Vitor Pamplona
2025-05-14 10:43:42 -04:00
parent 52d31502e6
commit 2c06df7e50
4 changed files with 35 additions and 14 deletions

View File

@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.ammolite.relays
class MutableSubscriptionManager : SubscriptionManager {
class MutableSubscriptionCache : SubscriptionCache {
private var subscriptions = mapOf<String, List<TypedFilter>>()
fun add(
@@ -42,13 +42,3 @@ class MutableSubscriptionManager : SubscriptionManager {
override fun getSubscriptionFiltersOrNull(subId: String): List<TypedFilter>? = subscriptions[subId]
}
interface SubscriptionManager {
fun isActive(subscriptionId: String): Boolean
fun allSubscriptions(): Map<String, List<TypedFilter>>
fun getSubscriptionFilters(subId: String): List<TypedFilter>
fun getSubscriptionFiltersOrNull(subId: String): List<TypedFilter>
}

View File

@@ -41,7 +41,7 @@ class NostrClient(
private val websocketBuilder: WebsocketBuilderFactory,
) : RelayPool.Listener {
private val relayPool: RelayPool = RelayPool()
private val activeSubscriptions: MutableSubscriptionManager = MutableSubscriptionManager()
private val activeSubscriptions: MutableSubscriptionCache = MutableSubscriptionCache()
private var listeners = setOf<Listener>()
fun buildRelay(it: RelaySetupInfoToConnect): Relay = Relay(it.url, it.read, it.write, it.forceProxy, it.feedTypes, websocketBuilder, activeSubscriptions)

View File

@@ -49,7 +49,7 @@ val EVENT_FINDER_TYPES =
class RelaySubFilter(
val url: String,
val activeTypes: Set<FeedType>,
val subs: SubscriptionManager,
val subs: SubscriptionCache,
) : SubscriptionCollection {
fun isMatch(filter: TypedFilter) = activeTypes.any { it in filter.types } && filter.isValidFor(url)
@@ -95,7 +95,7 @@ class Relay(
val forceProxy: Boolean = false,
val activeTypes: Set<FeedType>,
socketBuilderFactory: WebsocketBuilderFactory,
subs: SubscriptionManager,
subs: SubscriptionCache,
) : SimpleClientRelay.Listener {
private var listeners = setOf<Listener>()

View File

@@ -0,0 +1,31 @@
/**
* 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
interface SubscriptionCache {
fun isActive(subscriptionId: String): Boolean
fun allSubscriptions(): Map<String, List<TypedFilter>>
fun getSubscriptionFilters(subId: String): List<TypedFilter>
fun getSubscriptionFiltersOrNull(subId: String): List<TypedFilter>?
}