Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes for v1.0-beta-14 #32

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)