Dynamic filters for Longs, Shorts, Polls and Pictures

This commit is contained in:
Vitor Pamplona
2026-03-31 14:44:56 -04:00
parent 794af6eb2b
commit 29bb0d2682
18 changed files with 80 additions and 61 deletions
@@ -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<IFeedTopNavFilter> =
fun topNavFilterFlow(listName: MutableStateFlow<TopFilter>) =
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<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultHomeFollowList)
val liveHomeFollowListsPerRelay = OutboxLoaderState(liveHomeFollowLists, cache, scope).flow
val liveStoriesFollowLists: StateFlow<IFeedTopNavFilter> =
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<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultStoriesFollowList)
val liveStoriesFollowListsPerRelay = OutboxLoaderState(liveStoriesFollowLists, cache, scope).flow
val liveDiscoveryFollowLists: StateFlow<IFeedTopNavFilter> =
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<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultDiscoveryFollowList)
val liveDiscoveryFollowListsPerRelay = OutboxLoaderState(liveDiscoveryFollowLists, cache, scope).flow
val liveNotificationFollowLists: StateFlow<IFeedTopNavFilter> =
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<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultNotificationFollowList)
val liveNotificationFollowListsPerRelay = OutboxLoaderState(liveNotificationFollowLists, cache, scope).flow
val livePollsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultPollsFollowList)
val livePollsFollowListsPerRelay = OutboxLoaderState(livePollsFollowLists, cache, scope).flow
val livePicturesFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultPicturesFollowList)
val livePicturesFollowListsPerRelay = OutboxLoaderState(livePicturesFollowLists, cache, scope).flow
val liveShortsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultShortsFollowList)
val liveShortsFollowListsPerRelay = OutboxLoaderState(liveShortsFollowLists, cache, scope).flow
val liveLongsFollowLists: StateFlow<IFeedTopNavFilter> = topNavFilterFlow(settings.defaultLongsFollowList)
val liveLongsFollowListsPerRelay = OutboxLoaderState(liveLongsFollowLists, cache, scope).flow
override fun isWriteable(): Boolean = settings.isWriteable()
suspend fun updateWarnReports(warnReports: Boolean): Boolean {
@@ -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
// ---
@@ -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()
@@ -46,7 +46,7 @@ fun LongsTopBar(
followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list,
accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList,
onChange = accountViewModel.account.settings::changeDefaultLongsFollowList,
)
}
}
@@ -71,7 +71,7 @@ class LongsFeedFilter(
fun buildFilterParams(account: Account): FilterByListParams =
FilterByListParams.create(
account.liveDiscoveryFollowLists.value,
account.liveLongsFollowLists.value,
account.hiddenUsers.flow.value,
)
@@ -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
@@ -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()
@@ -46,7 +46,7 @@ fun PicturesTopBar(
followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list,
accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList,
onChange = accountViewModel.account.settings::changeDefaultPicturesFollowList,
)
}
}
@@ -60,7 +60,7 @@ class PictureFeedFilter(
fun buildFilterParams(account: Account): FilterByListParams =
FilterByListParams.create(
account.liveDiscoveryFollowLists.value,
account.livePicturesFollowLists.value,
account.hiddenUsers.flow.value,
)
@@ -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
@@ -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()
@@ -46,7 +46,7 @@ fun PollsTopBar(
followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list,
accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList,
onChange = accountViewModel.account.settings::changeDefaultPollsFollowList,
)
}
}
@@ -61,7 +61,7 @@ class PollsFeedFilter(
fun buildFilterParams(account: Account): FilterByListParams =
FilterByListParams.create(
account.liveDiscoveryFollowLists.value,
account.livePollsFollowLists.value,
account.hiddenUsers.flow.value,
)
@@ -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
@@ -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()
@@ -46,7 +46,7 @@ fun ShortsTopBar(
followListsModel = accountViewModel.feedStates.feedListOptions,
listName = list,
accountViewModel = accountViewModel,
onChange = accountViewModel.account.settings::changeDefaultDiscoveryFollowList,
onChange = accountViewModel.account.settings::changeDefaultShortsFollowList,
)
}
}
@@ -71,7 +71,7 @@ class ShortsFeedFilter(
fun buildFilterParams(account: Account): FilterByListParams =
FilterByListParams.create(
account.liveDiscoveryFollowLists.value,
account.liveShortsFollowLists.value,
account.hiddenUsers.flow.value,
)
@@ -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