mirror of
https://github.com/pawelorzech/Swoosh.git
synced 2026-03-31 20:15:41 +00:00
fix: fetch Ghost avatar for existing accounts on app launch
This commit is contained in:
parent
ccd729e82f
commit
05f5518bdb
1 changed files with 19 additions and 0 deletions
|
|
@ -114,6 +114,25 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
fun refreshAccountsList() {
|
fun refreshAccountsList() {
|
||||||
_accounts.value = accountManager.getAccounts()
|
_accounts.value = accountManager.getAccounts()
|
||||||
_activeAccount.value = accountManager.getActiveAccount()
|
_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() {
|
private fun observeLocalPosts() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue