Update the SDK bindings to v0.2.39 (#3288)
- Rework `RoomSyncSubscriber` to work with the new `RoomListService.subscribeToRooms` API.
This commit is contained in:
parent
0b8e888540
commit
65718b3e96
4 changed files with 25 additions and 26 deletions
|
|
@ -51,23 +51,15 @@ class RoomSyncSubscriber(
|
|||
includeHeroes = false,
|
||||
)
|
||||
|
||||
suspend fun subscribe(roomId: RoomId) = mutex.withLock {
|
||||
withContext(dispatchers.io) {
|
||||
try {
|
||||
subscribeToRoom(roomId)
|
||||
} catch (exception: Exception) {
|
||||
Timber.e("Failed to subscribe to room $roomId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
|
||||
withContext(dispatchers.io) {
|
||||
for (roomId in roomIds) {
|
||||
suspend fun subscribe(roomId: RoomId) {
|
||||
mutex.withLock {
|
||||
withContext(dispatchers.io) {
|
||||
try {
|
||||
subscribeToRoom(roomId)
|
||||
} catch (cancellationException: CancellationException) {
|
||||
throw cancellationException
|
||||
if (!isSubscribedTo(roomId)) {
|
||||
Timber.d("Subscribing to room $roomId}")
|
||||
roomListService.subscribeToRooms(listOf(roomId.value), settings)
|
||||
}
|
||||
subscribedRoomIds.add(roomId)
|
||||
} catch (exception: Exception) {
|
||||
Timber.e("Failed to subscribe to room $roomId")
|
||||
}
|
||||
|
|
@ -75,14 +67,21 @@ class RoomSyncSubscriber(
|
|||
}
|
||||
}
|
||||
|
||||
private fun subscribeToRoom(roomId: RoomId) {
|
||||
if (!isSubscribedTo(roomId)) {
|
||||
Timber.d("Subscribing to room $roomId}")
|
||||
roomListService.room(roomId.value).use { roomListItem ->
|
||||
roomListItem.subscribe(settings)
|
||||
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
|
||||
withContext(dispatchers.io) {
|
||||
try {
|
||||
val roomIdsToSubscribeTo = roomIds.filterNot { isSubscribedTo(it) }
|
||||
if (roomIdsToSubscribeTo.isNotEmpty()) {
|
||||
Timber.d("Subscribing to rooms: $roomIds")
|
||||
roomListService.subscribeToRooms(roomIdsToSubscribeTo.map { it.value }, settings)
|
||||
subscribedRoomIds.addAll(roomIds)
|
||||
}
|
||||
} catch (cancellationException: CancellationException) {
|
||||
throw cancellationException
|
||||
} catch (exception: Exception) {
|
||||
Timber.e(exception, "Failed to subscribe to rooms: $roomIds")
|
||||
}
|
||||
}
|
||||
subscribedRoomIds.add(roomId)
|
||||
}
|
||||
|
||||
fun isSubscribedTo(roomId: RoomId): Boolean {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,8 @@ class RoomSummaryListProcessorTest {
|
|||
override fun syncIndicator(delayBeforeShowingInMs: UInt, delayBeforeHidingInMs: UInt, listener: RoomListServiceSyncIndicatorListener): TaskHandle {
|
||||
return TaskHandle(Pointer.NULL)
|
||||
}
|
||||
|
||||
override fun subscribeToRooms(roomIds: List<String>, settings: RoomSubscription?) = Unit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -270,6 +272,4 @@ class FakeRoomListItem(
|
|||
override suspend fun latestEvent(): EventTimelineItem? {
|
||||
return latestEvent
|
||||
}
|
||||
|
||||
override fun subscribe(settings: RoomSubscription?) = Unit
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue