Fixes top bar filter for Nests

This commit is contained in:
Vitor Pamplona
2026-04-28 20:38:34 -04:00
parent 86b1b02211
commit ee7eada00e
8 changed files with 29 additions and 9 deletions
@@ -105,6 +105,7 @@ private object PrefKeys {
const val DEFAULT_SHORTS_FOLLOW_LIST = "defaultShortsFollowList"
const val DEFAULT_PUBLIC_CHATS_FOLLOW_LIST = "defaultPublicChatsFollowList"
const val DEFAULT_LIVE_STREAMS_FOLLOW_LIST = "defaultLiveStreamsFollowList"
const val DEFAULT_NESTS_FOLLOW_LIST = "defaultNestsFollowList"
const val DEFAULT_LONGS_FOLLOW_LIST = "defaultLongsFollowList"
const val DEFAULT_ARTICLES_FOLLOW_LIST = "defaultArticlesFollowList"
const val DEFAULT_BADGES_FOLLOW_LIST = "defaultBadgesFollowList"
@@ -357,6 +358,7 @@ object LocalPreferences {
putString(PrefKeys.DEFAULT_SHORTS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultShortsFollowList.value))
putString(PrefKeys.DEFAULT_PUBLIC_CHATS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultPublicChatsFollowList.value))
putString(PrefKeys.DEFAULT_LIVE_STREAMS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultLiveStreamsFollowList.value))
putString(PrefKeys.DEFAULT_NESTS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultNestsFollowList.value))
putString(PrefKeys.DEFAULT_LONGS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultLongsFollowList.value))
putString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultArticlesFollowList.value))
putString(PrefKeys.DEFAULT_BADGES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultBadgesFollowList.value))
@@ -628,6 +630,7 @@ object LocalPreferences {
defaultShortsFollowList = MutableStateFlow(followListPrefs.shorts),
defaultPublicChatsFollowList = MutableStateFlow(followListPrefs.publicChats),
defaultLiveStreamsFollowList = MutableStateFlow(followListPrefs.liveStreams),
defaultNestsFollowList = MutableStateFlow(followListPrefs.nests),
defaultLongsFollowList = MutableStateFlow(followListPrefs.longs),
defaultArticlesFollowList = MutableStateFlow(followListPrefs.articles),
defaultBadgesFollowList = MutableStateFlow(followListPrefs.badges),
@@ -697,6 +700,7 @@ object LocalPreferences {
val shorts: TopFilter,
val publicChats: TopFilter,
val liveStreams: TopFilter,
val nests: TopFilter,
val longs: TopFilter,
val articles: TopFilter,
val badges: TopFilter,
@@ -717,6 +721,7 @@ object LocalPreferences {
shorts = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_SHORTS_FOLLOW_LIST, null), TopFilter.Global),
publicChats = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_PUBLIC_CHATS_FOLLOW_LIST, null), TopFilter.Global),
liveStreams = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_LIVE_STREAMS_FOLLOW_LIST, null), TopFilter.Global),
nests = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_NESTS_FOLLOW_LIST, null), TopFilter.Global),
longs = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_LONGS_FOLLOW_LIST, null), TopFilter.Global),
articles = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, null), TopFilter.AllFollows),
badges = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_BADGES_FOLLOW_LIST, null), TopFilter.Mine),
@@ -488,6 +488,9 @@ class Account(
val liveLiveStreamsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultLiveStreamsFollowList)
val liveLiveStreamsFollowListsPerRelay = OutboxLoaderState(liveLiveStreamsFollowLists, cache, scope).flow
val liveNestsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultNestsFollowList)
val liveNestsFollowListsPerRelay = OutboxLoaderState(liveNestsFollowLists, cache, scope).flow
val liveLongsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultLongsFollowList)
val liveLongsFollowListsPerRelay = OutboxLoaderState(liveLongsFollowLists, cache, scope).flow
@@ -159,6 +159,7 @@ class AccountSettings(
val defaultShortsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultPublicChatsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultLiveStreamsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultNestsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultLongsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultArticlesFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.AllFollows),
val defaultBadgesFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Mine),
@@ -527,6 +528,17 @@ class AccountSettings(
}
}
fun changeDefaultNestsFollowList(name: FeedDefinition) {
changeDefaultNestsFollowList(name.code)
}
fun changeDefaultNestsFollowList(name: TopFilter) {
if (defaultNestsFollowList.value != name) {
defaultNestsFollowList.tryEmit(name)
saveAccountSettings()
}
}
fun changeDefaultLongsFollowList(name: FeedDefinition) {
changeDefaultLongsFollowList(name.code)
}
@@ -46,7 +46,7 @@ class FollowPackFeedConversationsFeedFilter(
val followPackNote: AddressableNote,
val account: Account,
) : AdditiveFeedFilter<Note>() {
override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.settings.defaultHomeFollowList.value
override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.settings.defaultFollowPacksFollowList.value
override fun showHiddenKey(): Boolean =
account.liveHomeFollowLists.value is MutedAuthorsByOutboxTopNavFilter ||
@@ -194,7 +194,7 @@ fun WatchAccountForNestsScreen(
nestsFeedState: FeedContentState,
accountViewModel: AccountViewModel,
) {
val listState by accountViewModel.account.liveLiveStreamsFollowLists.collectAsStateWithLifecycle()
val listState by accountViewModel.account.liveNestsFollowLists.collectAsStateWithLifecycle()
// Use `by` to unwrap the StateFlow's value into the LaunchedEffect
// key — without it, the State<T> object is reference-stable across
// recompositions and the effect never re-fires when the user
@@ -39,14 +39,14 @@ fun NestsTopBar(
nav: INav,
) {
UserDrawerSearchTopBar(accountViewModel, nav) {
val list by accountViewModel.account.settings.defaultLiveStreamsFollowList
val list by accountViewModel.account.settings.defaultNestsFollowList
.collectAsStateWithLifecycle()
NestsTopNavFilterBar(
followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list,
accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultLiveStreamsFollowList,
onChange = accountViewModel.account.settings::changeDefaultNestsFollowList,
)
}
}
@@ -58,7 +58,7 @@ class NestsFeedFilter(
override fun limit() = 50
fun followList(): TopFilter = account.settings.defaultLiveStreamsFollowList.value
fun followList(): TopFilter = account.settings.defaultNestsFollowList.value
private fun TopFilter.isMuteList() = this is TopFilter.MuteList
@@ -76,7 +76,7 @@ class NestsFeedFilter(
override fun applyFilter(newItems: Set<Note>): Set<Note> = innerApplyFilter(newItems)
private fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
val topFilter = account.liveLiveStreamsFollowLists.value
val topFilter = account.liveNestsFollowLists.value
val filterParams =
FilterByListParams.create(
followLists = topFilter,
@@ -198,7 +198,7 @@ class NestsFeedFilter(
}
override fun sort(items: Set<Note>): List<Note> {
val topFilter = account.liveLiveStreamsFollowLists.value
val topFilter = account.liveNestsFollowLists.value
val topFilterAuthors =
when (topFilter) {
is AuthorsByOutboxTopNavFilter -> topFilter.authors
@@ -56,11 +56,11 @@ class NestsSubAssembler(
override fun list(key: NestsQueryState) = key.listName()
fun NestsQueryState.listNameFlow() = account.settings.defaultLiveStreamsFollowList
fun NestsQueryState.listNameFlow() = account.settings.defaultNestsFollowList
fun NestsQueryState.listName() = listNameFlow().value
fun NestsQueryState.followsPerRelayFlow() = account.liveLiveStreamsFollowListsPerRelay
fun NestsQueryState.followsPerRelayFlow() = account.liveNestsFollowListsPerRelay
fun NestsQueryState.followsPerRelay() = followsPerRelayFlow().value