Skip to content

Commit

Permalink
Changes for v1.0-beta-14.
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinGeekDev authored Feb 19, 2025
2 parents 39c5de6 + 6b174bf commit 2385edf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-13")
implementation("io.github.kotlingeekdev:rhodium:1.0-beta-14")

}
```
Expand Down Expand Up @@ -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-13")
implementation("com.github.KotlinGeekDev.Rhodium:rhodium:1.0-beta-14")


}
Expand All @@ -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-13")
implementation("com.github.KotlinGeekDev.Rhodium:rhodium-android:1.0-beta-14")

}
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {
val isJitpack = System.getenv("JITPACK") == "true"

group = "io.github.kotlingeekdev"
version = "1.0-beta-13"
version = "1.0-beta-14"


// val javadocJar = tasks.register<Jar>("javadocJar") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import rhodium.logging.serviceLogger
import rhodium.nostr.*
import rhodium.nostr.client.ClientMessage
import rhodium.nostr.client.RequestMessage
import rhodium.nostr.events.MetadataEvent
import rhodium.nostr.relay.*
import kotlin.coroutines.CoroutineContext

Expand Down Expand Up @@ -198,6 +199,7 @@ class NostrService(

is RelayNotice -> {
serviceLogger.i("Received a relay notice: $message")
if (message.message.contains("ERROR")) break
}
}

Expand Down Expand Up @@ -229,7 +231,7 @@ class NostrService(
return results
}

suspend fun getMetadataFor(profileHex: String, preferredRelays: List<String>): Event {
suspend fun getMetadataFor(profileHex: String, preferredRelays: List<String>): MetadataEvent {
val profileRequest = RequestMessage.singleFilterRequest(
filter = NostrFilter.newFilter()
.kinds(EventKind.METADATA.kind)
Expand All @@ -241,6 +243,7 @@ class NostrService(
requestWithResult(profileRequest) else requestWithResult(profileRequest, preferredRelays.map { Relay(it) })

return potentialResults.maxBy { it.creationDate }
.let { MetadataEvent(it.id, it.pubkey, it.creationDate, it.tags, it.content, it.eventSignature) }
}

suspend fun fetchRelayListFor(profileHex: String, fetchRelays: List<String>): List<Relay> {
Expand Down
11 changes: 7 additions & 4 deletions rhodium-core/src/commonMain/kotlin/rhodium/nostr/Event.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

package rhodium.nostr

import rhodium.crypto.CryptoUtils
import rhodium.crypto.toHexString
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import rhodium.crypto.CryptoUtils
import rhodium.crypto.toHexString

/**
* The Event class representing the Nostr Event.
Expand All @@ -22,15 +22,18 @@ import kotlinx.serialization.json.buildJsonArray
* @param eventSignature The event's signature, as a 64-byte string
*/
@Serializable
data class Event(
open class Event(
val id: String,
val pubkey: String,
@SerialName("created_at") val creationDate: Long,
@SerialName("kind") val eventKind: Int,
val tags: List<Tag>,
val content: String,
@SerialName("sig") val eventSignature: String
)
){
override fun toString(): String =
"Event(id=$id, pubkey=$pubkey, creationDate=$creationDate, eventKind=$eventKind, tags=$tags, content=$content, eventSignature=$eventSignature)"
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import rhodium.crypto.CryptoUtils

internal val eventMapper = Json
internal val eventMapper = Json { ignoreUnknownKeys = true }
@OptIn(ExperimentalSerializationApi::class)
internal val arraySerializer: KSerializer<Array<String>> = ArraySerializer(String.serializer())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
import rhodium.crypto.toHexString
import rhodium.nostr.Event
import rhodium.nostr.NostrFilter

Expand Down Expand Up @@ -115,7 +114,7 @@ open class RequestMessage(

companion object {
fun singleFilterRequest(
subscriptionId: String = uuid4().bytes.toHexString().substring(0, 5),
subscriptionId: String = uuid4().bytes.decodeToString().substring(0, 5),
filter: NostrFilter
): RequestMessage {
return RequestMessage(messageType = "REQ", subscriptionId, listOf(filter))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package rhodium.nostr.events

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import rhodium.nostr.Event
import rhodium.nostr.EventKind
import rhodium.nostr.Tag
import rhodium.nostr.eventMapper


class MetadataEvent(
id: String,
pubkey: String,
creationDate: Long,
tags: List<Tag>,
content: String,
signature: String
): Event(id, pubkey, creationDate, eventKind = EventKind.METADATA.kind, tags, content, signature) {

fun userInfo(): UserInfo = eventMapper.decodeFromString(content)

}

@Serializable()
data class UserInfo(
val name: String,
@SerialName("display_name") val displayName: String? = null,
val about: String?,
val picture: String? = null,
val banner: String? = null,
@SerialName("nip05") val address: String? = null,
val website: String? = null,
)

0 comments on commit 2385edf

Please sign in to comment.