Skip to content

Commit 65718b3

Browse files
authored
Update the SDK bindings to v0.2.39 (#3288)
- Rework `RoomSyncSubscriber` to work with the new `RoomListService.subscribeToRooms` API.
1 parent 0b8e888 commit 65718b3

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jsoup = "org.jsoup:jsoup:1.18.1"
163163
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
164164
molecule-runtime = "app.cash.molecule:molecule-runtime:2.0.0"
165165
timber = "com.jakewharton.timber:timber:5.0.1"
166-
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.38"
166+
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.39"
167167
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
168168
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
169169
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomSyncSubscriber.kt

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,37 @@ class RoomSyncSubscriber(
5151
includeHeroes = false,
5252
)
5353

54-
suspend fun subscribe(roomId: RoomId) = mutex.withLock {
55-
withContext(dispatchers.io) {
56-
try {
57-
subscribeToRoom(roomId)
58-
} catch (exception: Exception) {
59-
Timber.e("Failed to subscribe to room $roomId")
60-
}
61-
}
62-
}
63-
64-
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
65-
withContext(dispatchers.io) {
66-
for (roomId in roomIds) {
54+
suspend fun subscribe(roomId: RoomId) {
55+
mutex.withLock {
56+
withContext(dispatchers.io) {
6757
try {
68-
subscribeToRoom(roomId)
69-
} catch (cancellationException: CancellationException) {
70-
throw cancellationException
58+
if (!isSubscribedTo(roomId)) {
59+
Timber.d("Subscribing to room $roomId}")
60+
roomListService.subscribeToRooms(listOf(roomId.value), settings)
61+
}
62+
subscribedRoomIds.add(roomId)
7163
} catch (exception: Exception) {
7264
Timber.e("Failed to subscribe to room $roomId")
7365
}
7466
}
7567
}
7668
}
7769

78-
private fun subscribeToRoom(roomId: RoomId) {
79-
if (!isSubscribedTo(roomId)) {
80-
Timber.d("Subscribing to room $roomId}")
81-
roomListService.room(roomId.value).use { roomListItem ->
82-
roomListItem.subscribe(settings)
70+
suspend fun batchSubscribe(roomIds: List<RoomId>) = mutex.withLock {
71+
withContext(dispatchers.io) {
72+
try {
73+
val roomIdsToSubscribeTo = roomIds.filterNot { isSubscribedTo(it) }
74+
if (roomIdsToSubscribeTo.isNotEmpty()) {
75+
Timber.d("Subscribing to rooms: $roomIds")
76+
roomListService.subscribeToRooms(roomIdsToSubscribeTo.map { it.value }, settings)
77+
subscribedRoomIds.addAll(roomIds)
78+
}
79+
} catch (cancellationException: CancellationException) {
80+
throw cancellationException
81+
} catch (exception: Exception) {
82+
Timber.e(exception, "Failed to subscribe to rooms: $roomIds")
8383
}
8484
}
85-
subscribedRoomIds.add(roomId)
8685
}
8786

8887
fun isSubscribedTo(roomId: RoomId): Boolean {

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomSummaryListProcessorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class RoomSummaryListProcessorTest {
189189
override fun syncIndicator(delayBeforeShowingInMs: UInt, delayBeforeHidingInMs: UInt, listener: RoomListServiceSyncIndicatorListener): TaskHandle {
190190
return TaskHandle(Pointer.NULL)
191191
}
192+
193+
override fun subscribeToRooms(roomIds: List<String>, settings: RoomSubscription?) = Unit
192194
}
193195
}
194196

@@ -270,6 +272,4 @@ class FakeRoomListItem(
270272
override suspend fun latestEvent(): EventTimelineItem? {
271273
return latestEvent
272274
}
273-
274-
override fun subscribe(settings: RoomSubscription?) = Unit
275275
}

0 commit comments

Comments
 (0)