chore: improve performance #41
@@ -155,7 +155,7 @@ fun HomeScreen() {
|
|||||||
onPauseOrDispose { }
|
onPauseOrDispose { }
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(authState.signerRequired) {
|
||||||
chatViewModel.refreshChatRooms()
|
chatViewModel.refreshChatRooms()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,8 @@ class MessageManager(private val nostr: Nostr) {
|
|||||||
val userPubkey =
|
val userPubkey =
|
||||||
signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in")
|
signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in")
|
||||||
|
|
||||||
|
println("pubkey: ${userPubkey.toBech32()}")
|
||||||
|
|
||||||
val kind = Kind.fromStd(KindStandard.APPLICATION_SPECIFIC_DATA)
|
val kind = Kind.fromStd(KindStandard.APPLICATION_SPECIFIC_DATA)
|
||||||
val kTag = SingleLetterTag.lowercase(Alphabet.K)
|
val kTag = SingleLetterTag.lowercase(Alphabet.K)
|
||||||
|
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() {
|
|||||||
_state.update { it.copy(isPartialProcessedGiftWrap = true) }
|
_state.update { it.copy(isPartialProcessedGiftWrap = true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh UI every 10 messages OR when sync is fully done
|
// Refresh UI every 100 messages OR when sync is fully done
|
||||||
if (syncState.processedCount % 10 == 0 || !syncState.isSyncing) {
|
if (syncState.processedCount % 100 == 0 || !syncState.isSyncing) {
|
||||||
refreshChatRooms()
|
refreshChatRooms()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,9 +97,6 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() {
|
|||||||
_newEvents.emit(event)
|
_newEvents.emit(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial load of rooms
|
|
||||||
refreshChatRooms()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +146,7 @@ class ChatViewModel(private val nostr: Nostr) : BaseViewModel() {
|
|||||||
_state.update { currentState ->
|
_state.update { currentState ->
|
||||||
val merged = currentState.rooms.associateBy { it.id }.toMutableMap()
|
val merged = currentState.rooms.associateBy { it.id }.toMutableMap()
|
||||||
// Add or update rooms from the database
|
// Add or update rooms from the database
|
||||||
rooms.forEach { room ->
|
rooms.forEach { room -> merged[room.id] = room }
|
||||||
merged[room.id] = room
|
|
||||||
}
|
|
||||||
// Return as a sorted set to maintain UI consistency
|
// Return as a sorted set to maintain UI consistency
|
||||||
currentState.copy(rooms = merged.values.sortedDescending().toSet())
|
currentState.copy(rooms = merged.values.sortedDescending().toSet())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user