Some clean up on room details
This commit is contained in:
parent
7a247e1c29
commit
281f90e148
7 changed files with 37 additions and 71 deletions
|
|
@ -18,8 +18,8 @@ package io.element.android.appnav
|
|||
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.bumble.appyx.core.composable.Children
|
||||
import com.bumble.appyx.core.lifecycle.subscribe
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
|
|
@ -45,6 +45,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -56,7 +57,6 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
private val roomDetailsEntryPoint: RoomDetailsEntryPoint,
|
||||
private val appNavigationStateService: AppNavigationStateService,
|
||||
roomMembershipObserver: RoomMembershipObserver,
|
||||
coroutineScope: CoroutineScope,
|
||||
) : BackstackNode<RoomFlowNode.NavTarget>(
|
||||
backstack = BackStack(
|
||||
initialElement = NavTarget.Messages,
|
||||
|
|
@ -76,9 +76,6 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
) : NodeInputs
|
||||
|
||||
private val inputs: Inputs = inputs()
|
||||
private val timeline = inputs.room.timeline()
|
||||
|
||||
private val roomFlowPresenter = RoomFlowPresenter(inputs.room)
|
||||
|
||||
init {
|
||||
lifecycle.subscribe(
|
||||
|
|
@ -95,22 +92,34 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
}
|
||||
)
|
||||
|
||||
lifecycleScope.fetchRoomMembers()
|
||||
roomMembershipObserver.updates
|
||||
.filter { update -> update.roomId == inputs.room.roomId && !update.isUserInRoom }
|
||||
.onEach {
|
||||
navigateUp()
|
||||
}
|
||||
.launchIn(coroutineScope)
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.fetchRoomMembers() = launch {
|
||||
val room = inputs.room
|
||||
room.fetchMembers()
|
||||
.onFailure {
|
||||
Timber.e(it, "Fail to fetch members for room ${room.roomId}")
|
||||
}.onSuccess {
|
||||
Timber.v("Success fetching members for room ${room.roomId}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||
return when (navTarget) {
|
||||
NavTarget.Messages -> {
|
||||
messagesEntryPoint.createNode(this, buildContext, object : MessagesEntryPoint.Callback {
|
||||
val callback = object : MessagesEntryPoint.Callback {
|
||||
override fun onRoomDetailsClicked() {
|
||||
backstack.push(NavTarget.RoomDetails)
|
||||
}
|
||||
})
|
||||
}
|
||||
messagesEntryPoint.createNode(this, buildContext, callback)
|
||||
}
|
||||
NavTarget.RoomDetails -> {
|
||||
roomDetailsEntryPoint.createNode(this, buildContext, emptyList())
|
||||
|
|
@ -128,7 +137,6 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
roomFlowPresenter.present()
|
||||
Children(
|
||||
navModel = backstack,
|
||||
modifier = modifier,
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.appnav
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||
import timber.log.Timber
|
||||
|
||||
class RoomFlowPresenter(
|
||||
private val room: MatrixRoom,
|
||||
) : Presenter<RoomFlowState> {
|
||||
|
||||
@Composable
|
||||
override fun present(): RoomFlowState {
|
||||
// Preload room members so we can quickly detect if the room is a DM room
|
||||
LaunchedEffect(Unit) {
|
||||
room.fetchMembers()
|
||||
.onFailure {
|
||||
Timber.e(it, "Fail to fetch members for room ${room.roomId}")
|
||||
}.onSuccess {
|
||||
Timber.v("Success fetching members for room ${room.roomId}")
|
||||
}
|
||||
}
|
||||
|
||||
return RoomFlowState
|
||||
}
|
||||
}
|
||||
|
||||
// At first the return type was Unit, but detekt complained about it
|
||||
object RoomFlowState
|
||||
|
|
@ -56,19 +56,16 @@ class RoomDetailsFlowNode @AssistedInject constructor(
|
|||
object RoomMemberList : NavTarget
|
||||
}
|
||||
|
||||
interface Callback : Plugin {
|
||||
fun openRoomMemberList()
|
||||
}
|
||||
|
||||
val callback = object : Callback {
|
||||
override fun openRoomMemberList() {
|
||||
backstack.push(NavTarget.RoomMemberList)
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||
return when (navTarget) {
|
||||
NavTarget.RoomDetails -> createNode<RoomDetailsNode>(buildContext, listOf(callback))
|
||||
NavTarget.RoomDetails -> {
|
||||
val callback = object : RoomDetailsNode.Callback {
|
||||
override fun openRoomMemberList() {
|
||||
backstack.push(NavTarget.RoomMemberList)
|
||||
}
|
||||
}
|
||||
createNode<RoomDetailsNode>(buildContext, listOf(callback))
|
||||
}
|
||||
NavTarget.RoomMemberList -> createNode<RoomMemberListNode>(buildContext)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,11 @@ class RoomDetailsNode @AssistedInject constructor(
|
|||
private val room: MatrixRoom,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
|
||||
private val callback = plugins<RoomDetailsFlowNode.Callback>().firstOrNull()
|
||||
interface Callback : Plugin {
|
||||
fun openRoomMemberList()
|
||||
}
|
||||
|
||||
private val callback = plugins<Callback>().firstOrNull()
|
||||
|
||||
private fun openRoomMemberList() {
|
||||
callback?.openRoomMemberList()
|
||||
|
|
|
|||
|
|
@ -56,5 +56,5 @@ interface MatrixRoom: Closeable {
|
|||
|
||||
suspend fun redactEvent(eventId: EventId, reason: String? = null): Result<Unit>
|
||||
|
||||
fun leave(): Result<Unit>
|
||||
suspend fun leave(): Result<Unit>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ class RustMatrixRoom(
|
|||
coroutineDispatchers = coroutineDispatchers
|
||||
)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
innerRoom.destroy()
|
||||
slidingSyncRoom.destroy()
|
||||
|
|
@ -183,7 +184,9 @@ class RustMatrixRoom(
|
|||
}
|
||||
}
|
||||
|
||||
override fun leave(): Result<Unit> {
|
||||
return runCatching { innerRoom.leave() }
|
||||
override suspend fun leave(): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||
runCatching {
|
||||
innerRoom.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class FakeMatrixRoom(
|
|||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override fun leave(): Result<Unit> = leaveRoomError?.let { Result.failure(it) } ?: Result.success(Unit)
|
||||
override suspend fun leave(): Result<Unit> = leaveRoomError?.let { Result.failure(it) } ?: Result.success(Unit)
|
||||
|
||||
override fun close() = Unit
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue