From 29bb0d26820453a0778c67d1284ab5ee75e7243a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 31 Mar 2026 14:44:56 -0400 Subject: [PATCH] Dynamic filters for Longs, Shorts, Polls and Pictures --- .../vitorpamplona/amethyst/model/Account.kt | 65 ++++++------------- .../amethyst/model/AccountSettings.kt | 44 +++++++++++++ .../ui/screen/loggedIn/longs/LongsScreen.kt | 2 +- .../ui/screen/loggedIn/longs/LongsTopBar.kt | 2 +- .../loggedIn/longs/dal/LongsFeedFilter.kt | 2 +- .../longs/datasource/LongsSubAssembler.kt | 2 +- .../loggedIn/pictures/PicturesScreen.kt | 2 +- .../loggedIn/pictures/PicturesTopBar.kt | 2 +- .../pictures/dal/PictureFeedFilter.kt | 2 +- .../datasource/PicturesSubAssembler.kt | 2 +- .../ui/screen/loggedIn/polls/PollsScreen.kt | 2 +- .../ui/screen/loggedIn/polls/PollsTopBar.kt | 2 +- .../loggedIn/polls/dal/PollsFeedFilter.kt | 2 +- .../polls/datasource/PollsSubAssembler.kt | 2 +- .../ui/screen/loggedIn/shorts/ShortsScreen.kt | 2 +- .../ui/screen/loggedIn/shorts/ShortsTopBar.kt | 2 +- .../loggedIn/shorts/dal/ShortsFeedFilter.kt | 2 +- .../shorts/datasource/ShortsSubAssembler.kt | 2 +- 18 files changed, 80 insertions(+), 61 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index a92fa6138..e7e4eb3c6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -226,6 +226,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.debounce @@ -382,10 +383,9 @@ class Account( geohashCache = geohashListDecryptionCache, ) - // App-ready Feeds - val liveHomeFollowLists: StateFlow = + fun topNavFilterFlow(listName: MutableStateFlow) = FeedTopNavFilterState( - feedFilterListName = settings.defaultHomeFollowList, + feedFilterListName = listName, kind3Follows = kind3FollowList.flow, allFollows = allFollows.flow, locationFlow = geolocationFlow, @@ -397,56 +397,31 @@ class Account( scope = scope, ).flow + // App-ready Feeds + val liveHomeFollowLists: StateFlow = topNavFilterFlow(settings.defaultHomeFollowList) val liveHomeFollowListsPerRelay = OutboxLoaderState(liveHomeFollowLists, cache, scope).flow - val liveStoriesFollowLists: StateFlow = - FeedTopNavFilterState( - feedFilterListName = settings.defaultStoriesFollowList, - kind3Follows = kind3FollowList.flow, - allFollows = allFollows.flow, - locationFlow = geolocationFlow, - followsRelays = defaultGlobalRelays.flow, - blockedRelays = blockedRelayList.flow, - proxyRelays = proxyRelayList.flow, - caches = feedDecryptionCaches, - signer = signer, - scope = scope, - ).flow - + val liveStoriesFollowLists: StateFlow = topNavFilterFlow(settings.defaultStoriesFollowList) val liveStoriesFollowListsPerRelay = OutboxLoaderState(liveStoriesFollowLists, cache, scope).flow - val liveDiscoveryFollowLists: StateFlow = - FeedTopNavFilterState( - feedFilterListName = settings.defaultDiscoveryFollowList, - kind3Follows = kind3FollowList.flow, - allFollows = allFollows.flow, - locationFlow = geolocationFlow, - followsRelays = defaultGlobalRelays.flow, - blockedRelays = blockedRelayList.flow, - proxyRelays = proxyRelayList.flow, - caches = feedDecryptionCaches, - signer = signer, - scope = scope, - ).flow - + val liveDiscoveryFollowLists: StateFlow = topNavFilterFlow(settings.defaultDiscoveryFollowList) val liveDiscoveryFollowListsPerRelay = OutboxLoaderState(liveDiscoveryFollowLists, cache, scope).flow - val liveNotificationFollowLists: StateFlow = - FeedTopNavFilterState( - feedFilterListName = settings.defaultNotificationFollowList, - kind3Follows = kind3FollowList.flow, - allFollows = allFollows.flow, - locationFlow = geolocationFlow, - followsRelays = defaultGlobalRelays.flow, - blockedRelays = blockedRelayList.flow, - proxyRelays = proxyRelayList.flow, - caches = feedDecryptionCaches, - signer = signer, - scope = scope, - ).flow - + val liveNotificationFollowLists: StateFlow = topNavFilterFlow(settings.defaultNotificationFollowList) val liveNotificationFollowListsPerRelay = OutboxLoaderState(liveNotificationFollowLists, cache, scope).flow + val livePollsFollowLists: StateFlow = topNavFilterFlow(settings.defaultPollsFollowList) + val livePollsFollowListsPerRelay = OutboxLoaderState(livePollsFollowLists, cache, scope).flow + + val livePicturesFollowLists: StateFlow = topNavFilterFlow(settings.defaultPicturesFollowList) + val livePicturesFollowListsPerRelay = OutboxLoaderState(livePicturesFollowLists, cache, scope).flow + + val liveShortsFollowLists: StateFlow = topNavFilterFlow(settings.defaultShortsFollowList) + val liveShortsFollowListsPerRelay = OutboxLoaderState(liveShortsFollowLists, cache, scope).flow + + val liveLongsFollowLists: StateFlow = topNavFilterFlow(settings.defaultLongsFollowList) + val liveLongsFollowListsPerRelay = OutboxLoaderState(liveLongsFollowLists, cache, scope).flow + override fun isWriteable(): Boolean = settings.isWriteable() suspend fun updateWarnReports(warnReports: Boolean): Boolean { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AccountSettings.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AccountSettings.kt index cec2a4ab9..093a9a1cf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AccountSettings.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AccountSettings.kt @@ -325,6 +325,50 @@ class AccountSettings( } } + fun changeDefaultPollsFollowList(name: FeedDefinition) { + changeDefaultPollsFollowList(name.code) + } + + fun changeDefaultPollsFollowList(name: TopFilter) { + if (defaultPollsFollowList.value != name) { + defaultPollsFollowList.tryEmit(name) + saveAccountSettings() + } + } + + fun changeDefaultPicturesFollowList(name: FeedDefinition) { + changeDefaultPicturesFollowList(name.code) + } + + fun changeDefaultPicturesFollowList(name: TopFilter) { + if (defaultPicturesFollowList.value != name) { + defaultPicturesFollowList.tryEmit(name) + saveAccountSettings() + } + } + + fun changeDefaultShortsFollowList(name: FeedDefinition) { + changeDefaultShortsFollowList(name.code) + } + + fun changeDefaultShortsFollowList(name: TopFilter) { + if (defaultShortsFollowList.value != name) { + defaultShortsFollowList.tryEmit(name) + saveAccountSettings() + } + } + + fun changeDefaultLongsFollowList(name: FeedDefinition) { + changeDefaultLongsFollowList(name.code) + } + + fun changeDefaultLongsFollowList(name: TopFilter) { + if (defaultLongsFollowList.value != name) { + defaultLongsFollowList.tryEmit(name) + saveAccountSettings() + } + } + // --- // language services // --- diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsScreen.kt index ae6b3be1f..f30c361c4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsScreen.kt @@ -107,7 +107,7 @@ fun WatchAccountForLongsScreen( videoFeedState: FeedContentState, accountViewModel: AccountViewModel, ) { - val listState by accountViewModel.account.liveDiscoveryFollowLists.collectAsStateWithLifecycle() + val listState by accountViewModel.account.liveLongsFollowLists.collectAsStateWithLifecycle() val hiddenUsers = accountViewModel.account.hiddenUsers.flow .collectAsStateWithLifecycle() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsTopBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsTopBar.kt index a2d19a837..17fd9c371 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsTopBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/LongsTopBar.kt @@ -46,7 +46,7 @@ fun LongsTopBar( followListsModel = accountViewModel.feedStates.feedListOptions, listName = list, accountViewModel = accountViewModel, - onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList, + onChange = accountViewModel.account.settings::changeDefaultLongsFollowList, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/dal/LongsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/dal/LongsFeedFilter.kt index 0965f59c5..78aa82690 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/dal/LongsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/dal/LongsFeedFilter.kt @@ -71,7 +71,7 @@ class LongsFeedFilter( fun buildFilterParams(account: Account): FilterByListParams = FilterByListParams.create( - account.liveDiscoveryFollowLists.value, + account.liveLongsFollowLists.value, account.hiddenUsers.flow.value, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/datasource/LongsSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/datasource/LongsSubAssembler.kt index 743d17faf..b6087dbb3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/datasource/LongsSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/longs/datasource/LongsSubAssembler.kt @@ -55,7 +55,7 @@ class LongsSubAssembler( fun LongsQueryState.listName() = listNameFlow().value - fun LongsQueryState.followsPerRelayFlow() = account.liveDiscoveryFollowListsPerRelay + fun LongsQueryState.followsPerRelayFlow() = account.liveLongsFollowListsPerRelay fun LongsQueryState.followsPerRelay() = followsPerRelayFlow().value diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesScreen.kt index 0f791265e..7442d2ee9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesScreen.kt @@ -107,7 +107,7 @@ fun WatchAccountForPicturesScreen( picturesFeedContentState: FeedContentState, accountViewModel: AccountViewModel, ) { - val listState by accountViewModel.account.liveDiscoveryFollowLists.collectAsStateWithLifecycle() + val listState by accountViewModel.account.livePicturesFollowLists.collectAsStateWithLifecycle() val hiddenUsers = accountViewModel.account.hiddenUsers.flow .collectAsStateWithLifecycle() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesTopBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesTopBar.kt index 68f64c9a8..ec7a86771 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesTopBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/PicturesTopBar.kt @@ -46,7 +46,7 @@ fun PicturesTopBar( followListsModel = accountViewModel.feedStates.feedListOptions, listName = list, accountViewModel = accountViewModel, - onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList, + onChange = accountViewModel.account.settings::changeDefaultPicturesFollowList, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/dal/PictureFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/dal/PictureFeedFilter.kt index 57be85a18..3bbb4d106 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/dal/PictureFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/dal/PictureFeedFilter.kt @@ -60,7 +60,7 @@ class PictureFeedFilter( fun buildFilterParams(account: Account): FilterByListParams = FilterByListParams.create( - account.liveDiscoveryFollowLists.value, + account.livePicturesFollowLists.value, account.hiddenUsers.flow.value, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/datasource/PicturesSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/datasource/PicturesSubAssembler.kt index 0fc2ea198..d6ad67e16 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/datasource/PicturesSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/pictures/datasource/PicturesSubAssembler.kt @@ -55,7 +55,7 @@ class PicturesSubAssembler( fun PicturesQueryState.listName() = listNameFlow().value - fun PicturesQueryState.followsPerRelayFlow() = account.liveDiscoveryFollowListsPerRelay + fun PicturesQueryState.followsPerRelayFlow() = account.livePicturesFollowListsPerRelay fun PicturesQueryState.followsPerRelay() = followsPerRelayFlow().value diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsScreen.kt index 8d24c6817..973fea9e9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsScreen.kt @@ -99,7 +99,7 @@ fun WatchAccountForPollsScreen( pollsFeedContentState: FeedContentState, accountViewModel: AccountViewModel, ) { - val listState by accountViewModel.account.liveDiscoveryFollowLists.collectAsStateWithLifecycle() + val listState by accountViewModel.account.livePollsFollowLists.collectAsStateWithLifecycle() val hiddenUsers = accountViewModel.account.hiddenUsers.flow .collectAsStateWithLifecycle() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsTopBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsTopBar.kt index 9ff7d74cd..c895daf4f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsTopBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/PollsTopBar.kt @@ -46,7 +46,7 @@ fun PollsTopBar( followListsModel = accountViewModel.feedStates.feedListOptions, listName = list, accountViewModel = accountViewModel, - onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList, + onChange = accountViewModel.account.settings::changeDefaultPollsFollowList, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/dal/PollsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/dal/PollsFeedFilter.kt index 5e974385c..1297dba6f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/dal/PollsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/dal/PollsFeedFilter.kt @@ -61,7 +61,7 @@ class PollsFeedFilter( fun buildFilterParams(account: Account): FilterByListParams = FilterByListParams.create( - account.liveDiscoveryFollowLists.value, + account.livePollsFollowLists.value, account.hiddenUsers.flow.value, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/datasource/PollsSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/datasource/PollsSubAssembler.kt index 53ca0d603..ffe9caad0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/datasource/PollsSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/polls/datasource/PollsSubAssembler.kt @@ -55,7 +55,7 @@ class PollsSubAssembler( fun PollsQueryState.listName() = listNameFlow().value - fun PollsQueryState.followsPerRelayFlow() = account.liveDiscoveryFollowListsPerRelay + fun PollsQueryState.followsPerRelayFlow() = account.livePollsFollowListsPerRelay fun PollsQueryState.followsPerRelay() = followsPerRelayFlow().value diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsScreen.kt index f93f31f56..68ed14421 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsScreen.kt @@ -107,7 +107,7 @@ fun WatchAccountForShortsScreen( videoFeedState: FeedContentState, accountViewModel: AccountViewModel, ) { - val listState by accountViewModel.account.liveDiscoveryFollowLists.collectAsStateWithLifecycle() + val listState by accountViewModel.account.liveShortsFollowLists.collectAsStateWithLifecycle() val hiddenUsers = accountViewModel.account.hiddenUsers.flow .collectAsStateWithLifecycle() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsTopBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsTopBar.kt index 603f0df42..28b48f07b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsTopBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/ShortsTopBar.kt @@ -46,7 +46,7 @@ fun ShortsTopBar( followListsModel = accountViewModel.feedStates.feedListOptions, listName = list, accountViewModel = accountViewModel, - onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList, + onChange = accountViewModel.account.settings::changeDefaultShortsFollowList, ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/dal/ShortsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/dal/ShortsFeedFilter.kt index bbf523924..07c5d4e0e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/dal/ShortsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/dal/ShortsFeedFilter.kt @@ -71,7 +71,7 @@ class ShortsFeedFilter( fun buildFilterParams(account: Account): FilterByListParams = FilterByListParams.create( - account.liveDiscoveryFollowLists.value, + account.liveShortsFollowLists.value, account.hiddenUsers.flow.value, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/datasource/ShortsSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/datasource/ShortsSubAssembler.kt index fa7ccff09..eb90a6929 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/datasource/ShortsSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/shorts/datasource/ShortsSubAssembler.kt @@ -55,7 +55,7 @@ class ShortsSubAssembler( fun ShortsQueryState.listName() = listNameFlow().value - fun ShortsQueryState.followsPerRelayFlow() = account.liveDiscoveryFollowListsPerRelay + fun ShortsQueryState.followsPerRelayFlow() = account.liveShortsFollowListsPerRelay fun ShortsQueryState.followsPerRelay() = followsPerRelayFlow().value