Merge pull request #854 from jeremyd/main

allow relay selection dialog to pick any relays
This commit is contained in:
Vitor Pamplona 2024-05-13 10:47:17 -04:00 committed by GitHub
commit fb9ad2b457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 2 deletions

View File

@ -2435,6 +2435,10 @@ class Account(
return (activeRelays() ?: convertLocalRelays()).filter { it.write }
}
fun activeAllRelays(): List<Relay> {
return ((activeRelays() ?: convertLocalRelays()).toList())
}
fun isAllHidden(users: Set<HexKey>): Boolean {
return users.all { isHidden(it) }
}

View File

@ -449,6 +449,38 @@ class Relay(
}
}
// This function sends the event regardless of the relay being write or not.
fun sendOverride(signedEvent: EventInterface) {
checkNotInMainThread()
if (signedEvent is RelayAuthEvent) {
authResponse.put(signedEvent.id, false)
// specific protocol for this event.
val event = """["AUTH",${signedEvent.toJson()}]"""
socket?.send(event)
eventUploadCounterInBytes += event.bytesUsedInMemory()
} else {
val event = """["EVENT",${signedEvent.toJson()}]"""
if (isConnected()) {
if (isReady) {
socket?.send(event)
eventUploadCounterInBytes += event.bytesUsedInMemory()
}
} else {
// sends all filters after connection is successful.
connectAndRun {
checkNotInMainThread()
socket?.send(event)
eventUploadCounterInBytes += event.bytesUsedInMemory()
// Sends everything.
renewFilters()
}
}
}
}
fun send(signedEvent: EventInterface) {
checkNotInMainThread()

View File

@ -150,13 +150,17 @@ object RelayPool : Relay.Listener {
list: List<Relay>,
signedEvent: EventInterface,
) {
list.forEach { relay -> relays.filter { it.url == relay.url }.forEach { it.send(signedEvent) } }
list.forEach { relay -> relays.filter { it.url == relay.url }.forEach { it.sendOverride(signedEvent) } }
}
fun send(signedEvent: EventInterface) {
relays.forEach { it.send(signedEvent) }
}
fun sendOverride(signedEvent: EventInterface) {
relays.forEach { it.sendOverride(signedEvent) }
}
fun close(subscriptionId: String) {
relays.forEach { it.close(subscriptionId) }
}

View File

@ -78,7 +78,7 @@ fun RelaySelectionDialog(
var relays by remember {
mutableStateOf(
accountViewModel.account.activeWriteRelays().map {
accountViewModel.account.activeAllRelays().map {
RelayList(
relay = it,
relayInfo = RelayBriefInfoCache.RelayBriefInfo(it.url),