From e0701504aa5f9b5ecd85349792f34d38d0923d24 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 9 Jul 2026 16:12:38 +0700 Subject: [PATCH] remove unnecessary query call --- .../kotlin/su/reya/coop/screens/HomeScreen.kt | 2 +- .../commonMain/kotlin/su/reya/coop/nostr/Messaging.kt | 2 ++ .../kotlin/su/reya/coop/viewmodel/ChatViewModel.kt | 11 +++-------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt index f2fbe89..5c446a9 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/HomeScreen.kt @@ -155,7 +155,7 @@ fun HomeScreen() { onPauseOrDispose { } } - LaunchedEffect(Unit) { + LaunchedEffect(authState.signerRequired) { chatViewModel.refreshChatRooms() } diff --git a/shared/src/commonMain/kotlin/su/reya/coop/nostr/Messaging.kt b/shared/src/commonMain/kotlin/su/reya/coop/nostr/Messaging.kt index dac7031..6031153 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/nostr/Messaging.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/nostr/Messaging.kt @@ -165,6 +165,8 @@ class MessageManager(private val nostr: Nostr) { val userPubkey = signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in") + println("pubkey: ${userPubkey.toBech32()}") + val kind = Kind.fromStd(KindStandard.APPLICATION_SPECIFIC_DATA) val kTag = SingleLetterTag.lowercase(Alphabet.K) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt index baee6b6..94bbbb7 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt @@ -69,8 +69,8 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() { _state.update { it.copy(isPartialProcessedGiftWrap = true) } } - // Refresh UI every 10 messages OR when sync is fully done - if (syncState.processedCount % 10 == 0 || !syncState.isSyncing) { + // Refresh UI every 100 messages OR when sync is fully done + if (syncState.processedCount % 100 == 0 || !syncState.isSyncing) { refreshChatRooms() } } @@ -97,9 +97,6 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() { _newEvents.emit(event) } } - - // Initial load of rooms - refreshChatRooms() } } @@ -149,9 +146,7 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() { _state.update { currentState -> val merged = currentState.rooms.associateBy { it.id }.toMutableMap() // Add or update rooms from the database - rooms.forEach { room -> - merged[room.id] = room - } + rooms.forEach { room -> merged[room.id] = room } // Return as a sorted set to maintain UI consistency currentState.copy(rooms = merged.values.sortedDescending().toSet()) }