Show current user in the settings and extract code in CurrentUserProvider.
This commit is contained in:
parent
b4a5128a05
commit
e1b528e861
12 changed files with 226 additions and 69 deletions
|
|
@ -26,10 +26,10 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import io.element.android.features.networkmonitor.api.NetworkMonitor
|
||||
import io.element.android.features.networkmonitor.api.NetworkStatus
|
||||
import io.element.android.features.leaveroom.api.LeaveRoomEvent
|
||||
import io.element.android.features.leaveroom.api.LeaveRoomPresenter
|
||||
import io.element.android.features.networkmonitor.api.NetworkMonitor
|
||||
import io.element.android.features.networkmonitor.api.NetworkStatus
|
||||
import io.element.android.features.roomlist.impl.model.RoomListRoomSummary
|
||||
import io.element.android.features.roomlist.impl.model.RoomListRoomSummaryPlaceholders
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
|
|
@ -43,8 +43,8 @@ import io.element.android.libraries.designsystem.utils.collectSnackbarMessageAsS
|
|||
import io.element.android.libraries.eventformatter.api.RoomLastMessageFormatter
|
||||
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.UserId
|
||||
import io.element.android.libraries.matrix.api.room.RoomSummary
|
||||
import io.element.android.libraries.matrix.api.user.CurrentUserProvider
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
|
||||
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
|
||||
|
|
@ -60,6 +60,7 @@ private const val extendedRangeSize = 40
|
|||
|
||||
class RoomListPresenter @Inject constructor(
|
||||
private val client: MatrixClient,
|
||||
private val currentUserProvider: CurrentUserProvider,
|
||||
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
|
||||
private val roomLastMessageFormatter: RoomLastMessageFormatter,
|
||||
private val sessionVerificationService: SessionVerificationService,
|
||||
|
|
@ -162,13 +163,7 @@ class RoomListPresenter @Inject constructor(
|
|||
}
|
||||
|
||||
private fun CoroutineScope.initialLoad(matrixUser: MutableState<MatrixUser?>) = launch {
|
||||
val userAvatarUrl = client.loadUserAvatarURLString().getOrNull()
|
||||
val userDisplayName = client.loadUserDisplayName().getOrNull()
|
||||
matrixUser.value = MatrixUser(
|
||||
userId = UserId(client.sessionId.value),
|
||||
displayName = userDisplayName,
|
||||
avatarUrl = userAvatarUrl,
|
||||
)
|
||||
matrixUser.value = currentUserProvider.provide()
|
||||
}
|
||||
|
||||
private fun updateVisibleRange(range: IntRange) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
|||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
||||
import io.element.android.libraries.eventformatter.test.FakeRoomLastMessageFormatter
|
||||
import io.element.android.libraries.matrix.api.user.CurrentUserProvider
|
||||
import io.element.android.libraries.matrix.api.verification.SessionVerifiedStatus
|
||||
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
|
||||
import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
||||
|
|
@ -50,8 +51,10 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - should start with no user and then load user with success`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -75,11 +78,13 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - should start with no user and then load user with error`() = runTest {
|
||||
val matrixClient = FakeMatrixClient(
|
||||
userDisplayName = Result.failure(AN_EXCEPTION),
|
||||
userAvatarURLString = Result.failure(AN_EXCEPTION),
|
||||
)
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(
|
||||
userDisplayName = Result.failure(AN_EXCEPTION),
|
||||
userAvatarURLString = Result.failure(AN_EXCEPTION),
|
||||
),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -100,8 +105,10 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - should filter room with success`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -127,10 +134,12 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - load 1 room with success`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
)
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -159,10 +168,12 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - load 1 room with success and filter rooms`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
)
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -197,10 +208,12 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - update visible range`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
)
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -245,10 +258,12 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - handle DismissRequestVerificationPrompt`() = runTest {
|
||||
val roomSummaryDataSource = FakeRoomSummaryDataSource()
|
||||
val matrixClient = FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
)
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(
|
||||
roomSummaryDataSource = roomSummaryDataSource
|
||||
),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService().apply {
|
||||
|
|
@ -274,8 +289,10 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - sets invite state`() = runTest {
|
||||
val inviteStateFlow = MutableStateFlow(InvitesState.NoInvites)
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -304,8 +321,10 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - show context menu`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -331,8 +350,10 @@ class RoomListPresenterTests {
|
|||
|
||||
@Test
|
||||
fun `present - hide context menu`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
@ -363,8 +384,10 @@ class RoomListPresenterTests {
|
|||
@Test
|
||||
fun `present - leave room calls into leave room presenter`() = runTest {
|
||||
val leaveRoomPresenter = LeaveRoomPresenterFake()
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val presenter = RoomListPresenter(
|
||||
FakeMatrixClient(),
|
||||
matrixClient,
|
||||
CurrentUserProvider(matrixClient),
|
||||
createDateFormatter(),
|
||||
FakeRoomLastMessageFormatter(),
|
||||
FakeSessionVerificationService(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue