mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Ensure getRootSpaceSummaries()
is not called on the main thread.
This commit is contained in:
parent
3a9bacd7a8
commit
cd06ba656a
4 changed files with 16 additions and 6 deletions
|
@ -475,7 +475,9 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
// + C
|
||||
// + c1, c2
|
||||
|
||||
val rootSpaces = session.spaceService().getRootSpaceSummaries()
|
||||
val rootSpaces = commonTestHelper.runBlockingTest {
|
||||
session.spaceService().getRootSpaceSummaries()
|
||||
}
|
||||
|
||||
assertEquals("Unexpected number of root spaces ${rootSpaces.map { it.name }}", 2, rootSpaces.size)
|
||||
|
||||
|
|
|
@ -106,5 +106,8 @@ interface SpaceService {
|
|||
|
||||
suspend fun removeSpaceParent(childRoomId: String, parentSpaceId: String)
|
||||
|
||||
fun getRootSpaceSummaries(): List<RoomSummary>
|
||||
/**
|
||||
* Get the root spaces, i.e. all the spaces which do not have a parent space.
|
||||
*/
|
||||
suspend fun getRootSpaceSummaries(): List<RoomSummary>
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.session.space
|
|||
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.LiveData
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
|
@ -64,7 +66,8 @@ internal class DefaultSpaceService @Inject constructor(
|
|||
private val stateEventDataSource: StateEventDataSource,
|
||||
private val peekSpaceTask: PeekSpaceTask,
|
||||
private val resolveSpaceInfoTask: ResolveSpaceInfoTask,
|
||||
private val leaveRoomTask: LeaveRoomTask
|
||||
private val leaveRoomTask: LeaveRoomTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
) : SpaceService {
|
||||
|
||||
override suspend fun createSpace(params: CreateSpaceParams): String {
|
||||
|
@ -105,8 +108,10 @@ internal class DefaultSpaceService @Inject constructor(
|
|||
return roomSummaryDataSource.getSpaceSummaries(spaceSummaryQueryParams, sortOrder)
|
||||
}
|
||||
|
||||
override fun getRootSpaceSummaries(): List<RoomSummary> {
|
||||
return roomSummaryDataSource.getRootSpaceSummaries()
|
||||
override suspend fun getRootSpaceSummaries(): List<RoomSummary> {
|
||||
return withContext(coroutineDispatchers.io) {
|
||||
roomSummaryDataSource.getRootSpaceSummaries()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun peekSpace(spaceId: String): SpacePeekResult {
|
||||
|
|
|
@ -296,7 +296,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
|||
communityGroups
|
||||
}
|
||||
.execute { async ->
|
||||
val rootSpaces = session.spaceService().getRootSpaceSummaries()
|
||||
val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
|
||||
val orders = rootSpaces.map {
|
||||
it.roomId to session.getRoom(it.roomId)
|
||||
?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)
|
||||
|
|
Loading…
Reference in a new issue