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:
parent
186568a025
commit
c75ffc6af1
1 changed files with 4 additions and 16 deletions
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue