Cleanup to be able to merge.

This commit is contained in:
Benoit Marty 2025-09-26 12:10:41 +02:00 committed by Benoit Marty
parent 3c64eeb1c4
commit 6608d29fa0
2 changed files with 10 additions and 18 deletions

View file

@ -25,18 +25,17 @@ import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.architecture.runUpdatingState import io.element.android.libraries.architecture.runUpdatingState
import io.element.android.libraries.matrix.api.MatrixClient import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.previewutils.room.aSpaceRoom import io.element.android.libraries.matrix.api.spaces.SpaceRoom
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.jvm.optionals.getOrNull import kotlin.jvm.optionals.getOrNull
@Inject @Inject
class LeaveSpacePresenter( class LeaveSpacePresenter(
@Assisted private val inputs: SpaceEntryPoint.Inputs, @Assisted private val inputs: SpaceEntryPoint.Inputs,
private val matrixClient: MatrixClient, matrixClient: MatrixClient,
) : Presenter<LeaveSpaceState> { ) : Presenter<LeaveSpaceState> {
@AssistedFactory @AssistedFactory
fun interface Factory { fun interface Factory {
@ -57,14 +56,7 @@ class LeaveSpacePresenter(
} }
val joinedSpaceRooms by produceState(emptyList()) { val joinedSpaceRooms by produceState(emptyList()) {
// TODO Get the joined room from the SDK, should also have the // TODO Get the joined room from the SDK, should also have the
val rooms = listOf( val rooms = emptyList<SpaceRoom>()
aSpaceRoom(
roomId = RoomId("!roomId1:example.com"),
),
aSpaceRoom(
roomId = RoomId("!roomId2:example.com"),
),
)
// By default select all rooms // By default select all rooms
selectedRoomIds.value = rooms.map { it.roomId }.toSet() selectedRoomIds.value = rooms.map { it.roomId }.toSet()
value = rooms value = rooms
@ -77,10 +69,10 @@ class LeaveSpacePresenter(
value = AsyncData.Success( value = AsyncData.Success(
joinedSpaceRooms.map { joinedSpaceRooms.map {
SelectableSpaceRoom( SelectableSpaceRoom(
it, spaceRoom = it,
// TODO Get this value from the SDK // TODO Get this value from the SDK
isLastAdmin = false, isLastAdmin = false,
selectedRoomIds.value.contains(it.roomId), isSelected = selectedRoomIds.value.contains(it.roomId),
) )
}.toPersistentList() }.toPersistentList()
) )
@ -130,10 +122,7 @@ class LeaveSpacePresenter(
) = launch { ) = launch {
runUpdatingState(leaveSpaceAction) { runUpdatingState(leaveSpaceAction) {
// TODO SDK API call to leave all the rooms and space // TODO SDK API call to leave all the rooms and space
delay(1000) Result.failure(Exception("Not implemented"))
val room = matrixClient.getRoom(inputs.roomId)
?: return@runUpdatingState Result.failure(Exception("Room not found"))
room.leave()
} }
} }
} }

View file

@ -157,7 +157,7 @@ private fun LoadingMoreIndicator(
private fun SpaceViewTopBar( private fun SpaceViewTopBar(
state: SpaceState, state: SpaceState,
onBackClick: () -> Unit, onBackClick: () -> Unit,
onLeaveSpaceClick: () -> Unit, @Suppress("unused") onLeaveSpaceClick: () -> Unit,
onShareSpace: () -> Unit, onShareSpace: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
@ -203,6 +203,8 @@ private fun SpaceViewTopBar(
) )
} }
) )
/*
// TODO re-enable when we have SDK APIs to leave a space
DropdownMenuItem( DropdownMenuItem(
onClick = { onClick = {
showMenu = false showMenu = false
@ -217,6 +219,7 @@ private fun SpaceViewTopBar(
) )
} }
) )
*/
} }
}, },
) )