mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-06 18:43:04 +02:00
Simple refactoring for the name of the subscription cache
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.ammolite.relays
|
package com.vitorpamplona.ammolite.relays
|
||||||
|
|
||||||
class MutableSubscriptionManager : SubscriptionManager {
|
class MutableSubscriptionCache : SubscriptionCache {
|
||||||
private var subscriptions = mapOf<String, List<TypedFilter>>()
|
private var subscriptions = mapOf<String, List<TypedFilter>>()
|
||||||
|
|
||||||
fun add(
|
fun add(
|
||||||
@@ -42,13 +42,3 @@ class MutableSubscriptionManager : SubscriptionManager {
|
|||||||
|
|
||||||
override fun getSubscriptionFiltersOrNull(subId: String): List<TypedFilter>? = subscriptions[subId]
|
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>
|
|
||||||
}
|
|
@@ -41,7 +41,7 @@ class NostrClient(
|
|||||||
private val websocketBuilder: WebsocketBuilderFactory,
|
private val websocketBuilder: WebsocketBuilderFactory,
|
||||||
) : RelayPool.Listener {
|
) : RelayPool.Listener {
|
||||||
private val relayPool: RelayPool = RelayPool()
|
private val relayPool: RelayPool = RelayPool()
|
||||||
private val activeSubscriptions: MutableSubscriptionManager = MutableSubscriptionManager()
|
private val activeSubscriptions: MutableSubscriptionCache = MutableSubscriptionCache()
|
||||||
private var listeners = setOf<Listener>()
|
private var listeners = setOf<Listener>()
|
||||||
|
|
||||||
fun buildRelay(it: RelaySetupInfoToConnect): Relay = Relay(it.url, it.read, it.write, it.forceProxy, it.feedTypes, websocketBuilder, activeSubscriptions)
|
fun buildRelay(it: RelaySetupInfoToConnect): Relay = Relay(it.url, it.read, it.write, it.forceProxy, it.feedTypes, websocketBuilder, activeSubscriptions)
|
||||||
|
@@ -49,7 +49,7 @@ val EVENT_FINDER_TYPES =
|
|||||||
class RelaySubFilter(
|
class RelaySubFilter(
|
||||||
val url: String,
|
val url: String,
|
||||||
val activeTypes: Set<FeedType>,
|
val activeTypes: Set<FeedType>,
|
||||||
val subs: SubscriptionManager,
|
val subs: SubscriptionCache,
|
||||||
) : SubscriptionCollection {
|
) : SubscriptionCollection {
|
||||||
fun isMatch(filter: TypedFilter) = activeTypes.any { it in filter.types } && filter.isValidFor(url)
|
fun isMatch(filter: TypedFilter) = activeTypes.any { it in filter.types } && filter.isValidFor(url)
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ class Relay(
|
|||||||
val forceProxy: Boolean = false,
|
val forceProxy: Boolean = false,
|
||||||
val activeTypes: Set<FeedType>,
|
val activeTypes: Set<FeedType>,
|
||||||
socketBuilderFactory: WebsocketBuilderFactory,
|
socketBuilderFactory: WebsocketBuilderFactory,
|
||||||
subs: SubscriptionManager,
|
subs: SubscriptionCache,
|
||||||
) : SimpleClientRelay.Listener {
|
) : SimpleClientRelay.Listener {
|
||||||
private var listeners = setOf<Listener>()
|
private var listeners = setOf<Listener>()
|
||||||
|
|
||||||
|
@@ -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>?
|
||||||
|
}
|
Reference in New Issue
Block a user