@@ -44,8 +44,8 @@ import io.element.android.libraries.matrix.api.timeline.item.event.EventType
4444import io.element.android.libraries.matrix.impl.core.toProgressWatcher
4545import io.element.android.libraries.matrix.impl.media.MediaUploadHandlerImpl
4646import io.element.android.libraries.matrix.impl.media.map
47- import io.element.android.libraries.matrix.impl.poll.toInner
4847import io.element.android.libraries.matrix.impl.notificationsettings.RustNotificationSettingsService
48+ import io.element.android.libraries.matrix.impl.poll.toInner
4949import io.element.android.libraries.matrix.impl.room.location.toInner
5050import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
5151import io.element.android.libraries.matrix.impl.util.destroyAll
@@ -59,6 +59,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
5959import kotlinx.coroutines.flow.StateFlow
6060import kotlinx.coroutines.flow.asStateFlow
6161import kotlinx.coroutines.withContext
62+ import kotlinx.coroutines.yield
6263import org.matrix.rustcomponents.sdk.RequiredState
6364import org.matrix.rustcomponents.sdk.Room
6465import 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