mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Merge pull request #903 from vector-im/feature/bma/sessionDeleted
React to session deletion (from another session)
This commit is contained in:
+24
-8
@@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.filter
|
|||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
import org.matrix.rustcomponents.sdk.Client
|
import org.matrix.rustcomponents.sdk.Client
|
||||||
@@ -70,6 +71,7 @@ import org.matrix.rustcomponents.sdk.RoomListItem
|
|||||||
import org.matrix.rustcomponents.sdk.use
|
import org.matrix.rustcomponents.sdk.use
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import org.matrix.rustcomponents.sdk.CreateRoomParameters as RustCreateRoomParameters
|
import org.matrix.rustcomponents.sdk.CreateRoomParameters as RustCreateRoomParameters
|
||||||
import org.matrix.rustcomponents.sdk.RoomPreset as RustRoomPreset
|
import org.matrix.rustcomponents.sdk.RoomPreset as RustRoomPreset
|
||||||
import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
||||||
@@ -80,7 +82,7 @@ class RustMatrixClient constructor(
|
|||||||
private val client: Client,
|
private val client: Client,
|
||||||
private val syncService: ClientSyncService,
|
private val syncService: ClientSyncService,
|
||||||
private val sessionStore: SessionStore,
|
private val sessionStore: SessionStore,
|
||||||
appCoroutineScope: CoroutineScope,
|
private val appCoroutineScope: CoroutineScope,
|
||||||
private val dispatchers: CoroutineDispatchers,
|
private val dispatchers: CoroutineDispatchers,
|
||||||
private val baseDirectory: File,
|
private val baseDirectory: File,
|
||||||
baseCacheDirectory: File,
|
baseCacheDirectory: File,
|
||||||
@@ -103,10 +105,20 @@ class RustMatrixClient constructor(
|
|||||||
|
|
||||||
private val notificationService = RustNotificationService(notificationClient)
|
private val notificationService = RustNotificationService(notificationClient)
|
||||||
|
|
||||||
|
private val isLoggingOut = AtomicBoolean(false)
|
||||||
|
|
||||||
private val clientDelegate = object : ClientDelegate {
|
private val clientDelegate = object : ClientDelegate {
|
||||||
override fun didReceiveAuthError(isSoftLogout: Boolean) {
|
override fun didReceiveAuthError(isSoftLogout: Boolean) {
|
||||||
//TODO handle this
|
Timber.w("didReceiveAuthError(isSoftLogout=$isSoftLogout)")
|
||||||
Timber.v("didReceiveAuthError(isSoftLogout=$isSoftLogout)")
|
if (isLoggingOut.getAndSet(true).not()) {
|
||||||
|
Timber.v("didReceiveAuthError -> do the cleanup")
|
||||||
|
//TODO handle isSoftLogout parameter.
|
||||||
|
appCoroutineScope.launch {
|
||||||
|
doLogout(doRequest = false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.v("didReceiveAuthError -> already cleaning up")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,11 +286,15 @@ class RustMatrixClient constructor(
|
|||||||
baseDirectory.deleteSessionDirectory(userID = sessionId.value, deleteCryptoDb = false)
|
baseDirectory.deleteSessionDirectory(userID = sessionId.value, deleteCryptoDb = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun logout() = withContext(sessionDispatcher) {
|
override suspend fun logout() = doLogout(doRequest = true)
|
||||||
try {
|
|
||||||
client.logout()
|
private suspend fun doLogout(doRequest: Boolean) = withContext(sessionDispatcher) {
|
||||||
} catch (failure: Throwable) {
|
if (doRequest) {
|
||||||
Timber.e(failure, "Fail to call logout on HS. Still delete local files.")
|
try {
|
||||||
|
client.logout()
|
||||||
|
} catch (failure: Throwable) {
|
||||||
|
Timber.e(failure, "Fail to call logout on HS. Still delete local files.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close()
|
close()
|
||||||
baseDirectory.deleteSessionDirectory(userID = sessionId.value, deleteCryptoDb = true)
|
baseDirectory.deleteSessionDirectory(userID = sessionId.value, deleteCryptoDb = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user