mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Remove previously used id filtering from RoomSyncSubscriber (#5985)
This is done in the SDK, doing it in the client was a source of issues.
This commit is contained in:
committed by
GitHub
parent
d3537bdd0f
commit
1f86a4d2c4
+4
-16
@@ -21,18 +21,14 @@ class RoomSyncSubscriber(
|
|||||||
private val roomListService: RoomListService,
|
private val roomListService: RoomListService,
|
||||||
private val dispatchers: CoroutineDispatchers,
|
private val dispatchers: CoroutineDispatchers,
|
||||||
) {
|
) {
|
||||||
private val subscribedRoomIds = mutableSetOf<RoomId>()
|
|
||||||
private val mutex = Mutex()
|
private val mutex = Mutex()
|
||||||
|
|
||||||
suspend fun subscribe(roomId: RoomId) {
|
suspend fun subscribe(roomId: RoomId) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
withContext(dispatchers.io) {
|
withContext(dispatchers.io) {
|
||||||
try {
|
try {
|
||||||
if (!isSubscribedTo(roomId)) {
|
Timber.d("Subscribing to room $roomId}")
|
||||||
Timber.d("Subscribing to room $roomId}")
|
roomListService.subscribeToRooms(listOf(roomId.value))
|
||||||
roomListService.subscribeToRooms(listOf(roomId.value))
|
|
||||||
}
|
|
||||||
subscribedRoomIds.add(roomId)
|
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Timber.e(exception, "Failed to subscribe to room $roomId")
|
Timber.e(exception, "Failed to subscribe to room $roomId")
|
||||||
}
|
}
|
||||||
@@ -43,12 +39,8 @@ class RoomSyncSubscriber(
|
|||||||
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
|
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
|
||||||
withContext(dispatchers.io) {
|
withContext(dispatchers.io) {
|
||||||
try {
|
try {
|
||||||
val roomIdsToSubscribeTo = roomIds.filterNot { isSubscribedTo(it) }
|
Timber.d("Subscribing to rooms: $roomIds")
|
||||||
if (roomIdsToSubscribeTo.isNotEmpty()) {
|
roomListService.subscribeToRooms(roomIds.map { it.value })
|
||||||
Timber.d("Subscribing to rooms: $roomIds")
|
|
||||||
roomListService.subscribeToRooms(roomIdsToSubscribeTo.map { it.value })
|
|
||||||
subscribedRoomIds.addAll(roomIds)
|
|
||||||
}
|
|
||||||
} catch (cancellationException: CancellationException) {
|
} catch (cancellationException: CancellationException) {
|
||||||
throw cancellationException
|
throw cancellationException
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
@@ -56,8 +48,4 @@ class RoomSyncSubscriber(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSubscribedTo(roomId: RoomId): Boolean {
|
|
||||||
return subscribedRoomIds.contains(roomId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user