mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-13 16:37:52 +01:00
Avoids sending an NWC filter when there are no keys subscribed to it
This commit is contained in:
@@ -37,25 +37,37 @@ class NWCPaymentQueryState(
|
|||||||
class NWCPaymentFilterAssembler(
|
class NWCPaymentFilterAssembler(
|
||||||
client: NostrClient,
|
client: NostrClient,
|
||||||
) : QueryBasedSubscriptionOrchestrator<NWCPaymentQueryState>(client) {
|
) : QueryBasedSubscriptionOrchestrator<NWCPaymentQueryState>(client) {
|
||||||
fun createAccountMetadataFilter(keys: Set<NWCPaymentQueryState>): TypedFilter =
|
fun createAccountMetadataFilter(keys: Set<NWCPaymentQueryState>): TypedFilter? {
|
||||||
TypedFilter(
|
val fromAuthors = keys.mapTo(mutableSetOf()) { it.fromServiceHex }
|
||||||
|
val replyingToPayments = keys.mapTo(mutableSetOf()) { it.replyingToHex }
|
||||||
|
val aboutUsers = keys.mapTo(mutableSetOf()) { it.toUserHex }
|
||||||
|
|
||||||
|
if (fromAuthors.isEmpty()) return null
|
||||||
|
|
||||||
|
return TypedFilter(
|
||||||
types = setOf(FeedType.WALLET_CONNECT),
|
types = setOf(FeedType.WALLET_CONNECT),
|
||||||
filter =
|
filter =
|
||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(LnZapPaymentResponseEvent.KIND),
|
kinds = listOf(LnZapPaymentResponseEvent.KIND),
|
||||||
authors = keys.map { it.fromServiceHex },
|
authors = fromAuthors.toList(),
|
||||||
tags =
|
tags =
|
||||||
mapOf(
|
mapOf(
|
||||||
"e" to keys.map { it.replyingToHex },
|
"e" to replyingToPayments.toList(),
|
||||||
"p" to keys.map { it.toUserHex },
|
"p" to aboutUsers.toList(),
|
||||||
),
|
),
|
||||||
limit = 1,
|
limit = 1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val channel = requestNewSubscription()
|
val channel = requestNewSubscription()
|
||||||
|
|
||||||
override fun updateSubscriptions(keys: Set<NWCPaymentQueryState>) {
|
override fun updateSubscriptions(keys: Set<NWCPaymentQueryState>) {
|
||||||
channel.typedFilters = listOf(createAccountMetadataFilter(keys))
|
val filter = createAccountMetadataFilter(keys)
|
||||||
|
if (filter != null) {
|
||||||
|
channel.typedFilters = listOf(filter)
|
||||||
|
} else {
|
||||||
|
channel.typedFilters = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user