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_SHORTS_FOLLOW_LIST = "defaultShortsFollowList"
const val DEFAULT_PUBLIC_CHATS_FOLLOW_LIST = "defaultPublicChatsFollowList" const val DEFAULT_PUBLIC_CHATS_FOLLOW_LIST = "defaultPublicChatsFollowList"
const val DEFAULT_LIVE_STREAMS_FOLLOW_LIST = "defaultLiveStreamsFollowList" 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_LONGS_FOLLOW_LIST = "defaultLongsFollowList"
const val DEFAULT_ARTICLES_FOLLOW_LIST = "defaultArticlesFollowList" const val DEFAULT_ARTICLES_FOLLOW_LIST = "defaultArticlesFollowList"
const val DEFAULT_BADGES_FOLLOW_LIST = "defaultBadgesFollowList" 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_SHORTS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultShortsFollowList.value))
putString(PrefKeys.DEFAULT_PUBLIC_CHATS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultPublicChatsFollowList.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_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_LONGS_FOLLOW_LIST, JsonMapper.toJson(settings.defaultLongsFollowList.value))
putString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultArticlesFollowList.value)) putString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultArticlesFollowList.value))
putString(PrefKeys.DEFAULT_BADGES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultBadgesFollowList.value)) putString(PrefKeys.DEFAULT_BADGES_FOLLOW_LIST, JsonMapper.toJson(settings.defaultBadgesFollowList.value))
@@ -628,6 +630,7 @@ object LocalPreferences {
defaultShortsFollowList = MutableStateFlow(followListPrefs.shorts), defaultShortsFollowList = MutableStateFlow(followListPrefs.shorts),
defaultPublicChatsFollowList = MutableStateFlow(followListPrefs.publicChats), defaultPublicChatsFollowList = MutableStateFlow(followListPrefs.publicChats),
defaultLiveStreamsFollowList = MutableStateFlow(followListPrefs.liveStreams), defaultLiveStreamsFollowList = MutableStateFlow(followListPrefs.liveStreams),
defaultNestsFollowList = MutableStateFlow(followListPrefs.nests),
defaultLongsFollowList = MutableStateFlow(followListPrefs.longs), defaultLongsFollowList = MutableStateFlow(followListPrefs.longs),
defaultArticlesFollowList = MutableStateFlow(followListPrefs.articles), defaultArticlesFollowList = MutableStateFlow(followListPrefs.articles),
defaultBadgesFollowList = MutableStateFlow(followListPrefs.badges), defaultBadgesFollowList = MutableStateFlow(followListPrefs.badges),
@@ -697,6 +700,7 @@ object LocalPreferences {
val shorts: TopFilter, val shorts: TopFilter,
val publicChats: TopFilter, val publicChats: TopFilter,
val liveStreams: TopFilter, val liveStreams: TopFilter,
val nests: TopFilter,
val longs: TopFilter, val longs: TopFilter,
val articles: TopFilter, val articles: TopFilter,
val badges: TopFilter, val badges: TopFilter,
@@ -717,6 +721,7 @@ object LocalPreferences {
shorts = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_SHORTS_FOLLOW_LIST, null), TopFilter.Global), shorts = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_SHORTS_FOLLOW_LIST, null), TopFilter.Global),
publicChats = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_PUBLIC_CHATS_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), 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), longs = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_LONGS_FOLLOW_LIST, null), TopFilter.Global),
articles = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, null), TopFilter.AllFollows), articles = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_ARTICLES_FOLLOW_LIST, null), TopFilter.AllFollows),
badges = parseTopFilterOrDefault(getString(PrefKeys.DEFAULT_BADGES_FOLLOW_LIST, null), TopFilter.Mine), 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 liveLiveStreamsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultLiveStreamsFollowList)
val liveLiveStreamsFollowListsPerRelay = OutboxLoaderState(liveLiveStreamsFollowLists, cache, scope).flow 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 liveLongsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultLongsFollowList)
val liveLongsFollowListsPerRelay = OutboxLoaderState(liveLongsFollowLists, cache, scope).flow val liveLongsFollowListsPerRelay = OutboxLoaderState(liveLongsFollowLists, cache, scope).flow
@@ -159,6 +159,7 @@ class AccountSettings(
val defaultShortsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global), val defaultShortsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultPublicChatsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global), val defaultPublicChatsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultLiveStreamsFollowList: 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 defaultLongsFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Global),
val defaultArticlesFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.AllFollows), val defaultArticlesFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.AllFollows),
val defaultBadgesFollowList: MutableStateFlow<TopFilter> = MutableStateFlow(TopFilter.Mine), 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) { fun changeDefaultLongsFollowList(name: FeedDefinition) {
changeDefaultLongsFollowList(name.code) changeDefaultLongsFollowList(name.code)
} }
@@ -46,7 +46,7 @@ class FollowPackFeedConversationsFeedFilter(
val followPackNote: AddressableNote, val followPackNote: AddressableNote,
val account: Account, val account: Account,
) : AdditiveFeedFilter<Note>() { ) : 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 = override fun showHiddenKey(): Boolean =
account.liveHomeFollowLists.value is MutedAuthorsByOutboxTopNavFilter || account.liveHomeFollowLists.value is MutedAuthorsByOutboxTopNavFilter ||
@@ -194,7 +194,7 @@ fun WatchAccountForNestsScreen(
nestsFeedState: FeedContentState, nestsFeedState: FeedContentState,
accountViewModel: AccountViewModel, 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 // Use `by` to unwrap the StateFlow's value into the LaunchedEffect
// key — without it, the State<T> object is reference-stable across // key — without it, the State<T> object is reference-stable across
// recompositions and the effect never re-fires when the user // recompositions and the effect never re-fires when the user
@@ -39,14 +39,14 @@ fun NestsTopBar(
nav: INav, nav: INav,
) { ) {
UserDrawerSearchTopBar(accountViewModel, nav) { UserDrawerSearchTopBar(accountViewModel, nav) {
val list by accountViewModel.account.settings.defaultLiveStreamsFollowList val list by accountViewModel.account.settings.defaultNestsFollowList
.collectAsStateWithLifecycle() .collectAsStateWithLifecycle()
NestsTopNavFilterBar( NestsTopNavFilterBar(
followListsModel = accountViewModel.feedStates.feedListOptions, followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list, listName = list,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultLiveStreamsFollowList, onChange = accountViewModel.account.settings::changeDefaultNestsFollowList,
) )
} }
} }
@@ -58,7 +58,7 @@ class NestsFeedFilter(
override fun limit() = 50 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 private fun TopFilter.isMuteList() = this is TopFilter.MuteList
@@ -76,7 +76,7 @@ class NestsFeedFilter(
override fun applyFilter(newItems: Set<Note>): Set<Note> = innerApplyFilter(newItems) override fun applyFilter(newItems: Set<Note>): Set<Note> = innerApplyFilter(newItems)
private fun innerApplyFilter(collection: Collection<Note>): Set<Note> { private fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
val topFilter = account.liveLiveStreamsFollowLists.value val topFilter = account.liveNestsFollowLists.value
val filterParams = val filterParams =
FilterByListParams.create( FilterByListParams.create(
followLists = topFilter, followLists = topFilter,
@@ -198,7 +198,7 @@ class NestsFeedFilter(
} }
override fun sort(items: Set<Note>): List<Note> { override fun sort(items: Set<Note>): List<Note> {
val topFilter = account.liveLiveStreamsFollowLists.value val topFilter = account.liveNestsFollowLists.value
val topFilterAuthors = val topFilterAuthors =
when (topFilter) { when (topFilter) {
is AuthorsByOutboxTopNavFilter -> topFilter.authors is AuthorsByOutboxTopNavFilter -> topFilter.authors
@@ -56,11 +56,11 @@ class NestsSubAssembler(
override fun list(key: NestsQueryState) = key.listName() 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.listName() = listNameFlow().value
fun NestsQueryState.followsPerRelayFlow() = account.liveLiveStreamsFollowListsPerRelay fun NestsQueryState.followsPerRelayFlow() = account.liveNestsFollowListsPerRelay
fun NestsQueryState.followsPerRelay() = followsPerRelayFlow().value fun NestsQueryState.followsPerRelay() = followsPerRelayFlow().value