Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

not for this PR as it would introduce lots of changes, but worth highlighting in case we want guard against other cases

from my understanding the general approach of coroutines scoping is to define the context switching at the lowest possible level, which in this case would be

monarchy.fetchAllMappedSync

we already have a similar wrapper for awaitTransaction

this would also force non coroutine based usages to rely on runBlocking, which would have the benefit of make finding the usages a bit easier

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, good point!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we might want to dispatch querying db to a background thread, to avoid blocking the dispatcher, as Retrofit does for request (and probably Room)

roomSummaryDataSource.getRootSpaceSummaries()
}
}

override suspend fun peekSpace(spaceId: String): SpacePeekResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
communityGroups

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename this to spaceList

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I wanted to limit the number of changes for the hotfix

}
.execute { async ->
val rootSpaces = session.spaceService().getRootSpaceSummaries()
val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my side this is equivalent, but I do not have any spaces with child space. I will create some

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it works as expected

val orders = rootSpaces.map {
it.roomId to session.getRoom(it.roomId)
?.getAccountDataEvent(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)
Expand Down