client : rename some internals and do not destroy client related instances manually
This commit is contained in:
parent
982410ece8
commit
8d86ba88a1
7 changed files with 58 additions and 68 deletions
|
|
@ -118,44 +118,44 @@ import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
||||||
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
||||||
|
|
||||||
class RustMatrixClient(
|
class RustMatrixClient(
|
||||||
private val client: Client,
|
private val innerClient: Client,
|
||||||
private val baseDirectory: File,
|
private val baseDirectory: File,
|
||||||
private val sessionStore: SessionStore,
|
private val sessionStore: SessionStore,
|
||||||
private val appCoroutineScope: CoroutineScope,
|
private val appCoroutineScope: CoroutineScope,
|
||||||
private val sessionDelegate: RustClientSessionDelegate,
|
private val sessionDelegate: RustClientSessionDelegate,
|
||||||
syncService: ClientSyncService,
|
innerSyncService: ClientSyncService,
|
||||||
dispatchers: CoroutineDispatchers,
|
dispatchers: CoroutineDispatchers,
|
||||||
baseCacheDirectory: File,
|
baseCacheDirectory: File,
|
||||||
clock: SystemClock,
|
clock: SystemClock,
|
||||||
timelineEventTypeFilterFactory: TimelineEventTypeFilterFactory,
|
timelineEventTypeFilterFactory: TimelineEventTypeFilterFactory,
|
||||||
featureFlagService: FeatureFlagService,
|
featureFlagService: FeatureFlagService,
|
||||||
) : MatrixClient {
|
) : MatrixClient {
|
||||||
override val sessionId: UserId = UserId(client.userId())
|
override val sessionId: UserId = UserId(innerClient.userId())
|
||||||
override val deviceId: DeviceId = DeviceId(client.deviceId())
|
override val deviceId: DeviceId = DeviceId(innerClient.deviceId())
|
||||||
override val sessionCoroutineScope = appCoroutineScope.childScope(dispatchers.main, "Session-$sessionId")
|
override val sessionCoroutineScope = appCoroutineScope.childScope(dispatchers.main, "Session-$sessionId")
|
||||||
|
|
||||||
private val innerRoomListService = syncService.roomListService()
|
|
||||||
private val sessionDispatcher = dispatchers.io.limitedParallelism(64)
|
private val sessionDispatcher = dispatchers.io.limitedParallelism(64)
|
||||||
|
|
||||||
private val rustSyncService = RustSyncService(syncService, sessionCoroutineScope)
|
private val innerRoomListService = innerSyncService.roomListService()
|
||||||
|
|
||||||
|
private val rustSyncService = RustSyncService(innerSyncService, sessionCoroutineScope)
|
||||||
private val pushersService = RustPushersService(
|
private val pushersService = RustPushersService(
|
||||||
client = client,
|
client = innerClient,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
)
|
)
|
||||||
private val notificationProcessSetup = NotificationProcessSetup.SingleProcess(syncService)
|
private val notificationProcessSetup = NotificationProcessSetup.SingleProcess(innerSyncService)
|
||||||
private val notificationClient = runBlocking { client.notificationClient(notificationProcessSetup) }
|
private val innerNotificationClient = runBlocking { innerClient.notificationClient(notificationProcessSetup) }
|
||||||
private val notificationService = RustNotificationService(notificationClient, dispatchers, clock)
|
private val notificationService = RustNotificationService(innerNotificationClient, dispatchers, clock)
|
||||||
private val notificationSettingsService = RustNotificationSettingsService(client, dispatchers)
|
private val notificationSettingsService = RustNotificationSettingsService(innerClient, dispatchers)
|
||||||
.apply { start() }
|
.apply { start() }
|
||||||
private val encryptionService = RustEncryptionService(
|
private val encryptionService = RustEncryptionService(
|
||||||
client = client,
|
client = innerClient,
|
||||||
syncService = rustSyncService,
|
syncService = rustSyncService,
|
||||||
sessionCoroutineScope = sessionCoroutineScope,
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val roomDirectoryService = RustRoomDirectoryService(
|
private val roomDirectoryService = RustRoomDirectoryService(
|
||||||
client = client,
|
client = innerClient,
|
||||||
sessionDispatcher = sessionDispatcher,
|
sessionDispatcher = sessionDispatcher,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ class RustMatrixClient(
|
||||||
)
|
)
|
||||||
|
|
||||||
private val verificationService = RustSessionVerificationService(
|
private val verificationService = RustSessionVerificationService(
|
||||||
client = client,
|
client = innerClient,
|
||||||
isSyncServiceReady = rustSyncService.syncState.map { it == SyncState.Running },
|
isSyncServiceReady = rustSyncService.syncState.map { it == SyncState.Running },
|
||||||
sessionCoroutineScope = sessionCoroutineScope,
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
)
|
)
|
||||||
|
|
@ -198,26 +198,26 @@ class RustMatrixClient(
|
||||||
override val mediaLoader: MatrixMediaLoader = RustMediaLoader(
|
override val mediaLoader: MatrixMediaLoader = RustMediaLoader(
|
||||||
baseCacheDirectory = baseCacheDirectory,
|
baseCacheDirectory = baseCacheDirectory,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
innerClient = client,
|
innerClient = innerClient,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val roomMembershipObserver = RoomMembershipObserver()
|
private val roomMembershipObserver = RoomMembershipObserver()
|
||||||
|
|
||||||
private var clientDelegateTaskHandle: TaskHandle? = client.setDelegate(sessionDelegate)
|
private var clientDelegateTaskHandle: TaskHandle? = innerClient.setDelegate(sessionDelegate)
|
||||||
|
|
||||||
private val _userProfile: MutableStateFlow<MatrixUser> = MutableStateFlow(
|
private val _userProfile: MutableStateFlow<MatrixUser> = MutableStateFlow(
|
||||||
MatrixUser(
|
MatrixUser(
|
||||||
userId = sessionId,
|
userId = sessionId,
|
||||||
// TODO cache for displayName?
|
// TODO cache for displayName?
|
||||||
displayName = null,
|
displayName = null,
|
||||||
avatarUrl = client.cachedAvatarUrl(),
|
avatarUrl = innerClient.cachedAvatarUrl(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
override val userProfile: StateFlow<MatrixUser> = _userProfile
|
override val userProfile: StateFlow<MatrixUser> = _userProfile
|
||||||
|
|
||||||
override val ignoredUsersFlow = mxCallbackFlow<ImmutableList<UserId>> {
|
override val ignoredUsersFlow = mxCallbackFlow<ImmutableList<UserId>> {
|
||||||
client.subscribeToIgnoredUsers(object : IgnoredUsersListener {
|
innerClient.subscribeToIgnoredUsers(object : IgnoredUsersListener {
|
||||||
override fun call(ignoredUserIds: List<String>) {
|
override fun call(ignoredUserIds: List<String>) {
|
||||||
channel.trySend(ignoredUserIds.map(::UserId).toPersistentList())
|
channel.trySend(ignoredUserIds.map(::UserId).toPersistentList())
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +238,7 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override fun userIdServerName(): String {
|
override fun userIdServerName(): String {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
client.userIdServerName()
|
innerClient.userIdServerName()
|
||||||
}
|
}
|
||||||
.onFailure {
|
.onFailure {
|
||||||
Timber.w(it, "Failed to get userIdServerName")
|
Timber.w(it, "Failed to get userIdServerName")
|
||||||
|
|
@ -249,7 +249,7 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override suspend fun getUrl(url: String): Result<String> = withContext(sessionDispatcher) {
|
override suspend fun getUrl(url: String): Result<String> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.getUrl(url)
|
innerClient.getUrl(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,23 +279,23 @@ class RustMatrixClient(
|
||||||
.filter { roomSummary -> roomSummary.info.currentUserMembership == currentUserMembership }
|
.filter { roomSummary -> roomSummary.info.currentUserMembership == currentUserMembership }
|
||||||
.first()
|
.first()
|
||||||
// Ensure that the room is ready
|
// Ensure that the room is ready
|
||||||
.also { client.awaitRoomRemoteEcho(it.roomId.value) }
|
.also { innerClient.awaitRoomRemoteEcho(it.roomId.value) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findDM(userId: UserId): RoomId? {
|
override suspend fun findDM(userId: UserId): RoomId? {
|
||||||
return client.getDmRoom(userId.value)?.use { RoomId(it.id()) }
|
return innerClient.getDmRoom(userId.value)?.use { RoomId(it.id()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun ignoreUser(userId: UserId): Result<Unit> = withContext(sessionDispatcher) {
|
override suspend fun ignoreUser(userId: UserId): Result<Unit> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.ignoreUser(userId.value)
|
innerClient.ignoreUser(userId.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unignoreUser(userId: UserId): Result<Unit> = withContext(sessionDispatcher) {
|
override suspend fun unignoreUser(userId: UserId): Result<Unit> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.unignoreUser(userId.value)
|
innerClient.unignoreUser(userId.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,7 +338,7 @@ class RustMatrixClient(
|
||||||
},
|
},
|
||||||
canonicalAlias = createRoomParams.roomAliasName.getOrNull(),
|
canonicalAlias = createRoomParams.roomAliasName.getOrNull(),
|
||||||
)
|
)
|
||||||
val roomId = RoomId(client.createRoom(rustParams))
|
val roomId = RoomId(innerClient.createRoom(rustParams))
|
||||||
// Wait to receive the room back from the sync but do not returns failure if it fails.
|
// Wait to receive the room back from the sync but do not returns failure if it fails.
|
||||||
try {
|
try {
|
||||||
awaitRoom(roomId.toRoomIdOrAlias(), 30.seconds, CurrentUserMembership.JOINED)
|
awaitRoom(roomId.toRoomIdOrAlias(), 30.seconds, CurrentUserMembership.JOINED)
|
||||||
|
|
@ -363,7 +363,7 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override suspend fun getProfile(userId: UserId): Result<MatrixUser> = withContext(sessionDispatcher) {
|
override suspend fun getProfile(userId: UserId): Result<MatrixUser> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.getProfile(userId.value).let(UserProfileMapper::map)
|
innerClient.getProfile(userId.value).let(UserProfileMapper::map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,28 +373,28 @@ class RustMatrixClient(
|
||||||
override suspend fun searchUsers(searchTerm: String, limit: Long): Result<MatrixSearchUserResults> =
|
override suspend fun searchUsers(searchTerm: String, limit: Long): Result<MatrixSearchUserResults> =
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.searchUsers(searchTerm, limit.toULong()).let(UserSearchResultMapper::map)
|
innerClient.searchUsers(searchTerm, limit.toULong()).let(UserSearchResultMapper::map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setDisplayName(displayName: String): Result<Unit> =
|
override suspend fun setDisplayName(displayName: String): Result<Unit> =
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
runCatching { client.setDisplayName(displayName) }
|
runCatching { innerClient.setDisplayName(displayName) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun uploadAvatar(mimeType: String, data: ByteArray): Result<Unit> =
|
override suspend fun uploadAvatar(mimeType: String, data: ByteArray): Result<Unit> =
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
runCatching { client.uploadAvatar(mimeType, data) }
|
runCatching { innerClient.uploadAvatar(mimeType, data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun removeAvatar(): Result<Unit> =
|
override suspend fun removeAvatar(): Result<Unit> =
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
runCatching { client.removeAvatar() }
|
runCatching { innerClient.removeAvatar() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun joinRoom(roomId: RoomId): Result<RoomSummary?> = withContext(sessionDispatcher) {
|
override suspend fun joinRoom(roomId: RoomId): Result<RoomSummary?> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.joinRoomById(roomId.value).destroy()
|
innerClient.joinRoomById(roomId.value).destroy()
|
||||||
try {
|
try {
|
||||||
awaitRoom(roomId.toRoomIdOrAlias(), 10.seconds, CurrentUserMembership.JOINED)
|
awaitRoom(roomId.toRoomIdOrAlias(), 10.seconds, CurrentUserMembership.JOINED)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
@ -406,7 +406,7 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override suspend fun joinRoomByIdOrAlias(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomSummary?> = withContext(sessionDispatcher) {
|
override suspend fun joinRoomByIdOrAlias(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomSummary?> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.joinRoomByIdOrAlias(
|
innerClient.joinRoomByIdOrAlias(
|
||||||
roomIdOrAlias = roomIdOrAlias.identifier,
|
roomIdOrAlias = roomIdOrAlias.identifier,
|
||||||
serverNames = serverNames,
|
serverNames = serverNames,
|
||||||
).destroy()
|
).destroy()
|
||||||
|
|
@ -423,7 +423,7 @@ class RustMatrixClient(
|
||||||
sessionDispatcher
|
sessionDispatcher
|
||||||
) {
|
) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.knock(roomIdOrAlias.identifier, message, serverNames).destroy()
|
innerClient.knock(roomIdOrAlias.identifier, message, serverNames).destroy()
|
||||||
try {
|
try {
|
||||||
awaitRoom(roomIdOrAlias, 10.seconds, CurrentUserMembership.KNOCKED)
|
awaitRoom(roomIdOrAlias, 10.seconds, CurrentUserMembership.KNOCKED)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
@ -435,19 +435,19 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override suspend fun trackRecentlyVisitedRoom(roomId: RoomId): Result<Unit> = withContext(sessionDispatcher) {
|
override suspend fun trackRecentlyVisitedRoom(roomId: RoomId): Result<Unit> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.trackRecentlyVisitedRoom(roomId.value)
|
innerClient.trackRecentlyVisitedRoom(roomId.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRecentlyVisitedRooms(): Result<List<RoomId>> = withContext(sessionDispatcher) {
|
override suspend fun getRecentlyVisitedRooms(): Result<List<RoomId>> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.getRecentlyVisitedRooms().map(::RoomId)
|
innerClient.getRecentlyVisitedRooms().map(::RoomId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<Optional<ResolvedRoomAlias>> = withContext(sessionDispatcher) {
|
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<Optional<ResolvedRoomAlias>> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
val result = client.resolveRoomAlias(roomAlias.value)?.let {
|
val result = innerClient.resolveRoomAlias(roomAlias.value)?.let {
|
||||||
ResolvedRoomAlias(
|
ResolvedRoomAlias(
|
||||||
roomId = RoomId(it.roomId),
|
roomId = RoomId(it.roomId),
|
||||||
servers = it.servers,
|
servers = it.servers,
|
||||||
|
|
@ -460,8 +460,8 @@ class RustMatrixClient(
|
||||||
override suspend fun getRoomPreviewInfo(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomPreviewInfo> = withContext(sessionDispatcher) {
|
override suspend fun getRoomPreviewInfo(roomIdOrAlias: RoomIdOrAlias, serverNames: List<String>): Result<RoomPreviewInfo> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
when (roomIdOrAlias) {
|
when (roomIdOrAlias) {
|
||||||
is RoomIdOrAlias.Alias -> client.getRoomPreviewFromRoomAlias(roomIdOrAlias.roomAlias.value)
|
is RoomIdOrAlias.Alias -> innerClient.getRoomPreviewFromRoomAlias(roomIdOrAlias.roomAlias.value)
|
||||||
is RoomIdOrAlias.Id -> client.getRoomPreviewFromRoomId(roomIdOrAlias.roomId.value, serverNames)
|
is RoomIdOrAlias.Id -> innerClient.getRoomPreviewFromRoomId(roomIdOrAlias.roomId.value, serverNames)
|
||||||
}.use { roomPreview ->
|
}.use { roomPreview ->
|
||||||
RoomPreviewInfoMapper.map(roomPreview.info())
|
RoomPreviewInfoMapper.map(roomPreview.info())
|
||||||
}
|
}
|
||||||
|
|
@ -491,11 +491,6 @@ class RustMatrixClient(
|
||||||
clientDelegateTaskHandle?.cancelAndDestroy()
|
clientDelegateTaskHandle?.cancelAndDestroy()
|
||||||
notificationSettingsService.destroy()
|
notificationSettingsService.destroy()
|
||||||
verificationService.destroy()
|
verificationService.destroy()
|
||||||
innerRoomListService.destroy()
|
|
||||||
notificationClient.destroy()
|
|
||||||
notificationProcessSetup.destroy()
|
|
||||||
encryptionService.destroy()
|
|
||||||
client.destroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getCacheSize(): Long {
|
override suspend fun getCacheSize(): Long {
|
||||||
|
|
@ -515,13 +510,13 @@ class RustMatrixClient(
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
if (userInitiated) {
|
if (userInitiated) {
|
||||||
try {
|
try {
|
||||||
result = client.logout()
|
result = innerClient.logout()
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
if (ignoreSdkError) {
|
if (ignoreSdkError) {
|
||||||
Timber.e(failure, "Fail to call logout on HS. Still delete local files.")
|
Timber.e(failure, "Fail to call logout on HS. Still delete local files.")
|
||||||
} else {
|
} else {
|
||||||
// If the logout failed we need to restore the delegate
|
// If the logout failed we need to restore the delegate
|
||||||
clientDelegateTaskHandle = client.setDelegate(sessionDelegate)
|
clientDelegateTaskHandle = innerClient.setDelegate(sessionDelegate)
|
||||||
Timber.e(failure, "Fail to call logout on HS.")
|
Timber.e(failure, "Fail to call logout on HS.")
|
||||||
throw failure
|
throw failure
|
||||||
}
|
}
|
||||||
|
|
@ -539,7 +534,7 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override fun canDeactivateAccount(): Boolean {
|
override fun canDeactivateAccount(): Boolean {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
client.canDeactivateAccount()
|
innerClient.canDeactivateAccount()
|
||||||
}
|
}
|
||||||
.getOrNull()
|
.getOrNull()
|
||||||
.orFalse()
|
.orFalse()
|
||||||
|
|
@ -553,7 +548,7 @@ class RustMatrixClient(
|
||||||
runCatching {
|
runCatching {
|
||||||
// First call without AuthData, should fail
|
// First call without AuthData, should fail
|
||||||
val firstAttempt = runCatching {
|
val firstAttempt = runCatching {
|
||||||
client.deactivateAccount(
|
innerClient.deactivateAccount(
|
||||||
authData = null,
|
authData = null,
|
||||||
eraseData = eraseData,
|
eraseData = eraseData,
|
||||||
)
|
)
|
||||||
|
|
@ -562,7 +557,7 @@ class RustMatrixClient(
|
||||||
Timber.w(firstAttempt.exceptionOrNull(), "Expected failure, try again")
|
Timber.w(firstAttempt.exceptionOrNull(), "Expected failure, try again")
|
||||||
// This is expected, try again with the password
|
// This is expected, try again with the password
|
||||||
runCatching {
|
runCatching {
|
||||||
client.deactivateAccount(
|
innerClient.deactivateAccount(
|
||||||
authData = AuthData.Password(
|
authData = AuthData.Password(
|
||||||
passwordDetails = AuthDataPasswordDetails(
|
passwordDetails = AuthDataPasswordDetails(
|
||||||
identifier = sessionId.value,
|
identifier = sessionId.value,
|
||||||
|
|
@ -574,7 +569,7 @@ class RustMatrixClient(
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it, "Failed to deactivate account")
|
Timber.e(it, "Failed to deactivate account")
|
||||||
// If the deactivation failed we need to restore the delegate
|
// If the deactivation failed we need to restore the delegate
|
||||||
clientDelegateTaskHandle = client.setDelegate(sessionDelegate)
|
clientDelegateTaskHandle = innerClient.setDelegate(sessionDelegate)
|
||||||
throw it
|
throw it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -589,13 +584,13 @@ class RustMatrixClient(
|
||||||
override suspend fun getAccountManagementUrl(action: AccountManagementAction?): Result<String?> = withContext(sessionDispatcher) {
|
override suspend fun getAccountManagementUrl(action: AccountManagementAction?): Result<String?> = withContext(sessionDispatcher) {
|
||||||
val rustAction = action?.toRustAction()
|
val rustAction = action?.toRustAction()
|
||||||
runCatching {
|
runCatching {
|
||||||
client.accountUrl(rustAction)
|
innerClient.accountUrl(rustAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun uploadMedia(mimeType: String, data: ByteArray, progressCallback: ProgressCallback?): Result<String> = withContext(sessionDispatcher) {
|
override suspend fun uploadMedia(mimeType: String, data: ByteArray, progressCallback: ProgressCallback?): Result<String> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.uploadMedia(mimeType, data, progressCallback?.toProgressWatcher())
|
innerClient.uploadMedia(mimeType, data, progressCallback?.toProgressWatcher())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,13 +617,13 @@ class RustMatrixClient(
|
||||||
withContext(sessionDispatcher) {
|
withContext(sessionDispatcher) {
|
||||||
Timber.i("setAllSendQueuesEnabled($enabled)")
|
Timber.i("setAllSendQueuesEnabled($enabled)")
|
||||||
tryOrNull {
|
tryOrNull {
|
||||||
client.enableAllSendQueues(enabled)
|
innerClient.enableAllSendQueues(enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendQueueDisabledFlow(): Flow<RoomId> = mxCallbackFlow {
|
override fun sendQueueDisabledFlow(): Flow<RoomId> = mxCallbackFlow {
|
||||||
client.subscribeToSendQueueStatus(object : SendQueueRoomErrorListener {
|
innerClient.subscribeToSendQueueStatus(object : SendQueueRoomErrorListener {
|
||||||
override fun onError(roomId: String, error: ClientException) {
|
override fun onError(roomId: String, error: ClientException) {
|
||||||
trySend(RoomId(roomId))
|
trySend(RoomId(roomId))
|
||||||
}
|
}
|
||||||
|
|
@ -637,13 +632,13 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override suspend fun availableSlidingSyncVersions(): Result<List<SlidingSyncVersion>> = withContext(sessionDispatcher) {
|
override suspend fun availableSlidingSyncVersions(): Result<List<SlidingSyncVersion>> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.availableSlidingSyncVersions().map { it.map() }
|
innerClient.availableSlidingSyncVersions().map { it.map() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun currentSlidingSyncVersion(): Result<SlidingSyncVersion> = withContext(sessionDispatcher) {
|
override suspend fun currentSlidingSyncVersion(): Result<SlidingSyncVersion> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
client.session().slidingSyncVersion.map()
|
innerClient.session().slidingSyncVersion.map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,12 @@ class RustMatrixClientFactory @Inject constructor(
|
||||||
.finish()
|
.finish()
|
||||||
|
|
||||||
return RustMatrixClient(
|
return RustMatrixClient(
|
||||||
client = client,
|
innerClient = client,
|
||||||
baseDirectory = baseDirectory,
|
baseDirectory = baseDirectory,
|
||||||
sessionStore = sessionStore,
|
sessionStore = sessionStore,
|
||||||
appCoroutineScope = appCoroutineScope,
|
appCoroutineScope = appCoroutineScope,
|
||||||
sessionDelegate = sessionDelegate,
|
sessionDelegate = sessionDelegate,
|
||||||
syncService = syncService,
|
innerSyncService = syncService,
|
||||||
dispatchers = coroutineDispatchers,
|
dispatchers = coroutineDispatchers,
|
||||||
baseCacheDirectory = cacheDirectory,
|
baseCacheDirectory = cacheDirectory,
|
||||||
clock = clock,
|
clock = clock,
|
||||||
|
|
|
||||||
|
|
@ -94,10 +94,6 @@ internal class RustEncryptionService(
|
||||||
}
|
}
|
||||||
.stateIn(sessionCoroutineScope, SharingStarted.Eagerly, false)
|
.stateIn(sessionCoroutineScope, SharingStarted.Eagerly, false)
|
||||||
|
|
||||||
fun destroy() {
|
|
||||||
service.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun enableBackups(): Result<Unit> = withContext(dispatchers.io) {
|
override suspend fun enableBackups(): Result<Unit> = withContext(dispatchers.io) {
|
||||||
runCatching {
|
runCatching {
|
||||||
service.enableBackups()
|
service.enableBackups()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ class RustNotificationSettingsService(
|
||||||
|
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
notificationSettings.setDelegate(null)
|
notificationSettings.setDelegate(null)
|
||||||
notificationSettings.destroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationSettings> =
|
override suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationSettings> =
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ package io.element.android.libraries.matrix.impl.sync
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncState
|
import io.element.android.libraries.matrix.api.sync.SyncState
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.matrix.rustcomponents.sdk.SyncServiceState
|
import org.matrix.rustcomponents.sdk.SyncServiceState
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
@ -49,12 +51,11 @@ class RustSyncService(
|
||||||
Timber.d("Stop sync failed: $it")
|
Timber.d("Stop sync failed: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun destroy() {
|
suspend fun destroy() = withContext(NonCancellable) {
|
||||||
// If the service was still running, stop it
|
// If the service was still running, stop it
|
||||||
stopSync()
|
stopSync()
|
||||||
Timber.d("Destroying sync service")
|
Timber.d("Destroying sync service")
|
||||||
isServiceReady.set(false)
|
isServiceReady.set(false)
|
||||||
innerSyncService.destroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val syncState: StateFlow<SyncState> =
|
override val syncState: StateFlow<SyncState> =
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,6 @@ class RustSessionVerificationService(
|
||||||
recoveryStateListenerTaskHandle.cancelAndDestroy()
|
recoveryStateListenerTaskHandle.cancelAndDestroy()
|
||||||
if (this::verificationController.isInitialized) {
|
if (this::verificationController.isInitialized) {
|
||||||
verificationController.setDelegate(null)
|
verificationController.setDelegate(null)
|
||||||
verificationController.destroy()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ class RustMatrixClientTest {
|
||||||
private fun TestScope.createRustMatrixClient(
|
private fun TestScope.createRustMatrixClient(
|
||||||
sessionStore: SessionStore = InMemorySessionStore(),
|
sessionStore: SessionStore = InMemorySessionStore(),
|
||||||
) = RustMatrixClient(
|
) = RustMatrixClient(
|
||||||
client = FakeRustClient(),
|
innerClient = FakeRustClient(),
|
||||||
baseDirectory = File(""),
|
baseDirectory = File(""),
|
||||||
sessionStore = sessionStore,
|
sessionStore = sessionStore,
|
||||||
appCoroutineScope = this,
|
appCoroutineScope = this,
|
||||||
sessionDelegate = aRustClientSessionDelegate(
|
sessionDelegate = aRustClientSessionDelegate(
|
||||||
sessionStore = sessionStore,
|
sessionStore = sessionStore,
|
||||||
),
|
),
|
||||||
syncService = FakeRustSyncService(),
|
innerSyncService = FakeRustSyncService(),
|
||||||
dispatchers = testCoroutineDispatchers(),
|
dispatchers = testCoroutineDispatchers(),
|
||||||
baseCacheDirectory = File(""),
|
baseCacheDirectory = File(""),
|
||||||
clock = FakeSystemClock(),
|
clock = FakeSystemClock(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue