diff --git a/README.md b/README.md index 0b952ec..dc5c204 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ You can include the library from either Maven Central or Jitpack. You can include the library in the common source set like this: ```kotlin dependencies { - implementation("io.github.kotlingeekdev:rhodium:1.0-beta-12") + implementation("io.github.kotlingeekdev:rhodium:1.0-beta-13") } ``` @@ -74,7 +74,7 @@ then, in your module's `build.gradle(.kts)`, you need to add: // build.gradle.kts dependencies { //... - implementation("com.github.KotlinGeekDev.Rhodium:rhodium:1.0-beta-12") + implementation("com.github.KotlinGeekDev.Rhodium:rhodium:1.0-beta-13") } @@ -85,7 +85,7 @@ If you're including it in an Android app, you can just add: // app/build.gradle.kts dependencies { //... - implementation("com.github.KotlinGeekDev.Rhodium:rhodium-android:1.0-beta-12") + implementation("com.github.KotlinGeekDev.Rhodium:rhodium-android:1.0-beta-13") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 7f5d11e..9269e06 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,7 +31,7 @@ allprojects { val isJitpack = System.getenv("JITPACK") == "true" group = "io.github.kotlingeekdev" - version = "1.0-beta-12" + version = "1.0-beta-13" // val javadocJar = tasks.register("javadocJar") { diff --git a/rhodium-core/src/commonMain/kotlin/rhodium/net/NostrService.kt b/rhodium-core/src/commonMain/kotlin/rhodium/net/NostrService.kt index c35ccc2..4f8f93b 100644 --- a/rhodium-core/src/commonMain/kotlin/rhodium/net/NostrService.kt +++ b/rhodium-core/src/commonMain/kotlin/rhodium/net/NostrService.kt @@ -243,6 +243,35 @@ class NostrService( return potentialResults.maxBy { it.creationDate } } + suspend fun fetchRelayListFor(profileHex: String, fetchRelays: List): List { + val relayListRequest = RequestMessage.singleFilterRequest( + filter = NostrFilter.newFilter() + .kinds(EventKind.RELAY_LIST.kind) + .authors(profileHex) + .limit(1) + .build() + ) + val potentialResults = if (fetchRelays.isEmpty()) + requestWithResult(relayListRequest) else requestWithResult(relayListRequest, fetchRelays.map { Relay(it) }) + + val mostUpdatedRelayList = potentialResults.maxBy { it.creationDate } + val potentialRelays = mostUpdatedRelayList.tags.filter { tag -> tag.identifier == "r" } + if (potentialRelays.isEmpty()) { + return emptyList() + } + else { + val relays = potentialRelays.map { relayTag -> + Relay( + relayTag.description, + readPolicy = if (relayTag.content == null) true else relayTag.content.contentEquals("read"), + writePolicy = if (relayTag.content == null) true else relayTag.content.contentEquals("write") + ) + } + + return relays + } + } + fun clearRelayPool() { relayPool.clearPool() } diff --git a/rhodium-core/src/commonMain/kotlin/rhodium/nostr/relay/Relay.kt b/rhodium-core/src/commonMain/kotlin/rhodium/nostr/relay/Relay.kt index 676e3c4..0552dfc 100644 --- a/rhodium-core/src/commonMain/kotlin/rhodium/nostr/relay/Relay.kt +++ b/rhodium-core/src/commonMain/kotlin/rhodium/nostr/relay/Relay.kt @@ -10,4 +10,8 @@ class Relay( return Relay(address) } } + + override fun toString(): String { + return "Relay(url=$relayURI, read=$readPolicy, write=$writePolicy)" + } } \ No newline at end of file