-
Notifications
You must be signed in to change notification settings - Fork 296
Leave space - UI #5354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Leave space - UI #5354
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
74c2ee4
Leave space - Add screen to leave a space.
bmarty cbd591e
Remove translations (key values have changed).
bmarty 9732d55
Add the (Admin) info.
bmarty de6f52c
Add unit test on LeaveSpaceState
bmarty f503bc4
Select all rooms by default
bmarty 5afe213
Update UI
bmarty b4232a8
Update tests
bmarty c1678b5
Cleanup to be able to merge.
bmarty 4d1a503
Metro now have `@AssistedInject`.
bmarty 6921117
Update screenshots
ElementBot 0e3efaf
Merge branch 'develop' into feature/bma/leaveSpace
bmarty c78aa7c
Update screenshots
ElementBot ef36922
Address review comments.
bmarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
features/space/impl/src/main/kotlin/io/element/android/features/space/impl/SpaceFlowNode.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
@file:OptIn(ExperimentalMaterial3Api::class) | ||
|
||
package io.element.android.features.space.impl | ||
|
||
import android.os.Parcelable | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.bumble.appyx.core.modality.BuildContext | ||
import com.bumble.appyx.core.node.Node | ||
import com.bumble.appyx.core.plugin.Plugin | ||
import com.bumble.appyx.navmodel.backstack.BackStack | ||
import com.bumble.appyx.navmodel.backstack.operation.push | ||
import dev.zacsweers.metro.Assisted | ||
import dev.zacsweers.metro.Inject | ||
import io.element.android.annotations.ContributesNode | ||
import io.element.android.features.space.api.SpaceEntryPoint | ||
import io.element.android.features.space.impl.leave.LeaveSpaceNode | ||
import io.element.android.features.space.impl.root.SpaceNode | ||
import io.element.android.libraries.architecture.BackstackView | ||
import io.element.android.libraries.architecture.BaseFlowNode | ||
import io.element.android.libraries.architecture.createNode | ||
import io.element.android.libraries.architecture.inputs | ||
import io.element.android.libraries.di.SessionScope | ||
import io.element.android.libraries.matrix.api.core.RoomId | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@ContributesNode(SessionScope::class) | ||
@Inject | ||
class SpaceFlowNode( | ||
@Assisted val buildContext: BuildContext, | ||
@Assisted plugins: List<Plugin>, | ||
) : BaseFlowNode<SpaceFlowNode.NavTarget>( | ||
backstack = BackStack( | ||
initialElement = NavTarget.Root, | ||
savedStateMap = buildContext.savedStateMap, | ||
), | ||
buildContext = buildContext, | ||
plugins = plugins, | ||
) { | ||
private val inputs: SpaceEntryPoint.Inputs = inputs() | ||
private val callback = plugins.filterIsInstance<SpaceEntryPoint.Callback>().single() | ||
|
||
sealed interface NavTarget : Parcelable { | ||
@Parcelize | ||
data object Root : NavTarget | ||
|
||
@Parcelize | ||
data object Leave : NavTarget | ||
} | ||
|
||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node { | ||
return when (navTarget) { | ||
NavTarget.Leave -> { | ||
createNode<LeaveSpaceNode>(buildContext, listOf(inputs)) | ||
} | ||
NavTarget.Root -> { | ||
val callback = object : SpaceNode.Callback { | ||
override fun onOpenRoom(roomId: RoomId, viaParameters: List<String>) { | ||
callback.onOpenRoom(roomId, viaParameters) | ||
} | ||
|
||
override fun onLeaveSpace() { | ||
backstack.push(NavTarget.Leave) | ||
} | ||
} | ||
createNode<SpaceNode>(buildContext, listOf(inputs, callback)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
override fun View(modifier: Modifier) = BackstackView() | ||
} |
18 changes: 18 additions & 0 deletions
18
...ace/impl/src/main/kotlin/io/element/android/features/space/impl/leave/LeaveSpaceEvents.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.space.impl.leave | ||
|
||
import io.element.android.libraries.matrix.api.core.RoomId | ||
|
||
sealed interface LeaveSpaceEvents { | ||
data object SelectAllRooms : LeaveSpaceEvents | ||
data object DeselectAllRooms : LeaveSpaceEvents | ||
data class ToggleRoomSelection(val roomId: RoomId) : LeaveSpaceEvents | ||
data object LeaveSpace : LeaveSpaceEvents | ||
data object CloseError : LeaveSpaceEvents | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
.../impl/src/main/kotlin/io/element/android/features/space/impl/leave/LeaveSpacePresenter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.space.impl.leave | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import dev.zacsweers.metro.Assisted | ||
import dev.zacsweers.metro.AssistedFactory | ||
import dev.zacsweers.metro.Inject | ||
import io.element.android.features.space.api.SpaceEntryPoint | ||
import io.element.android.libraries.architecture.AsyncAction | ||
import io.element.android.libraries.architecture.AsyncData | ||
import io.element.android.libraries.architecture.Presenter | ||
import io.element.android.libraries.architecture.runUpdatingState | ||
import io.element.android.libraries.matrix.api.MatrixClient | ||
import io.element.android.libraries.matrix.api.core.RoomId | ||
import io.element.android.libraries.previewutils.room.aSpaceRoom | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlin.jvm.optionals.getOrNull | ||
|
||
@Inject | ||
class LeaveSpacePresenter( | ||
@Assisted private val inputs: SpaceEntryPoint.Inputs, | ||
private val matrixClient: MatrixClient, | ||
) : Presenter<LeaveSpaceState> { | ||
@AssistedFactory | ||
fun interface Factory { | ||
fun create(inputs: SpaceEntryPoint.Inputs): LeaveSpacePresenter | ||
} | ||
|
||
private val spaceRoomList = matrixClient.spaceService.spaceRoomList(inputs.roomId) | ||
|
||
@Composable | ||
override fun present(): LeaveSpaceState { | ||
val coroutineScope = rememberCoroutineScope() | ||
val currentSpace by spaceRoomList.currentSpaceFlow.collectAsState() | ||
val leaveSpaceAction = remember { | ||
mutableStateOf<AsyncAction<Unit>>(AsyncAction.Uninitialized) | ||
} | ||
val selectedRoomIds = remember { | ||
mutableStateOf<Set<RoomId>>(emptySet()) | ||
} | ||
val joinedSpaceRooms by produceState(emptyList()) { | ||
// TODO Get the joined room from the SDK, should also have the | ||
val rooms = listOf( | ||
aSpaceRoom( | ||
roomId = RoomId("!roomId1:example.com"), | ||
), | ||
aSpaceRoom( | ||
roomId = RoomId("!roomId2:example.com"), | ||
), | ||
) | ||
value = rooms | ||
} | ||
val selectableSpaceRooms by produceState<AsyncData<ImmutableList<SelectableSpaceRoom>>>( | ||
initialValue = AsyncData.Uninitialized, | ||
key1 = joinedSpaceRooms, | ||
key2 = selectedRoomIds.value, | ||
) { | ||
value = AsyncData.Success( | ||
joinedSpaceRooms.map { | ||
SelectableSpaceRoom( | ||
it, | ||
// TODO Get this value from the SDK | ||
isLastAdmin = false, | ||
selectedRoomIds.value.contains(it.roomId), | ||
) | ||
}.toPersistentList() | ||
) | ||
} | ||
|
||
fun handleEvents(event: LeaveSpaceEvents) { | ||
when (event) { | ||
LeaveSpaceEvents.DeselectAllRooms -> selectedRoomIds.value = emptySet() | ||
LeaveSpaceEvents.SelectAllRooms -> { | ||
selectedRoomIds.value = selectableSpaceRooms.dataOrNull() | ||
.orEmpty() | ||
.filter { it.isLastAdmin.not() } | ||
.map { it.spaceRoom.roomId } | ||
.toSet() | ||
} | ||
is LeaveSpaceEvents.ToggleRoomSelection -> { | ||
val currentSet = selectedRoomIds.value | ||
selectedRoomIds.value = if (currentSet.contains(event.roomId)) { | ||
currentSet - event.roomId | ||
} else { | ||
currentSet + event.roomId | ||
} | ||
} | ||
LeaveSpaceEvents.LeaveSpace -> coroutineScope.leaveSpace( | ||
leaveSpaceAction = leaveSpaceAction, | ||
selectedRoomIds = selectedRoomIds.value, | ||
) | ||
LeaveSpaceEvents.CloseError -> { | ||
leaveSpaceAction.value = AsyncAction.Uninitialized | ||
} | ||
} | ||
} | ||
|
||
return LeaveSpaceState( | ||
spaceName = currentSpace.getOrNull()?.name, | ||
selectableSpaceRooms = selectableSpaceRooms, | ||
leaveSpaceAction = leaveSpaceAction.value, | ||
eventSink = ::handleEvents, | ||
) | ||
} | ||
|
||
private fun CoroutineScope.leaveSpace( | ||
leaveSpaceAction: MutableState<AsyncAction<Unit>>, | ||
@Suppress("unused") selectedRoomIds: Set<RoomId>, | ||
) = launch { | ||
runUpdatingState(leaveSpaceAction) { | ||
// TODO SDK API call to leave all the rooms and space | ||
delay(1000) | ||
val room = matrixClient.getRoom(inputs.roomId) | ||
?: return@runUpdatingState Result.failure(Exception("Room not found")) | ||
room.leave() | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...pace/impl/src/main/kotlin/io/element/android/features/space/impl/leave/LeaveSpaceState.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.space.impl.leave | ||
|
||
import io.element.android.libraries.architecture.AsyncAction | ||
import io.element.android.libraries.architecture.AsyncData | ||
import io.element.android.libraries.core.bool.orFalse | ||
import kotlinx.collections.immutable.ImmutableList | ||
|
||
data class LeaveSpaceState( | ||
val spaceName: String?, | ||
val selectableSpaceRooms: AsyncData<ImmutableList<SelectableSpaceRoom>>, | ||
val leaveSpaceAction: AsyncAction<Unit>, | ||
val eventSink: (LeaveSpaceEvents) -> Unit, | ||
) { | ||
val showQuickAction = selectableSpaceRooms.dataOrNull().orEmpty().any { !it.isLastAdmin } | ||
val hasOnlyLastAdminRoom = selectableSpaceRooms.dataOrNull() | ||
?.let { rooms -> | ||
rooms.isNotEmpty() && rooms.all { it.isLastAdmin } | ||
} | ||
.orFalse() | ||
val numberOfSelectRooms = selectableSpaceRooms.dataOrNull().orEmpty().count { it.isSelected } | ||
|
||
val areAllSelected = selectableSpaceRooms.dataOrNull() | ||
?.filter { !it.isLastAdmin } | ||
?.let { rooms -> | ||
rooms.isNotEmpty() && rooms.all { it.isSelected } | ||
} | ||
.orFalse() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems incomplete, so much suspense 🕵️ .