Dm header icons reactive (#190)

* header reactive to noise session

* favorite button reactive

* icon change

* nice
This commit is contained in:
callebtc
2025-07-25 19:50:40 +02:00
committed by GitHub
parent 271df2e720
commit c9aba00478
8 changed files with 166 additions and 33 deletions
@@ -80,6 +80,8 @@ class ChatViewModel(
val showCommandSuggestions: LiveData<Boolean> = state.showCommandSuggestions
val commandSuggestions: LiveData<List<CommandSuggestion>> = state.commandSuggestions
val favoritePeers: LiveData<Set<String>> = state.favoritePeers
val peerSessionStates: LiveData<Map<String, String>> = state.peerSessionStates
val peerFingerprints: LiveData<Map<String, String>> = state.peerFingerprints
val showAppInfo: LiveData<Boolean> = state.showAppInfo
init {
@@ -115,6 +117,9 @@ class ChatViewModel(
dataManager.logAllFavorites()
logCurrentFavoriteState()
// Initialize session state monitoring
initializeSessionStateMonitoring()
// Note: Mesh service is now started by MainActivity
// Show welcome message if no peers after delay
@@ -279,6 +284,35 @@ class ChatViewModel(
Log.i("ChatViewModel", "==============================")
}
/**
* Initialize session state monitoring for reactive UI updates
*/
private fun initializeSessionStateMonitoring() {
viewModelScope.launch {
while (true) {
delay(1000) // Check session states every second
updateReactiveStates()
}
}
}
/**
* Update reactive states for all connected peers (session states and fingerprints)
*/
private fun updateReactiveStates() {
val currentPeers = state.getConnectedPeersValue()
// Update session states
val sessionStates = currentPeers.associateWith { peerID ->
meshService.getSessionState(peerID).toString()
}
state.setPeerSessionStates(sessionStates)
// Update fingerprint mappings from centralized manager
val fingerprints = privateChatManager.getAllPeerFingerprints()
state.setPeerFingerprints(fingerprints)
}
// MARK: - Debug and Troubleshooting
fun getDebugStatus(): String {