Skip to content

Commit

Permalink
Merge pull request element-hq#2753 from element-hq/feature/bma/remove…
Browse files Browse the repository at this point in the history
…FlagRoomListFilters

Remove flag RoomListFilters.
  • Loading branch information
bmarty authored Apr 25, 2024
2 parents 7397df8 + 25751ef commit 1fc01c9
Show file tree
Hide file tree
Showing 19 changed files with 25 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class RoomListState(
val acceptDeclineInviteState: AcceptDeclineInviteState,
val eventSink: (RoomListEvents) -> Unit,
) {
val displayFilters = filtersState.isFeatureEnabled && contentState is RoomListContentState.Rooms
val displayFilters = contentState is RoomListContentState.Rooms
val displayActions = contentState !is RoomListContentState.Migration

sealed interface ContextMenu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ open class RoomListStateProvider : PreviewParameterProvider<RoomListState> {
aRoomListState(contentState = aSkeletonContentState()),
aRoomListState(matrixUser = MatrixUser(userId = UserId("@id:domain")), contentState = aMigrationContentState()),
aRoomListState(searchState = aRoomListSearchState(isSearchActive = true, query = "Test")),
aRoomListState(filtersState = aRoomListFiltersState(isFeatureEnabled = true)),
)
}

Expand All @@ -64,7 +63,7 @@ internal fun aRoomListState(
contextMenu: RoomListState.ContextMenu = RoomListState.ContextMenu.Hidden,
leaveRoomState: LeaveRoomState = aLeaveRoomState(),
searchState: RoomListSearchState = aRoomListSearchState(),
filtersState: RoomListFiltersState = aRoomListFiltersState(isFeatureEnabled = false),
filtersState: RoomListFiltersState = aRoomListFiltersState(),
contentState: RoomListContentState = aRoomsContentState(),
acceptDeclineInviteState: AcceptDeclineInviteState = anAcceptDeclineInviteState(),
eventSink: (RoomListEvents) -> Unit = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import io.element.android.features.roomlist.impl.filters.selection.FilterSelectionStrategy
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.matrix.api.roomlist.RoomListService
import kotlinx.collections.immutable.toPersistentList
import javax.inject.Inject
import io.element.android.libraries.matrix.api.roomlist.RoomListFilter as MatrixRoomListFilter

class RoomListFiltersPresenter @Inject constructor(
private val roomListService: RoomListService,
private val featureFlagService: FeatureFlagService,
private val filterSelectionStrategy: FilterSelectionStrategy,
) : Presenter<RoomListFiltersState> {
@Composable
override fun present(): RoomListFiltersState {
val isFeatureEnabled by featureFlagService.isFeatureEnabledFlow(FeatureFlags.RoomListFilters).collectAsState(false)
val filters by filterSelectionStrategy.filterSelectionStates.collectAsState()

fun handleEvents(event: RoomListFiltersEvents) {
Expand All @@ -50,32 +46,25 @@ class RoomListFiltersPresenter @Inject constructor(
}
}

LaunchedEffect(isFeatureEnabled) {
if (!isFeatureEnabled) {
filterSelectionStrategy.clear()
}
}

LaunchedEffect(filters) {
val allRoomsFilter = MatrixRoomListFilter.All(
filters
.filter { it.isSelected }
.map { roomListFilter ->
when (roomListFilter.filter) {
RoomListFilter.Rooms -> MatrixRoomListFilter.Category.Group
RoomListFilter.People -> MatrixRoomListFilter.Category.People
RoomListFilter.Unread -> MatrixRoomListFilter.Unread
RoomListFilter.Favourites -> MatrixRoomListFilter.Favorite
RoomListFilter.Invites -> MatrixRoomListFilter.Invite
when (roomListFilter.filter) {
RoomListFilter.Rooms -> MatrixRoomListFilter.Category.Group
RoomListFilter.People -> MatrixRoomListFilter.Category.People
RoomListFilter.Unread -> MatrixRoomListFilter.Unread
RoomListFilter.Favourites -> MatrixRoomListFilter.Favorite
RoomListFilter.Invites -> MatrixRoomListFilter.Invite
}
}
}
)
roomListService.allRooms.updateFilter(allRoomsFilter)
}

return RoomListFiltersState(
filterSelectionStates = filters.toPersistentList(),
isFeatureEnabled = isFeatureEnabled,
eventSink = ::handleEvents
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import kotlinx.collections.immutable.toPersistentList

data class RoomListFiltersState(
val filterSelectionStates: ImmutableList<FilterSelectionState>,
val isFeatureEnabled: Boolean,
val eventSink: (RoomListFiltersEvents) -> Unit,
) {
val hasAnyFilterSelected = filterSelectionStates.any { it.isSelected }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class RoomListFiltersStateProvider : PreviewParameterProvider<RoomListFiltersSta

fun aRoomListFiltersState(
filterSelectionStates: List<FilterSelectionState> = RoomListFilter.entries.map { FilterSelectionState(it, isSelected = false) },
isFeatureEnabled: Boolean = true,
eventSink: (RoomListFiltersEvents) -> Unit = {},
) = RoomListFiltersState(
filterSelectionStates = filterSelectionStates.toImmutableList(),
isFeatureEnabled = isFeatureEnabled,
eventSink = eventSink,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.features.roomlist.impl.filters.selection.DefaultFilterSelectionStrategy
import io.element.android.features.roomlist.impl.filters.selection.FilterSelectionState
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
import io.element.android.libraries.matrix.api.roomlist.RoomListService
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
import io.element.android.tests.testutils.awaitLastSequentialItem
Expand Down Expand Up @@ -120,11 +118,9 @@ private fun filterSelectionState(filter: RoomListFilter, selected: Boolean) = Fi

private fun createRoomListFiltersPresenter(
roomListService: RoomListService = FakeRoomListService(),
featureFlagService: FeatureFlagService = FakeFeatureFlagService(),
): RoomListFiltersPresenter {
return RoomListFiltersPresenter(
roomListService = roomListService,
featureFlagService = featureFlagService,
filterSelectionStrategy = DefaultFilterSelectionStrategy(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ enum class FeatureFlags(
defaultValue = true,
isFinished = false,
),
RoomListFilters(
key = "feature.roomlistfilters",
title = "Room list filters",
description = "Allow user to filter the room list",
defaultValue = true,
isFinished = false,
),
RoomDirectorySearch(
key = "feature.roomdirectorysearch",
title = "Room directory search",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class StaticFeatureFlagProvider @Inject constructor() :
FeatureFlags.PinUnlock -> true
FeatureFlags.Mentions -> true
FeatureFlags.MarkAsUnread -> true
FeatureFlags.RoomListFilters -> true
FeatureFlags.RoomDirectorySearch -> false
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class RoomListScreen(
),
filtersPresenter = RoomListFiltersPresenter(
roomListService = matrixClient.roomListService,
featureFlagService = featureFlagService,
filterSelectionStrategy = DefaultFilterSelectionStrategy(),
),
acceptDeclineInvitePresenter = AcceptDeclineInvitePresenter(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1fc01c9

Please sign in to comment.