diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt index 74ad4e6f..be40fc81 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/dao/NostrDao.kt @@ -10,6 +10,7 @@ import androidx.room.Embedded import androidx.room.Relation import androidx.room.Transaction import co.touchlab.kermit.Logger +import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent import kotlinx.coroutines.delay import kotlin.time.Clock @@ -25,7 +26,7 @@ abstract class NostrDao( relayURLs: List ) { logger.i("Publish Nostr Event: $nostrEvent ($relayURLs)") - // TODO: Find or create profile with the pubKey... if not found submit a sync request... + // Find or create profile with the pubKey... if not found TODO: submit a sync request... val profile = database.profileDao().getProfileByPublicKey(nostrEvent.pubKey) if (profile == null) { @@ -48,7 +49,6 @@ abstract class NostrDao( // TODO: Sync to find and update profile } - database.nostrEventDao().upsert(nostrEvent) nostrEvent.toPost()?.let { post -> @@ -103,11 +103,7 @@ abstract class NostrDao( nostrEvent.toZap()?.let { zap -> database.zapDao().upsert(zap) } - // Submit a broadcastRequest... - if (nostrEvent.kind == 0) { - // Look busy - delay(2_500) - } + relayURLs.forEach { relayURL -> database.broadcastNostrEventRequestDao().upsert( BroadcastNostrEventRequest( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/model/NostrEvent.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/model/NostrEvent.kt index aec78c2a..2a4b40f3 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/model/NostrEvent.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/model/NostrEvent.kt @@ -78,6 +78,9 @@ data class NostrEvent( return result } + fun isProfileCreationEvent(): Boolean { + return kind == MetadataEvent.KIND && unsignedNostrEventId != null + } fun toPost(): Post? = try { if (kind == TextNoteEvent.KIND) { val textNote = EventFactory.create( diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/repository/DatabaseNostrRepository.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/repository/DatabaseNostrRepository.kt index 5174e0be..cd35d636 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/database/repository/DatabaseNostrRepository.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/database/repository/DatabaseNostrRepository.kt @@ -52,8 +52,13 @@ class DatabaseNostrRepository( ) ) + + if (unsignedNostrEvent == null) { onError.invoke() + } else if (unsignedNostrEvent.kind == 0 ) { + // Look busy for the onboarding screen + delay(3_500) } } diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/UnannouncedProfileScreen.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/UnannouncedProfileScreen.kt index a27f9de9..472e19a0 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/UnannouncedProfileScreen.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/composable/UnannouncedProfileScreen.kt @@ -69,7 +69,7 @@ fun UnannouncedProfileScreen( ) Text( - text = "Aux will be broadcast to what you publish to relays so that it's distributed and decentralized.", + text = "Aux will be broadcast what you publish to a distributed set of relays so that it's decentralized.", style = MaterialTheme.typography.bodySmall, textAlign = TextAlign.Center ) diff --git a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt index 7f6397b7..17c0e13f 100644 --- a/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/aux/compose/ui/view/model/NavigationViewModel.kt @@ -73,6 +73,7 @@ class NavigationViewModel( content = unsignedNostrEvent.content ) + nostrRepository.publishNostrEvent( NostrEvent( id = event.id, @@ -116,7 +117,7 @@ class NavigationViewModel( broadcastNostrEventReceipt = localProfile.broadcastNostrEventReceipt ) } else if (localProfile.broadcastNostrEventRequest != null) { - logger.i("We have a profile: ${localProfile.profile}") + logger.i("We have a broadcast request: ${localProfile.broadcastNostrEventRequest}") NavigationUIState.UnannouncedProfile( broadcastNostrEventRequest = localProfile.broadcastNostrEventRequest )