@@ -299,19 +299,25 @@ class RootFlowNode(
299
299
}
300
300
301
301
private suspend fun onLoginLink (params : LoginParams ) {
302
- // Is there a session already?
303
- val latestSessionId = authenticationService.getLatestSessionId()
304
- if (latestSessionId == null ) {
305
- // No session, open login
306
- if (accountProviderAccessControl.isAllowedToConnectToAccountProvider(params.accountProvider.ensureProtocol())) {
307
- switchToNotLoggedInFlow(params)
302
+ if (accountProviderAccessControl.isAllowedToConnectToAccountProvider(params.accountProvider.ensureProtocol())) {
303
+ // Is there a session already?
304
+ val sessions = sessionStore.getAllSessions()
305
+ if (sessions.isNotEmpty()) {
306
+ val loginHintMatrixId = params.loginHint?.removePrefix(" mxid:" )
307
+ val existingAccount = sessions.find { it.userId == loginHintMatrixId }
308
+ if (existingAccount != null ) {
309
+ // We have an existing account matching the login hint, ensure this is the current session
310
+ sessionStore.setLatestSession(existingAccount.userId)
311
+ } else {
312
+ val latestSessionId = sessions.maxBy { it.lastUsageIndex }.userId
313
+ attachSession(SessionId (latestSessionId))
314
+ backstack.push(NavTarget .NotLoggedInFlow (params))
315
+ }
308
316
} else {
309
- Timber .w(" Login link ignored, we are not allowed to connect to the homeserver" )
310
- switchToNotLoggedInFlow(null )
317
+ switchToNotLoggedInFlow(params)
311
318
}
312
319
} else {
313
- // Just ignore the login link if we already have a session
314
- Timber .w(" Login link ignored, we already have a session" )
320
+ Timber .w(" Login link ignored, we are not allowed to connect to the homeserver" )
315
321
}
316
322
}
317
323
@@ -322,6 +328,7 @@ class RootFlowNode(
322
328
// No session, open login
323
329
switchToNotLoggedInFlow(null )
324
330
} else {
331
+ // TODO Multi-account: show a screen to select an account
325
332
attachSession(latestSessionId)
326
333
.attachIncomingShare(intent)
327
334
}
0 commit comments