Forces a given event kind to be displayed in the Discovery tab

This commit is contained in:
Vitor Pamplona
2023-07-16 11:47:05 -04:00
parent 53a4dfb702
commit 0224af18c0
3 changed files with 32 additions and 14 deletions
@@ -86,6 +86,7 @@ fun ChannelCardCompose(
routeForLastRead: String? = null, routeForLastRead: String? = null,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null, parentBackgroundColor: MutableState<Color>? = null,
forceEventKind: Int?,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
@@ -107,6 +108,7 @@ fun ChannelCardCompose(
) )
} }
} else { } else {
if (forceEventKind == null || baseNote.event?.kind() == forceEventKind) {
CheckHiddenChannelCardCompose( CheckHiddenChannelCardCompose(
baseNote, baseNote,
routeForLastRead, routeForLastRead,
@@ -118,6 +120,7 @@ fun ChannelCardCompose(
} }
} }
} }
}
@Composable @Composable
fun CheckHiddenChannelCardCompose( fun CheckHiddenChannelCardCompose(
@@ -35,6 +35,9 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleEventObserver
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.NostrDiscoveryDataSource import com.vitorpamplona.amethyst.service.NostrDiscoveryDataSource
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.CommunityDefinitionEvent
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent
import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.navigation.Route
import com.vitorpamplona.amethyst.ui.note.ChannelCardCompose import com.vitorpamplona.amethyst.ui.note.ChannelCardCompose
import com.vitorpamplona.amethyst.ui.screen.FeedEmpty import com.vitorpamplona.amethyst.ui.screen.FeedEmpty
@@ -92,9 +95,9 @@ fun DiscoverScreen(
val tabs by remember(discoveryLiveFeedViewModel, discoveryCommunityFeedViewModel, discoveryChatFeedViewModel) { val tabs by remember(discoveryLiveFeedViewModel, discoveryCommunityFeedViewModel, discoveryChatFeedViewModel) {
mutableStateOf( mutableStateOf(
listOf( listOf(
TabItem(R.string.discover_live, discoveryLiveFeedViewModel, Route.Discover.base + "Live", ScrollStateKeys.DISCOVER_LIVE), TabItem(R.string.discover_live, discoveryLiveFeedViewModel, Route.Discover.base + "Live", ScrollStateKeys.DISCOVER_LIVE, LiveActivitiesEvent.kind),
TabItem(R.string.discover_community, discoveryCommunityFeedViewModel, Route.Discover.base + "Community", ScrollStateKeys.DISCOVER_COMMUNITY), TabItem(R.string.discover_community, discoveryCommunityFeedViewModel, Route.Discover.base + "Community", ScrollStateKeys.DISCOVER_COMMUNITY, CommunityDefinitionEvent.kind),
TabItem(R.string.discover_chat, discoveryChatFeedViewModel, Route.Discover.base + "Chats", ScrollStateKeys.DISCOVER_CHATS) TabItem(R.string.discover_chat, discoveryChatFeedViewModel, Route.Discover.base + "Chats", ScrollStateKeys.DISCOVER_CHATS, ChannelCreateEvent.kind)
).toImmutableList() ).toImmutableList()
) )
} }
@@ -139,7 +142,14 @@ private fun DiscoverPages(
HorizontalPager(pageCount = 3, state = pagerState) { page -> HorizontalPager(pageCount = 3, state = pagerState) { page ->
RefresheableView(tabs[page].viewModel, true) { RefresheableView(tabs[page].viewModel, true) {
SaveableFeedState(tabs[page].viewModel, scrollStateKey = tabs[page].scrollStateKey) { listState -> SaveableFeedState(tabs[page].viewModel, scrollStateKey = tabs[page].scrollStateKey) { listState ->
RenderDiscoverFeed(tabs[page].viewModel, tabs[page].routeForLastRead, accountViewModel, listState, nav) RenderDiscoverFeed(
viewModel = tabs[page].viewModel,
routeForLastRead = tabs[page].routeForLastRead,
forceEventKind = tabs[page].forceEventKind,
listState = listState,
accountViewModel = accountViewModel,
nav = nav
)
} }
} }
} }
@@ -149,8 +159,9 @@ private fun DiscoverPages(
private fun RenderDiscoverFeed( private fun RenderDiscoverFeed(
viewModel: FeedViewModel, viewModel: FeedViewModel,
routeForLastRead: String?, routeForLastRead: String?,
accountViewModel: AccountViewModel, forceEventKind: Int?,
listState: LazyListState, listState: LazyListState,
accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val feedState by viewModel.feedContent.collectAsState() val feedState by viewModel.feedContent.collectAsState()
@@ -177,6 +188,7 @@ private fun RenderDiscoverFeed(
state, state,
routeForLastRead, routeForLastRead,
listState, listState,
forceEventKind,
accountViewModel, accountViewModel,
nav nav
) )
@@ -212,6 +224,7 @@ private fun DiscoverFeedLoaded(
state: FeedState.Loaded, state: FeedState.Loaded,
routeForLastRead: String?, routeForLastRead: String?,
listState: LazyListState, listState: LazyListState,
forceEventKind: Int?,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
@@ -232,6 +245,7 @@ private fun DiscoverFeedLoaded(
baseNote = item, baseNote = item,
routeForLastRead = routeForLastRead, routeForLastRead = routeForLastRead,
modifier = Modifier, modifier = Modifier,
forceEventKind = forceEventKind,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav nav = nav
) )
@@ -175,5 +175,6 @@ class TabItem(
val resource: Int, val resource: Int,
val viewModel: FeedViewModel, val viewModel: FeedViewModel,
val routeForLastRead: String, val routeForLastRead: String,
val scrollStateKey: String val scrollStateKey: String,
val forceEventKind: Int? = null
) )