-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
109 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Main changes in this version: Enables the improved sign in and sign up journeys. | ||
Full changelog: https://github.com/vector-im/element-android/releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
vector/src/main/java/im/vector/app/core/di/ActiveSessionSetter.kt
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
vector/src/main/java/im/vector/app/core/di/SessionInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.di | ||
|
||
import kotlinx.coroutines.sync.Semaphore | ||
import kotlinx.coroutines.sync.withPermit | ||
import org.matrix.android.sdk.api.auth.AuthenticationService | ||
import org.matrix.android.sdk.api.session.Session | ||
import javax.inject.Inject | ||
|
||
private val initializerSemaphore = Semaphore(permits = 1) | ||
|
||
class SessionInitializer @Inject constructor( | ||
private val authenticationService: AuthenticationService, | ||
) { | ||
|
||
/** | ||
* A thread safe way to initialize the last authenticated Session instance. | ||
* | ||
* @param readCurrentSession expects an in-memory Session to be provided or null if not yet set. | ||
* @param initializer callback to allow additional initialization on the Session, such as setting the in-memory Session instance. | ||
* @return the initialized Session or null when no authenticated sessions are available. | ||
*/ | ||
suspend fun tryInitialize(readCurrentSession: () -> Session?, initializer: (Session) -> Unit): Session? { | ||
return initializerSemaphore.withPermit { | ||
val currentInMemorySession = readCurrentSession() | ||
when { | ||
currentInMemorySession != null -> currentInMemorySession | ||
authenticationService.hasAuthenticatedSessions() -> { | ||
val lastAuthenticatedSession = authenticationService.getLastAuthenticatedSession()!! | ||
lastAuthenticatedSession.also { initializer(lastAuthenticatedSession) } | ||
} | ||
else -> null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters