Avoid database access on the main thread when opening the settings

`getUserProfile()` was storing the user profile (DB read, avatar Base64 encoding, DB write) on the caller
dispatcher, i.e. the main thread when called from a presenter, causing glitches in the screen transition.
- Run the whole `getUserProfile()` on the session dispatcher.
- Make `DatabaseSessionStore` main-safe by running the queries on the IO dispatcher.
- Do not refresh the profile twice from the settings screen.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benoit Marty
2026-10-12 10:42:19 +02:00
parent f12b9c77d5
commit 8912341439
3 changed files with 93 additions and 83 deletions
@@ -519,12 +519,14 @@ class RustMatrixClient(
}
}
override suspend fun getUserProfile(): Result<MatrixUser> = getProfile(sessionId)
.onSuccess { matrixUser ->
// Also update our session storage
_userProfile.emit(matrixUser)
storeUserProfile(matrixUser)
}
override suspend fun getUserProfile(): Result<MatrixUser> = withContext(sessionDispatcher) {
getProfile(sessionId)
.onSuccess { matrixUser ->
// Also update our session storage
_userProfile.emit(matrixUser)
storeUserProfile(matrixUser)
}
}
/**
* Store the user profile in the session storage, including a base64 encoded thumbnail of the avatar,