fix: fetch Ghost avatar for existing accounts on app launch

This commit is contained in:
Paweł Orzech 2026-03-19 15:30:28 +01:00
parent ccd729e82f
commit 05f5518bdb
No known key found for this signature in database

View file

@ -114,6 +114,25 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
fun refreshAccountsList() {
_accounts.value = accountManager.getAccounts()
_activeAccount.value = accountManager.getActiveAccount()
// Fetch avatar if missing for active account
val active = _activeAccount.value
if (active != null && active.avatarUrl == null) {
viewModelScope.launch {
try {
val service = ApiClient.getService(
active.blogUrl,
apiKeyProvider = { active.apiKey }
)
val response = service.getCurrentUser()
val avatarUrl = response.body()?.users?.firstOrNull()?.profile_image
if (avatarUrl != null) {
accountManager.updateAccount(id = active.id, avatarUrl = avatarUrl)
_activeAccount.value = accountManager.getActiveAccount()
_accounts.value = accountManager.getAccounts()
}
} catch (_: Exception) { /* best-effort */ }
}
}
}
private fun observeLocalPosts() {