diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenter.kt index 2594fd5509..eccc8dd9d2 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenter.kt @@ -43,7 +43,6 @@ import io.element.android.libraries.matrix.ui.room.getDirectRoomMember import io.element.android.libraries.matrix.ui.room.isOwnUserAdmin import io.element.android.services.analytics.api.AnalyticsService import io.element.android.services.analyticsproviders.api.trackers.captureInteraction -import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.launchIn @@ -113,21 +112,6 @@ class RoomDetailsPresenter @Inject constructor( val roomNotificationSettingsState by room.roomNotificationSettingsStateFlow.collectAsState() - val roomBadges by produceState(persistentListOf(), isPublic) { - value = buildList { - if (room.isEncrypted || isPublic) { - if (room.isEncrypted) { - add(RoomBadge.ENCRYPTED) - } else { - add(RoomBadge.NOT_ENCRYPTED) - } - } - if (isPublic) { - add(RoomBadge.PUBLIC) - } - }.toPersistentList() - } - fun handleEvents(event: RoomDetailsEvent) { when (event) { RoomDetailsEvent.LeaveRoom -> @@ -167,7 +151,6 @@ class RoomDetailsPresenter @Inject constructor( isFavorite = isFavorite, displayRolesAndPermissionsSettings = !room.isDm && isUserAdmin, isPublic = isPublic, - roomBadges = roomBadges, heroes = roomInfo?.heroes.orEmpty().toPersistentList(), canShowPinnedMessages = canShowPinnedMessages, pinnedMessagesCount = pinnedMessagesCount, diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsState.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsState.kt index 21fa239c82..2208748563 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsState.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsState.kt @@ -16,6 +16,7 @@ import io.element.android.libraries.matrix.api.room.RoomMember import io.element.android.libraries.matrix.api.room.RoomNotificationSettings import io.element.android.libraries.matrix.api.user.MatrixUser import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toPersistentList data class RoomDetailsState( val roomId: RoomId, @@ -36,12 +37,24 @@ data class RoomDetailsState( val isFavorite: Boolean, val displayRolesAndPermissionsSettings: Boolean, val isPublic: Boolean, - val roomBadges: ImmutableList, val heroes: ImmutableList, val canShowPinnedMessages: Boolean, val pinnedMessagesCount: Int?, val eventSink: (RoomDetailsEvent) -> Unit -) +) { + val roomBadges = buildList { + if (isEncrypted || isPublic) { + if (isEncrypted) { + add(RoomBadge.ENCRYPTED) + } else { + add(RoomBadge.NOT_ENCRYPTED) + } + } + if (isPublic) { + add(RoomBadge.PUBLIC) + } + }.toPersistentList() +} @Immutable sealed interface RoomDetailsType { diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateProvider.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateProvider.kt index 5462bc65a7..d9b0c22c65 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateProvider.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateProvider.kt @@ -96,18 +96,6 @@ fun aRoomDetailsState( isFavorite: Boolean = false, displayAdminSettings: Boolean = false, isPublic: Boolean = true, - roomBadges: List = buildList { - if (isEncrypted || isPublic) { - if (isEncrypted) { - add(RoomBadge.ENCRYPTED) - } else { - add(RoomBadge.NOT_ENCRYPTED) - } - } - if (isPublic) { - add(RoomBadge.PUBLIC) - } - }, heroes: List = emptyList(), canShowPinnedMessages: Boolean = true, pinnedMessagesCount: Int? = null, @@ -131,7 +119,6 @@ fun aRoomDetailsState( isFavorite = isFavorite, displayRolesAndPermissionsSettings = displayAdminSettings, isPublic = isPublic, - roomBadges = roomBadges.toPersistentList(), heroes = heroes.toPersistentList(), canShowPinnedMessages = canShowPinnedMessages, pinnedMessagesCount = pinnedMessagesCount, diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/RoomDetailsPresenterTest.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenterTest.kt similarity index 92% rename from features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/RoomDetailsPresenterTest.kt rename to features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenterTest.kt index e678a31641..ea83f89181 100644 --- a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/RoomDetailsPresenterTest.kt +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsPresenterTest.kt @@ -5,7 +5,7 @@ * Please see LICENSE in the repository root for full details. */ -package io.element.android.features.roomdetails +package io.element.android.features.roomdetails.impl import androidx.lifecycle.Lifecycle import app.cash.molecule.RecompositionMode @@ -17,12 +17,7 @@ import im.vector.app.features.analytics.plan.Interaction import io.element.android.features.leaveroom.api.LeaveRoomEvent import io.element.android.features.leaveroom.api.LeaveRoomState import io.element.android.features.leaveroom.api.aLeaveRoomState -import io.element.android.features.roomdetails.impl.RoomBadge -import io.element.android.features.roomdetails.impl.RoomDetailsEvent -import io.element.android.features.roomdetails.impl.RoomDetailsPresenter -import io.element.android.features.roomdetails.impl.RoomDetailsState -import io.element.android.features.roomdetails.impl.RoomDetailsType -import io.element.android.features.roomdetails.impl.RoomTopicState +import io.element.android.features.roomdetails.aMatrixRoom import io.element.android.features.roomdetails.impl.members.aRoomMember import io.element.android.features.roomdetails.impl.members.details.RoomMemberDetailsPresenter import io.element.android.features.userprofile.shared.aUserProfileState @@ -126,6 +121,7 @@ class RoomDetailsPresenterTest { ) val presenter = createRoomDetailsPresenter(room) presenter.test { + skipItems(1) val initialState = awaitItem() assertThat(initialState.roomId).isEqualTo(room.roomId) assertThat(initialState.roomName).isEqualTo(room.displayName) @@ -135,8 +131,6 @@ class RoomDetailsPresenterTest { assertThat(initialState.isEncrypted).isEqualTo(room.isEncrypted) assertThat(initialState.canShowPinnedMessages).isTrue() assertThat(initialState.pinnedMessagesCount).isNull() - assertThat(initialState.roomBadges).isEmpty() - assertThat(awaitItem().roomBadges).isEqualTo(listOf(RoomBadge.ENCRYPTED)) } } @@ -164,55 +158,10 @@ class RoomDetailsPresenterTest { assertThat(updatedState.roomAvatarUrl).isEqualTo(roomInfo.avatarUrl) assertThat(updatedState.roomTopic).isEqualTo(RoomTopicState.ExistingTopic(roomInfo.topic!!)) assertThat(updatedState.pinnedMessagesCount).isEqualTo(roomInfo.pinnedEventIds.size) - assertThat(updatedState.roomBadges).isEqualTo(listOf(RoomBadge.ENCRYPTED, RoomBadge.PUBLIC)) cancelAndIgnoreRemainingEvents() } } - @Test - fun `present - initial state not public not encrypted should have no badges`() = runTest { - val roomInfo = aRoomInfo( - name = A_ROOM_NAME, - isPublic = false, - ) - val room = aMatrixRoom( - isEncrypted = false, - canInviteResult = { Result.success(true) }, - canUserJoinCallResult = { Result.success(true) }, - canSendStateResult = { _, _ -> Result.success(true) }, - ).apply { - givenRoomInfo(roomInfo) - } - val presenter = createRoomDetailsPresenter(room) - presenter.test { - skipItems(1) - val updatedState = awaitItem() - assertThat(updatedState.roomBadges).isEmpty() - } - } - - @Test - fun `present - initial state public not encrypted should have not encrypted and public badges`() = runTest { - val roomInfo = aRoomInfo( - name = A_ROOM_NAME, - isPublic = true, - ) - val room = aMatrixRoom( - isEncrypted = false, - canInviteResult = { Result.success(true) }, - canUserJoinCallResult = { Result.success(true) }, - canSendStateResult = { _, _ -> Result.success(true) }, - ).apply { - givenRoomInfo(roomInfo) - } - val presenter = createRoomDetailsPresenter(room) - presenter.test { - skipItems(1) - val updatedState = awaitItem() - assertThat(updatedState.roomBadges).isEqualTo(listOf(RoomBadge.NOT_ENCRYPTED, RoomBadge.PUBLIC)) - } - } - @Test fun `present - initial state with no room name`() = runTest { val room = aMatrixRoom( diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateTest.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateTest.kt new file mode 100644 index 0000000000..65e291a9a1 --- /dev/null +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/RoomDetailsStateTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only + * Please see LICENSE in the repository root for full details. + */ + +package io.element.android.features.roomdetails.impl + +import com.google.common.truth.Truth.assertThat +import kotlinx.collections.immutable.persistentListOf +import org.junit.Test + +class RoomDetailsStateTest { + @Test + fun `room not public not encrypted should have no badges`() { + val sut = aRoomDetailsState( + isPublic = false, + isEncrypted = false, + ) + assertThat(sut.roomBadges).isEmpty() + } + + @Test + fun `room public not encrypted should have not encrypted and public badges`() { + val sut = aRoomDetailsState( + isPublic = true, + isEncrypted = false, + ) + assertThat(sut.roomBadges).isEqualTo( + persistentListOf(RoomBadge.NOT_ENCRYPTED, RoomBadge.PUBLIC) + ) + } + + @Test + fun `room public encrypted should have encrypted and public badges`() { + val sut = aRoomDetailsState( + isPublic = true, + isEncrypted = true, + ) + assertThat(sut.roomBadges).isEqualTo( + persistentListOf(RoomBadge.ENCRYPTED, RoomBadge.PUBLIC) + ) + } + + @Test + fun `room not public encrypted should have encrypted badges`() { + val sut = aRoomDetailsState( + isPublic = false, + isEncrypted = true, + ) + assertThat(sut.roomBadges).isEqualTo( + persistentListOf(RoomBadge.ENCRYPTED) + ) + } +}