Preparing to refactor the Relay classes.
This commit is contained in:
@@ -98,7 +98,7 @@ object Client : RelayPool.Listener {
|
||||
checkNotInMainThread()
|
||||
|
||||
subscriptions = subscriptions + Pair(subscriptionId, filters)
|
||||
RelayPool.sendFilter(subscriptionId)
|
||||
RelayPool.sendFilter(subscriptionId, filters)
|
||||
}
|
||||
|
||||
fun sendFilterOnlyIfDisconnected(
|
||||
@@ -134,7 +134,7 @@ object Client : RelayPool.Listener {
|
||||
newSporadicRelay(
|
||||
relay,
|
||||
feedTypes,
|
||||
onConnected = { relay -> relay.send(signedEvent) },
|
||||
onConnected = { myRelay -> myRelay.send(signedEvent) },
|
||||
onDone = onDone,
|
||||
)
|
||||
}
|
||||
@@ -152,7 +152,9 @@ object Client : RelayPool.Listener {
|
||||
RelayPool.addRelay(relay)
|
||||
|
||||
relay.connectAndRun {
|
||||
allSubscriptions().forEach { relay.sendFilter(requestId = it) }
|
||||
allSubscriptions().forEach {
|
||||
relay.sendFilter(it.key, it.value)
|
||||
}
|
||||
|
||||
onConnected(relay)
|
||||
|
||||
@@ -264,8 +266,8 @@ object Client : RelayPool.Listener {
|
||||
listeners = listeners.minus(listener)
|
||||
}
|
||||
|
||||
fun allSubscriptions(): Set<String> {
|
||||
return subscriptions.keys
|
||||
fun allSubscriptions(): Map<String, List<TypedFilter>> {
|
||||
return subscriptions
|
||||
}
|
||||
|
||||
fun getSubscriptionFilters(subId: String): List<TypedFilter> {
|
||||
|
||||
@@ -344,16 +344,15 @@ class Relay(
|
||||
afterEOSEPerSubscription = LinkedHashMap(afterEOSEPerSubscription.size)
|
||||
}
|
||||
|
||||
fun sendFilter(requestId: String) {
|
||||
fun sendFilter(
|
||||
requestId: String,
|
||||
filters: List<TypedFilter>,
|
||||
) {
|
||||
checkNotInMainThread()
|
||||
|
||||
if (read) {
|
||||
if (isConnected()) {
|
||||
if (isReady) {
|
||||
val filters =
|
||||
Client.getSubscriptionFilters(requestId).filter { filter ->
|
||||
activeTypes.any { it in filter.types }
|
||||
}
|
||||
if (filters.isNotEmpty()) {
|
||||
val request =
|
||||
filters.joinToStringLimited(
|
||||
@@ -423,7 +422,14 @@ class Relay(
|
||||
|
||||
fun renewFilters() {
|
||||
// Force update all filters after AUTH.
|
||||
Client.allSubscriptions().forEach { sendFilter(requestId = it) }
|
||||
Client.allSubscriptions().forEach {
|
||||
val filters =
|
||||
it.value.filter { filter ->
|
||||
activeTypes.any { it in filter.types }
|
||||
}
|
||||
|
||||
sendFilter(requestId = it.key, filters)
|
||||
}
|
||||
}
|
||||
|
||||
fun send(signedEvent: EventInterface) {
|
||||
|
||||
@@ -77,8 +77,11 @@ object RelayPool : Relay.Listener {
|
||||
relays.forEach { it.connect() }
|
||||
}
|
||||
|
||||
fun sendFilter(subscriptionId: String) {
|
||||
relays.forEach { it.sendFilter(subscriptionId) }
|
||||
fun sendFilter(
|
||||
subscriptionId: String,
|
||||
filters: List<TypedFilter>,
|
||||
) {
|
||||
relays.forEach { it.sendFilter(subscriptionId, filters) }
|
||||
}
|
||||
|
||||
fun connectAndSendFiltersIfDisconnected() {
|
||||
|
||||
@@ -356,7 +356,9 @@ private fun RenderRoomTopBar(
|
||||
|
||||
RoomNameOnlyDisplay(
|
||||
room,
|
||||
Modifier.padding(start = 10.dp).weight(1f),
|
||||
Modifier
|
||||
.padding(start = 10.dp)
|
||||
.weight(1f),
|
||||
fontWeight = FontWeight.Normal,
|
||||
accountViewModel.userProfile(),
|
||||
)
|
||||
@@ -504,7 +506,10 @@ fun GenericMainTopBar(
|
||||
) {
|
||||
Box(Modifier) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().fillMaxHeight(),
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
@@ -784,12 +789,14 @@ fun SimpleTextSpinner(
|
||||
}
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.matchParentSize().clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null,
|
||||
) {
|
||||
optionsShowing = true
|
||||
},
|
||||
Modifier
|
||||
.matchParentSize()
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null,
|
||||
) {
|
||||
optionsShowing = true
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -922,13 +929,7 @@ fun AmethystClickableIcon() {
|
||||
|
||||
fun debugState(context: Context) {
|
||||
Client.allSubscriptions()
|
||||
.map {
|
||||
"$it ${
|
||||
Client.getSubscriptionFilters(it)
|
||||
.joinToString { it.filter.toJson() }
|
||||
}"
|
||||
}
|
||||
.forEach { Log.d("STATE DUMP", it) }
|
||||
.forEach { Log.d("STATE DUMP", "${it.key} ${it.value.joinToString { it.filter.toJson() }}") }
|
||||
|
||||
NostrAccountDataSource.printCounter()
|
||||
NostrChannelDataSource.printCounter()
|
||||
|
||||
Reference in New Issue
Block a user