Bug fix relay management

This commit is contained in:
Kgothatso Ngako
2026-05-04 00:08:03 +02:00
parent db679535aa
commit f62e04d73b
4 changed files with 10 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package ac.cord.auxiliary.compose.network.dto
import ac.cord.auxiliary.compose.database.model.Relay
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import kotlinx.serialization.Serializable
@Serializable
@@ -9,7 +10,6 @@ data class RelayDTO(
val read: Boolean,
val write: Boolean,
) {
}
fun Relay.mapToRelayDTO() =

View File

@@ -117,10 +117,13 @@ class RelayPool(
}
fun addRelaysIfMissing(relays: Set<RelayDTO>) {
val existingRelayUrls = socketClients.map { it.socketUrl }
logger.d("addRelaysIfMissing: ${relays.map { it.url }}")
val existingRelayUrls = socketClients.map { NormalizedRelayUrl(it.socketUrl).displayUrl() }
logger.d("Existing Relays: $existingRelayUrls")
val newRelayUrls = relays.map { it.url }
val toAddRelayUrls = newRelayUrls.filter { it !in existingRelayUrls }.toSet()
val toAddRelayUrls = newRelayUrls.filter { NormalizedRelayUrl(it).displayUrl() !in existingRelayUrls }.toSet()
logger.d("toAddRelayUrls: $toAddRelayUrls")
val toAddSocketClients = relays.filter { it.url in toAddRelayUrls }.mapAsNostrSocketClient()
logger.d("toAddSocketClients: ${toAddSocketClients.map { it.socketUrl }}" )
val newSocketClients = socketClients.toMutableSet().apply {

View File

@@ -134,7 +134,7 @@ class RelaysSocketManager constructor(
}
}
suspend fun tryConnectingToUserRelay(url: String) = relayPool.tryConnectingToRelay(url)
// suspend fun tryConnectingToUserRelay(url: String) = relayPool.tryConnectingToRelay(url)
suspend fun query(reqCommand: ReqCmd, relayUrl: String): Flow<NostrIncomingMessage> {
return relayPool.query(

View File

@@ -2,6 +2,8 @@ package ac.cord.auxiliary.compose.network.sockets
import ac.cord.auxiliary.compose.exceptions.NetworkException
import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import fr.acinq.lightning.channel.states.Normal
import io.ktor.client.HttpClient
import io.ktor.client.plugins.websocket.webSocketSession
import io.ktor.websocket.CloseReason
@@ -61,7 +63,7 @@ internal class NostrSocketClientImpl(
wsMutex.withLock {
if (wsSession == null || wsSession?.isActive == false) {
wsSession = acquireWebSocketSession(url = socketUrl)
wsSession = acquireWebSocketSession(socketUrl)
}
}
}