Skip to content

Commit

Permalink
Apply the same patch on account deactivation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Sep 17, 2024
1 parent c7c32af commit 1473afc
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ class RustMatrixClient(

override suspend fun deactivateAccount(password: String, eraseData: Boolean): Result<Unit> = withContext(sessionDispatcher) {
Timber.w("Deactivating account")
syncService.stop()
// Remove current delegate so we don't receive an auth error
clientDelegateTaskHandle?.cancelAndDestroy()
clientDelegateTaskHandle = null
runCatching {
// First call without AuthData, should fail
val firstAttempt = runCatching {
Expand All @@ -523,15 +525,22 @@ class RustMatrixClient(
if (firstAttempt.isFailure) {
Timber.w(firstAttempt.exceptionOrNull(), "Expected failure, try again")
// This is expected, try again with the password
client.deactivateAccount(
authData = AuthData.Password(
passwordDetails = AuthDataPasswordDetails(
identifier = sessionId.value,
password = password,
runCatching {
client.deactivateAccount(
authData = AuthData.Password(
passwordDetails = AuthDataPasswordDetails(
identifier = sessionId.value,
password = password,
),
),
),
eraseData = eraseData,
)
eraseData = eraseData,
)
}.onFailure {
Timber.e(it, "Failed to deactivate account")
// If the deactivation failed we need to restore the delegate
clientDelegateTaskHandle = client.setDelegate(sessionDelegate)
throw it
}
}
close()
deleteSessionDirectory(deleteCryptoDb = true)
Expand Down

0 comments on commit 1473afc

Please sign in to comment.