diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 52b3eed..3403d27 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -24,7 +24,7 @@ kotlin { implementation(libs.jetbrains.navigation3.ui) implementation(libs.jetbrains.lifecycle.viewmodelNavigation3) implementation(libs.androidx.core.splashscreen) - implementation("su.reya:nostr-sdk-kmp:0.2.6") + implementation("su.reya:nostr-sdk-kmp:0.2.7") implementation("io.coil-kt.coil3:coil-compose:3.4.0") implementation("io.coil-kt.coil3:coil-network-okhttp:3.4.0") implementation("io.github.kalinjul.easyqrscan:scanner:0.7.0") diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 8a5b486..f8e160e 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -33,7 +33,7 @@ kotlin { implementation(libs.androidx.lifecycle.runtimeCompose) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.8.0") - implementation("su.reya:nostr-sdk-kmp:0.2.6") + implementation("su.reya:nostr-sdk-kmp:0.2.7") implementation("com.squareup.okio:okio:3.16.2") } androidMain.dependencies { diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt index 193e135..c029d97 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -385,6 +385,7 @@ class Nostr { // Construct reference tags val tags = listOf( Tag.identifier(giftId.toHex()), + Tag.publicKey(rumor.author()), Tag.event(rumor.id()!!), Tag.custom("r", listOf(roomId.toString())), Tag.custom("k", listOf("14")) @@ -405,16 +406,18 @@ class Nostr { } private suspend fun extractRumor(event: Event): UnsignedEvent? { - // Check if the rumor is already cached - val cachedRumor = getCachedRumor(event.id()) - if (cachedRumor != null) return cachedRumor - - // Try to unwrap the gift with each signer try { + // Check if the rumor is already cached + val cachedRumor = getCachedRumor(event.id()) + if (cachedRumor != null) return cachedRumor + + // Unwrap the gift with current signer val gift = UnwrappedGift.fromGiftWrapAsync(signer = signer, giftWrap = event) val rumor = gift.rumor() + // Save the rumor to the database setCachedRumor(event.id(), rumor) + // Return the rumor return rumor } catch (e: Exception) { @@ -676,12 +679,14 @@ class Nostr { suspend fun getChatRooms(): Set? { try { - val userPubkey = signer.currentUser ?: throw IllegalStateException("User not signed in") + val userPubkey = + signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in") + val kind = Kind.fromStd(KindStandard.APPLICATION_SPECIFIC_DATA) val kTag = SingleLetterTag.lowercase(Alphabet.K) // Get all events sent by the user - val filter = Filter().kind(kind).author(userPubkey).customTags(kTag, listOf("14", "dm")) + val filter = Filter().kind(kind).pubkey(userPubkey).customTags(kTag, listOf("14", "dm")) val events = client?.database()?.query(filter) // Collect rooms @@ -697,8 +702,9 @@ class Nostr { // Check if the room already exists if (existingRoom == null || newRoom.createdAt.asSecs() > existingRoom.createdAt.asSecs()) { - val filter = - Filter().kind(kind).author(userPubkey).pubkeys(newRoom.members.toList()) + val kind = Kind.fromStd(KindStandard.PRIVATE_DIRECT_MESSAGE) + val pubkeys = newRoom.members.toList() + val filter = Filter().kind(kind).author(userPubkey).pubkeys(pubkeys) // Determine if it's an ongoing room val isOngoing = client?.database()?.query(filter)?.isEmpty() == false @@ -779,7 +785,7 @@ class Nostr { ) { try { val currentUser = - signer.currentUser ?: throw IllegalStateException("User not signed in") + signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in") val tags = mutableListOf() @@ -806,6 +812,7 @@ class Nostr { val rumor = EventBuilder(Kind.fromStd(KindStandard.PRIVATE_DIRECT_MESSAGE), content) .tags(tags) .finalizeUnsigned(currentUser) + .ensureId() // Emit the rumor to the chat screen if (receiver == currentUser) {