-
Notifications
You must be signed in to change notification settings - Fork 226
Add support for login link #4752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ab54580
c02a294
3142791
2bf4573
7adacdc
dcda037
8dbcd68
faef90d
d36d85b
76786b9
8f209a8
3faa348
59a508f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import io.element.android.appnav.intent.ResolvedIntent | |
import io.element.android.appnav.root.RootNavStateFlowFactory | ||
import io.element.android.appnav.root.RootPresenter | ||
import io.element.android.appnav.root.RootView | ||
import io.element.android.features.login.api.LoginParams | ||
import io.element.android.features.rageshake.api.bugreport.BugReportEntryPoint | ||
import io.element.android.features.signedout.api.SignedOutEntryPoint | ||
import io.element.android.features.viewfolder.api.ViewFolderEntryPoint | ||
|
@@ -99,14 +100,14 @@ class RootFlowNode @AssistedInject constructor( | |
if (navState.loggedInState.isTokenValid) { | ||
tryToRestoreLatestSession( | ||
onSuccess = { sessionId -> switchToLoggedInFlow(sessionId, navState.cacheIndex) }, | ||
onFailure = { switchToNotLoggedInFlow() } | ||
onFailure = { switchToNotLoggedInFlow(null) } | ||
) | ||
} else { | ||
switchToSignedOutFlow(SessionId(navState.loggedInState.sessionId)) | ||
} | ||
} | ||
LoggedInState.NotLoggedIn -> { | ||
switchToNotLoggedInFlow() | ||
switchToNotLoggedInFlow(null) | ||
} | ||
} | ||
} | ||
|
@@ -117,9 +118,9 @@ class RootFlowNode @AssistedInject constructor( | |
backstack.safeRoot(NavTarget.LoggedInFlow(sessionId, navId)) | ||
} | ||
|
||
private fun switchToNotLoggedInFlow() { | ||
private fun switchToNotLoggedInFlow(params: LoginParams?) { | ||
matrixSessionCache.removeAll() | ||
backstack.safeRoot(NavTarget.NotLoggedInFlow) | ||
backstack.safeRoot(NavTarget.NotLoggedInFlow(params)) | ||
} | ||
|
||
private fun switchToSignedOutFlow(sessionId: SessionId) { | ||
|
@@ -175,7 +176,9 @@ class RootFlowNode @AssistedInject constructor( | |
data object SplashScreen : NavTarget | ||
|
||
@Parcelize | ||
data object NotLoggedInFlow : NavTarget | ||
data class NotLoggedInFlow( | ||
val params: LoginParams? | ||
) : NavTarget | ||
|
||
@Parcelize | ||
data class LoggedInFlow( | ||
|
@@ -211,13 +214,16 @@ class RootFlowNode @AssistedInject constructor( | |
} | ||
createNode<LoggedInAppScopeFlowNode>(buildContext, plugins = listOf(inputs, callback)) | ||
} | ||
NavTarget.NotLoggedInFlow -> { | ||
is NavTarget.NotLoggedInFlow -> { | ||
val callback = object : NotLoggedInFlowNode.Callback { | ||
override fun onOpenBugReport() { | ||
backstack.push(NavTarget.BugReport) | ||
} | ||
} | ||
createNode<NotLoggedInFlowNode>(buildContext, plugins = listOf(callback)) | ||
val params = NotLoggedInFlowNode.Params( | ||
loginParams = navTarget.params, | ||
) | ||
createNode<NotLoggedInFlowNode>(buildContext, plugins = listOf(params, callback)) | ||
} | ||
is NavTarget.SignedOutFlow -> { | ||
signedOutEntryPoint.nodeBuilder(this, buildContext) | ||
|
@@ -272,18 +278,31 @@ class RootFlowNode @AssistedInject constructor( | |
val resolvedIntent = intentResolver.resolve(intent) ?: return | ||
when (resolvedIntent) { | ||
is ResolvedIntent.Navigation -> navigateTo(resolvedIntent.deeplinkData) | ||
is ResolvedIntent.Login -> onLoginLink(resolvedIntent.params) | ||
is ResolvedIntent.Oidc -> onOidcAction(resolvedIntent.oidcAction) | ||
is ResolvedIntent.Permalink -> navigateTo(resolvedIntent.permalinkData) | ||
is ResolvedIntent.IncomingShare -> onIncomingShare(resolvedIntent.intent) | ||
} | ||
} | ||
|
||
private suspend fun onLoginLink(params: LoginParams) { | ||
// Is there a session already? | ||
val latestSessionId = authenticationService.getLatestSessionId() | ||
if (latestSessionId == null) { | ||
// No session, open login | ||
switchToNotLoggedInFlow(params) | ||
} else { | ||
// Just ignore the login link if we already have a session | ||
Timber.w("Login link ignored, we already have a session") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should try to give some feedback to the user in this case, although I guess there's no easy way to display a dialog/toast from here 🫤 . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
private suspend fun onIncomingShare(intent: Intent) { | ||
// Is there a session already? | ||
val latestSessionId = authenticationService.getLatestSessionId() | ||
if (latestSessionId == null) { | ||
// No session, open login | ||
switchToNotLoggedInFlow() | ||
switchToNotLoggedInFlow(null) | ||
} else { | ||
attachSession(latestSessionId) | ||
.attachIncomingShare(intent) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.login.api | ||
|
||
interface LoginIntentResolver { | ||
fun parse(uriString: String): LoginParams? | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.login.api | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class LoginParams( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add some docs for what these are used for? |
||
val accountProvider: String, | ||
val loginHint: String? | ||
) : Parcelable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this accidentally added? I think you mentioned this was generated by the IDE before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :/
Does your IDE removes the added section? I do not know how to get ride of this change that I always have to not commit.
I'll revert the change for this PR.