[Room member list] Display room member list (#276)

* Implement room member list

* Move timeline initialization back to `TimelinePresenter`.

* Fix crash when the `innerRoom` inside a `RustMatrixRoom` is destroyed but `syncUpdateFlow` is still running.

* Address review comments
This commit is contained in:
Jorge Martin Espinosa
2023-04-04 18:07:57 +02:00
committed by GitHub
parent f0b95d30be
commit d7a6779343
62 changed files with 1159 additions and 157 deletions

View File

@@ -69,6 +69,8 @@ class RoomFlowNode @AssistedInject constructor(
private val inputs: Inputs = inputs()
private val roomFlowPresenter = RoomFlowPresenter(inputs.room)
init {
lifecycle.subscribe(
onCreate = {
@@ -110,6 +112,7 @@ class RoomFlowNode @AssistedInject constructor(
@Composable
override fun View(modifier: Modifier) {
roomFlowPresenter.present()
Children(
navModel = backstack,
modifier = modifier,

View File

@@ -0,0 +1,46 @@
/*
* 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

View File

@@ -0,0 +1,62 @@
/*
* 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 app.cash.molecule.RecompositionClock
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
import io.element.android.libraries.matrix.test.timeline.FakeMatrixTimeline
import kotlinx.coroutines.test.runTest
import org.junit.Test
import java.lang.IllegalStateException
class RoomFlowPresenterTest {
@Test
fun `present - fetches room members`() = runTest {
val fakeTimeline = FakeMatrixTimeline()
val room = FakeMatrixRoom(matrixTimeline = fakeTimeline)
val presenter = RoomFlowPresenter(room)
Truth.assertThat(room.areMembersFetched).isFalse()
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
Truth.assertThat(room.areMembersFetched).isTrue()
cancelAndIgnoreRemainingEvents()
}
}
@Test
fun `present - recovers from error while fetching room members`() = runTest {
val fakeTimeline = FakeMatrixTimeline()
val room = FakeMatrixRoom(matrixTimeline = fakeTimeline).apply {
givenFetchMemberResult(Result.failure(IllegalStateException("Some error")))
}
val presenter = RoomFlowPresenter(room)
Truth.assertThat(room.areMembersFetched).isFalse()
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
Truth.assertThat(room.areMembersFetched).isFalse()
cancelAndIgnoreRemainingEvents()
}
}
}