fix(memory): scope memory endpoints to active profile and auto-reload on profile switch (#1035)

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-09-01 19:20:18 +03:00
1 parent 11dd1eff92
commit 21db9bfdab
4 files changed
+63 -2

No files matched your search

@@ -34,6 +34,7 @@ object ProfileScopeInterceptor : Interceptor {
"/api/env",
"/api/gateway",
"/api/mcp",
"/api/memory",
"/api/messaging/platforms",
"/api/messaging/telegram/onboarding",
"/api/messaging/whatsapp/onboarding",
@@ -8,6 +8,7 @@ import com.m57.hermescontrol.data.model.MemoryResponse
import com.m57.hermescontrol.data.remote.ApiClient
import com.m57.hermescontrol.data.remote.NetworkResult
import com.m57.hermescontrol.data.remote.safeApiCall
import com.m57.hermescontrol.data.session.ProfileSwitchCoordinator
import com.m57.hermescontrol.ui.common.ToastHost
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@@ -37,9 +38,24 @@ class MemoryViewModel :
private val _uiState = MutableStateFlow(MemoryUiState())
val uiState: StateFlow<MemoryUiState> = _uiState.asStateFlow()
fun load() {
init {
viewModelScope.launch {
ProfileSwitchCoordinator.switched.collect {
load(silent = true)
}
}
viewModelScope.launch {
ProfileSwitchCoordinator.connectionSwitched.collect {
load(silent = true)
}
}
}
fun load(silent: Boolean = false) {
if (_uiState.value.isLoading) return
_uiState.update { it.copy(isLoading = true, errorMessage = null) }
if (!silent) {
_uiState.update { it.copy(isLoading = true, errorMessage = null) }
}
viewModelScope.launch {
val result = safeApiCall { ApiClient.hermesApi.getMemory() }
when (result) {