get chat rooms on login

This commit is contained in:
2026-05-28 09:26:31 +07:00
parent cab12da4a5
commit e2f4b454b9

View File

@@ -109,9 +109,7 @@ class NostrViewModel(
}, },
onSubscriptionClose = { onSubscriptionClose = {
getChatRooms() getChatRooms()
if (!_isPartialProcessedGiftWrap.value) {
_isPartialProcessedGiftWrap.value = true _isPartialProcessedGiftWrap.value = true
}
}, },
onNewMessage = { event -> onNewMessage = { event ->
viewModelScope.launch { viewModelScope.launch {
@@ -178,7 +176,9 @@ class NostrViewModel(
val results = nostr.getAllCacheMetadata() val results = nostr.getAllCacheMetadata()
results.forEach { (pubkey, metadata) -> results.forEach { (pubkey, metadata) ->
// Update the metadata state
updateMetadata(pubkey, metadata) updateMetadata(pubkey, metadata)
// Update seenPublicKeys to avoid duplicate requests
seenPublicKeys.add(pubkey) seenPublicKeys.add(pubkey)
} }
} }
@@ -193,14 +193,13 @@ class NostrViewModel(
val secret = secretStore.get("user_signer") val secret = secretStore.get("user_signer")
// If no secret is found, show onboarding screen // If no secret is found, show onboarding screen
when (secret) { if (secret == null) {
null -> {
_emptySecret.value = true _emptySecret.value = true
return@launch return@launch
} }
else -> _emptySecret.value = false // Update the empty secret state
} _emptySecret.value = false
// Handle different signer types // Handle different signer types
if (secret.startsWith("nsec1")) { if (secret.startsWith("nsec1")) {
@@ -229,11 +228,22 @@ class NostrViewModel(
val pubkey = nostr.signer.currentUser val pubkey = nostr.signer.currentUser
if (pubkey != null) { 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) delay(3000)
// Check if the relay list is empty
val relays = nostr.getMsgRelays(pubkey) val relays = nostr.getMsgRelays(pubkey)
if (relays.isEmpty()) { if (relays.isEmpty()) {
_isRelayListEmpty.value = true _isRelayListEmpty.value = true
} }
break break
} }