Multi accounts - experimental first implementation (#5285)

* Multi account - Do not reset analytics store on sign out.

Else when 1 of many accounts is removed, the analytics opt in screen is displayed again.

* Multi accounts - first implementation.

* Multi accounts - Prevent user from logging twice with the same account

* Multi accounts - ignore automatic GoBack in case of error.

* Multi accounts - update first view when adding an account.

* Rename method storeData to addSession.

* Multi accounts - handle account switch when coming from a notification

* Multi accounts - handle login link when there is already an account.

* Multi accounts - handle click on push history for not current account.

* Multi accounts - improve layout and add preview.

* Add accountselect modules

* Multi accounts - incoming share with account selection

* Multi accounts - check the feature flag before allowing login using login link.

* Multi accounts - swipe on account icon

* Cleanup

* Multi accounts - fix other implementation of SessionStore

* Multi accounts - fix PreferencesRootPresenterTest

* Multi accounts - Add test on AccountSelectPresenter

* Multi accounts - Fix test on HomePresenter - WIP

* Update database to be able to sort accounts by creation date.

* Add unit test on takeCurrentUserWithNeighbors

* Fix test and improve code.

* Add exception

* Multi accounts - handle permalink

* Code quality

* Multi accounts - localization

* Fix issue after rebase on develop

* Fix issue after rebase on develop

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Update Multi accounts flag details.

* Add missing test on DatabaseSessionStore

* Add missing preview on LoginModeView

* Remove dead code.

* Add missing preview on PushHistoryView

* Document API.

* Rename API and update test.

* Remove MatrixAuthenticationService.loggedInStateFlow()

* Update screenshots

* Remove unused import

* Add exception

* Fix compilation issue after rebase on develop.

* Update screenshots

* Fix test

* Avoid calling getLatestSession() twice

* Rename `matrixUserAndNeighbors` to `currentUserAndNeighbors`

* Extract code to its own class.

* Add comment to clarify the code.

* Init current user profile with what we now have in the database.

It allows having the cached data (user display name and avatar) when starting the application when no network is available.

* Let the RustMatrixClient update the profile in the session database

* Fix test.

* When logging out from Pin code screen, logout from all the sessions.

tom

* Make PushData.clientSecret mandatory.
Also do not restore the last session as a fallback, it can lead to error in a multi account context, or even when a ghost pusher send a Push.

* Change test in RustMatrixAuthenticationServiceTest

* Do not use MatrixAuthenticationService in RootFlowNode, only use SessionStore

* Remove MatrixAuthenticationService.getLatestSessionId()

* Fix compilation issue after merging develop

* Add test on DefaultAccountSelectEntryPoint

* Fix compilation issue after merging develop

* Introduce LoggedInAccountSwitcherNode, to improve animation when switching between accounts.

* Rename Node to follow naming convention.

* Fix navigation issue after login.

* Remove unused import

* Revert "Fix navigation issue after login."

This reverts commit e409630856d7a7e741548016d7afe174ff1b40f7.

* Revert "Rename Node to follow naming convention."

This reverts commit 883b1f37c7207512d9f6605749977ad9045846a1.

* Revert "Introduce LoggedInAccountSwitcherNode, to improve animation when switching between accounts."

This reverts commit 9c698ff8152aceb5fd2b8b5ab5f609d28de64d24.

* Metro now have `@AssistedInject`.

* Update screenshots

* Introduce DelegateTransitionHandler and use it in RootFlowNode

---------

Co-authored-by: ElementBot <android@element.io>
Co-authored-by: ganfra <francoisg@element.io>
This commit is contained in:
Benoit Marty 2025-09-26 15:45:06 +02:00 committed by GitHub
parent a8c4d5d019
commit 1e546335df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
117 changed files with 2161 additions and 281 deletions

View file

@ -39,4 +39,12 @@ data class SessionData(
val sessionPath: String,
/** The path to the cache data stored for the session in the filesystem. */
val cachePath: String,
/** The position, to be able to order account. */
val position: Long,
/** The index of the last date of session usage. */
val lastUsageIndex: Long,
/** The optional display name of the user. */
val userDisplayName: String?,
/** The optional avatar URL of the user. */
val userAvatarUrl: String?,
)

View file

@ -11,8 +11,22 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
interface SessionStore {
/**
* A flow emitting the current logged in state.
* If there is at least one session, the state is [LoggedInState.LoggedIn] with the latest used session.
* If there is no session, the state is [LoggedInState.NotLoggedIn].
*/
fun loggedInStateFlow(): Flow<LoggedInState>
/**
* Return a flow of all sessions ordered by last usage descending.
*/
fun sessionsFlow(): Flow<List<SessionData>>
/**
* Add a new session. If other sessions exist, the new one will be set as the latest used one, and
* the added session position will be set to a value higher than the other session positions.
*/
suspend fun addSession(sessionData: SessionData)
/**
@ -20,9 +34,35 @@ interface SessionStore {
* No op if userId is not found in DB.
*/
suspend fun updateData(sessionData: SessionData)
/**
* Update the user profile info of the session matching the userId.
*/
suspend fun updateUserProfile(sessionId: String, displayName: String?, avatarUrl: String?)
/**
* Get the session data matching the userId, or null if not found.
*/
suspend fun getSession(sessionId: String): SessionData?
/**
* Get all sessions ordered by last usage descending.
*/
suspend fun getAllSessions(): List<SessionData>
/**
* Get the latest session, or null if no session exists.
*/
suspend fun getLatestSession(): SessionData?
/**
* Set the session with [sessionId] as the latest used one.
*/
suspend fun setLatestSession(sessionId: String)
/**
* Remove the session matching the sessionId.
*/
suspend fun removeSession(sessionId: String)
}