Skip to content

Commit 0bd6ba0

Browse files
committed
Fix room member infinite loop
1 parent f1ad735 commit 0bd6ba0

File tree

1 file changed

+14
-10
lines changed
  • libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import io.element.android.libraries.matrix.api.timeline.item.event.EventType
4444
import io.element.android.libraries.matrix.impl.core.toProgressWatcher
4545
import io.element.android.libraries.matrix.impl.media.MediaUploadHandlerImpl
4646
import io.element.android.libraries.matrix.impl.media.map
47-
import io.element.android.libraries.matrix.impl.poll.toInner
4847
import io.element.android.libraries.matrix.impl.notificationsettings.RustNotificationSettingsService
48+
import io.element.android.libraries.matrix.impl.poll.toInner
4949
import io.element.android.libraries.matrix.impl.room.location.toInner
5050
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
5151
import io.element.android.libraries.matrix.impl.util.destroyAll
@@ -187,21 +187,25 @@ class RustMatrixRoom(
187187
_membersStateFlow.value = MatrixRoomMembersState.Pending(prevRoomMembers = currentMembers)
188188
var rustMembers: List<RoomMember>? = null
189189
try {
190-
rustMembers = buildList {
191-
while (true) {
192-
// Loading the whole iterator as a stop-gap measure.
193-
// We should probably implement some sort of paging in the future.
194-
addAll(innerRoom.members().nextChunk(1000u) ?: break)
190+
rustMembers = innerRoom.members().use { membersIterator ->
191+
buildList {
192+
while (true) {
193+
// Loading the whole membersIterator as a stop-gap measure.
194+
// We should probably implement some sort of paging in the future.
195+
addAll(membersIterator.nextChunk(1000u) ?: break)
196+
}
195197
}
196198
}
197199
val mappedMembers = rustMembers.parallelMap(RoomMemberMapper::map)
198200
_membersStateFlow.value = MatrixRoomMembersState.Ready(mappedMembers)
199201
Result.success(Unit)
200-
} catch (cancellationException: CancellationException) {
201-
throw cancellationException
202202
} catch (exception: Exception) {
203203
_membersStateFlow.value = MatrixRoomMembersState.Error(prevRoomMembers = currentMembers, failure = exception)
204-
Result.failure(exception)
204+
if (exception is CancellationException) {
205+
throw exception
206+
} else {
207+
Result.failure(exception)
208+
}
205209
} finally {
206210
rustMembers?.destroyAll()
207211
}
@@ -466,7 +470,7 @@ class RustMatrixRoom(
466470
}
467471

468472
private fun messageEventContentFromParts(body: String, htmlBody: String?): RoomMessageEventContentWithoutRelation =
469-
if(htmlBody != null) {
473+
if (htmlBody != null) {
470474
messageEventContentFromHtml(body, htmlBody)
471475
} else {
472476
messageEventContentFromMarkdown(body)

0 commit comments

Comments
 (0)