From e2f4b454b9effaa3e73bd2ea557dc7a3c7efd359 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 28 May 2026 09:26:31 +0700 Subject: [PATCH] get chat rooms on login --- .../kotlin/su/reya/coop/NostrViewModel.kt | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 049275c..80a687e 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -109,9 +109,7 @@ class NostrViewModel( }, onSubscriptionClose = { getChatRooms() - if (!_isPartialProcessedGiftWrap.value) { - _isPartialProcessedGiftWrap.value = true - } + _isPartialProcessedGiftWrap.value = true }, onNewMessage = { event -> viewModelScope.launch { @@ -178,7 +176,9 @@ class NostrViewModel( val results = nostr.getAllCacheMetadata() results.forEach { (pubkey, metadata) -> + // Update the metadata state updateMetadata(pubkey, metadata) + // Update seenPublicKeys to avoid duplicate requests seenPublicKeys.add(pubkey) } } @@ -193,15 +193,14 @@ class NostrViewModel( val secret = secretStore.get("user_signer") // If no secret is found, show onboarding screen - when (secret) { - null -> { - _emptySecret.value = true - return@launch - } - - else -> _emptySecret.value = false + if (secret == null) { + _emptySecret.value = true + return@launch } + // Update the empty secret state + _emptySecret.value = false + // Handle different signer types if (secret.startsWith("nsec1")) { val keys = Keys.parse(secret) @@ -229,11 +228,22 @@ class NostrViewModel( val pubkey = nostr.signer.currentUser if (pubkey != null) { + // Get chat rooms + val rooms = nostr.getChatRooms() ?: emptySet() + if (rooms.isNotEmpty()) { + _chatRooms.value = rooms + _isPartialProcessedGiftWrap.value = true + } + + // Small delay to ensure all relays are connected delay(3000) + + // Check if the relay list is empty val relays = nostr.getMsgRelays(pubkey) if (relays.isEmpty()) { _isRelayListEmpty.value = true } + break }