Skip to content

Commit 4d0180f

Browse files
authored
Merge pull request #1376 from vector-im/feature/fga/fix_room_member_infinite_loop
Fix room member infinite loop
2 parents d784ca3 + c3df84c commit 4d0180f

File tree

1 file changed

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

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 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
@@ -59,6 +59,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
5959
import kotlinx.coroutines.flow.StateFlow
6060
import kotlinx.coroutines.flow.asStateFlow
6161
import kotlinx.coroutines.withContext
62+
import kotlinx.coroutines.yield
6263
import org.matrix.rustcomponents.sdk.RequiredState
6364
import org.matrix.rustcomponents.sdk.Room
6465
import org.matrix.rustcomponents.sdk.RoomListItem
@@ -187,18 +188,22 @@ class RustMatrixRoom(
187188
_membersStateFlow.value = MatrixRoomMembersState.Pending(prevRoomMembers = currentMembers)
188189
var rustMembers: List<RoomMember>? = null
189190
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)
191+
rustMembers = innerRoom.members().use { membersIterator ->
192+
buildList {
193+
while (true) {
194+
// Loading the whole membersIterator as a stop-gap measure.
195+
// We should probably implement some sort of paging in the future.
196+
yield()
197+
addAll(membersIterator.nextChunk(1000u) ?: break)
198+
}
195199
}
196200
}
197201
val mappedMembers = rustMembers.parallelMap(RoomMemberMapper::map)
198202
_membersStateFlow.value = MatrixRoomMembersState.Ready(mappedMembers)
199203
Result.success(Unit)
200-
} catch (cancellationException: CancellationException) {
201-
throw cancellationException
204+
} catch (exception: CancellationException) {
205+
_membersStateFlow.value = MatrixRoomMembersState.Error(prevRoomMembers = currentMembers, failure = exception)
206+
throw exception
202207
} catch (exception: Exception) {
203208
_membersStateFlow.value = MatrixRoomMembersState.Error(prevRoomMembers = currentMembers, failure = exception)
204209
Result.failure(exception)
@@ -466,7 +471,7 @@ class RustMatrixRoom(
466471
}
467472

468473
private fun messageEventContentFromParts(body: String, htmlBody: String?): RoomMessageEventContentWithoutRelation =
469-
if(htmlBody != null) {
474+
if (htmlBody != null) {
470475
messageEventContentFromHtml(body, htmlBody)
471476
} else {
472477
messageEventContentFromMarkdown(body)

0 commit comments

Comments
 (0)