Make sure to save the tokens the Client might return when its session is restored (#3378)

* Use `ClientSessionDelegate` to ensure tokens are always updated.

Refreshed tokens on client restoration might not have been stored to disk if the token refresh happened before `RustMatrixClient` was built and the `ClientDelegate` was set in it.

Using `ClientSessionDelegate` should ensure the tokens refreshed callback is called at any point in time.

* Improve how assigning the Client works, fix docs

* Fix review comments
This commit is contained in:
Jorge Martin Espinosa 2024-09-04 10:54:31 +02:00 committed by GitHub
parent 9fb82a1e86
commit 2c8b0d0b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 161 additions and 98 deletions

View file

@ -33,7 +33,7 @@ class DefaultLogoutUseCase @Inject constructor(
return if (currentSession != null) {
matrixClientProvider.getOrRestore(currentSession)
.getOrThrow()
.logout(ignoreSdkError = true)
.logout(userInitiated = true, ignoreSdkError = true)
} else {
error("No session to sign out")
}

View file

@ -104,7 +104,7 @@ class LogoutPresenter @Inject constructor(
ignoreSdkError: Boolean,
) = launch {
suspend {
matrixClient.logout(ignoreSdkError)
matrixClient.logout(userInitiated = true, ignoreSdkError)
}.runCatchingUpdatingState(logoutAction)
}
}

View file

@ -86,7 +86,7 @@ class DefaultDirectLogoutPresenter @Inject constructor(
ignoreSdkError: Boolean,
) = launch {
suspend {
matrixClient.logout(ignoreSdkError)
matrixClient.logout(userInitiated = true, ignoreSdkError)
}.runCatchingUpdatingState(logoutAction)
}
}

View file

@ -144,7 +144,7 @@ class LogoutPresenterTest {
@Test
fun `present - logout with error then cancel`() = runTest {
val matrixClient = FakeMatrixClient().apply {
logoutLambda = { _ ->
logoutLambda = { _, _ ->
throw A_THROWABLE
}
}
@ -172,7 +172,7 @@ class LogoutPresenterTest {
@Test
fun `present - logout with error then force`() = runTest {
val matrixClient = FakeMatrixClient().apply {
logoutLambda = { ignoreSdkError ->
logoutLambda = { ignoreSdkError, _ ->
if (!ignoreSdkError) {
throw A_THROWABLE
} else {

View file

@ -125,7 +125,7 @@ class DefaultDirectLogoutPresenterTest {
@Test
fun `present - logout with error then cancel`() = runTest {
val matrixClient = FakeMatrixClient().apply {
logoutLambda = { _ ->
logoutLambda = { _, _ ->
throw A_THROWABLE
}
}
@ -153,7 +153,7 @@ class DefaultDirectLogoutPresenterTest {
@Test
fun `present - logout with error then force`() = runTest {
val matrixClient = FakeMatrixClient().apply {
logoutLambda = { ignoreSdkError ->
logoutLambda = { ignoreSdkError, _ ->
if (!ignoreSdkError) {
throw A_THROWABLE
} else {