Skip to content

Commit

Permalink
Revert "Respect labels on feeds and lists (bluesky-social#4818)"
Browse files Browse the repository at this point in the history
This reverts commit 9ec6fde.
  • Loading branch information
tkusano committed Aug 5, 2024
1 parent 49cfad8 commit 370f680
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 261 deletions.
21 changes: 6 additions & 15 deletions src/components/moderation/ScreenHider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {useModerationCauseDescription} from '#/lib/moderation/useModerationCause
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {NavigationProp} from 'lib/routes/types'
import {CenteredView} from '#/view/com/util/Views'
import {atoms as a, useTheme, web} from '#/alf'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import {
ModerationDetailsDialog,
Expand Down Expand Up @@ -105,7 +105,6 @@ export function ScreenHider({
a.mb_md,
a.px_lg,
a.text_center,
a.leading_snug,
t.atoms.text_contrast_medium,
]}>
{isNoPwi ? (
Expand All @@ -114,15 +113,8 @@ export function ScreenHider({
</Trans>
) : (
<>
<Trans>This {screenDescription} has been flagged:</Trans>{' '}
<Text
style={[
a.text_lg,
a.font_semibold,
a.leading_snug,
t.atoms.text,
a.ml_xs,
]}>
<Trans>This {screenDescription} has been flagged:</Trans>
<Text style={[a.text_lg, a.font_semibold, t.atoms.text, a.ml_xs]}>
{desc.name}.{' '}
</Text>
<TouchableWithoutFeedback
Expand All @@ -135,17 +127,16 @@ export function ScreenHider({
<Text
style={[
a.text_lg,
a.leading_snug,
{
color: t.palette.primary_500,
},
web({
// @ts-ignore web only -prf
cursor: 'pointer',
}),
},
]}>
<Trans>Learn More</Trans>
</Text>
</TouchableWithoutFeedback>

<ModerationDetailsDialog control={control} modcause={blur} />
</>
)}{' '}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/StarterPack/Wizard/StepFeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {useA11y} from '#/state/a11y'
import {DISCOVER_FEED_URI} from 'lib/constants'
import {
useGetPopularFeedsQuery,
usePopularFeedsSearch,
useSavedFeeds,
useSearchPopularFeedsQuery,
} from 'state/queries/feed'
import {SearchInput} from 'view/com/util/forms/SearchInput'
import {List} from 'view/com/util/List'
Expand Down Expand Up @@ -59,7 +59,7 @@ export function StepFeeds({moderationOpts}: {moderationOpts: ModerationOpts}) {
: undefined

const {data: searchedFeeds, isFetching: isFetchingSearchedFeeds} =
usePopularFeedsSearch({query: throttledQuery})
useSearchPopularFeedsQuery({q: throttledQuery})

const isLoading =
!isFetchedSavedFeeds || isLoadingPopularFeeds || isFetchingSearchedFeeds
Expand Down
53 changes: 20 additions & 33 deletions src/state/queries/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
AppBskyGraphDefs,
AppBskyUnspeccedGetPopularFeedGenerators,
AtUri,
moderateFeedGenerator,
RichText,
} from '@atproto/api'
import {
Expand All @@ -27,7 +26,6 @@ import {RQKEY as listQueryKey} from '#/state/queries/list'
import {usePreferencesQuery} from '#/state/queries/preferences'
import {useAgent, useSession} from '#/state/session'
import {router} from '#/routes'
import {useModerationOpts} from '../preferences/moderation-opts'
import {FeedDescriptor} from './post-feed'
import {precacheResolvedUri} from './resolve-uri'

Expand Down Expand Up @@ -209,16 +207,14 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
const limit = options?.limit || 10
const {data: preferences} = usePreferencesQuery()
const queryClient = useQueryClient()
const moderationOpts = useModerationOpts()

// Make sure this doesn't invalidate unless really needed.
const selectArgs = useMemo(
() => ({
hasSession,
savedFeeds: preferences?.savedFeeds || [],
moderationOpts,
}),
[hasSession, preferences?.savedFeeds, moderationOpts],
[hasSession, preferences?.savedFeeds],
)
const lastPageCountRef = useRef(0)

Expand All @@ -229,7 +225,6 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
QueryKey,
string | undefined
>({
enabled: Boolean(moderationOpts),
queryKey: createGetPopularFeedsQueryKey(options),
queryFn: async ({pageParam}) => {
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
Expand All @@ -251,11 +246,7 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
(
data: InfiniteData<AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema>,
) => {
const {
savedFeeds,
hasSession: hasSessionInner,
moderationOpts,
} = selectArgs
const {savedFeeds, hasSession: hasSessionInner} = selectArgs
return {
...data,
pages: data.pages.map(page => {
Expand All @@ -273,8 +264,7 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {
return f.value === feed.uri
}),
)
const decision = moderateFeedGenerator(feed, moderationOpts!)
return !alreadySaved && !decision.ui('contentList').filter
return !alreadySaved
}),
}
}),
Expand Down Expand Up @@ -314,24 +304,31 @@ export function useGetPopularFeedsQuery(options?: GetPopularFeedsOptions) {

export function useSearchPopularFeedsMutation() {
const agent = useAgent()
const moderationOpts = useModerationOpts()

return useMutation({
mutationFn: async (query: string) => {
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
limit: 10,
query: query,
})

if (moderationOpts) {
return res.data.feeds.filter(feed => {
const decision = moderateFeedGenerator(feed, moderationOpts)
return !decision.ui('contentList').filter
})
}
return res.data.feeds
},
})
}

export function useSearchPopularFeedsQuery({q}: {q: string}) {
const agent = useAgent()
return useQuery({
queryKey: ['searchPopularFeeds', q],
queryFn: async () => {
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
limit: 15,
query: q,
})

return res.data.feeds
},
placeholderData: keepPreviousData,
})
}

Expand All @@ -349,27 +346,17 @@ export function usePopularFeedsSearch({
enabled?: boolean
}) {
const agent = useAgent()
const moderationOpts = useModerationOpts()
const enabledInner = enabled ?? Boolean(moderationOpts)

return useQuery({
enabled: enabledInner,
enabled,
queryKey: createPopularFeedsSearchQueryKey(query),
queryFn: async () => {
const res = await agent.app.bsky.unspecced.getPopularFeedGenerators({
limit: 15,
limit: 10,
query: query,
})

return res.data.feeds
},
placeholderData: keepPreviousData,
select(data) {
return data.filter(feed => {
const decision = moderateFeedGenerator(feed, moderationOpts!)
return !decision.ui('contentList').filter
})
},
})
}

Expand Down
22 changes: 2 additions & 20 deletions src/state/queries/profile-feedgens.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {AppBskyFeedGetActorFeeds, moderateFeedGenerator} from '@atproto/api'
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'

import {useAgent} from '#/state/session'
import {useModerationOpts} from '../preferences/moderation-opts'

const PAGE_SIZE = 50
type RQPageParam = string | undefined
Expand All @@ -15,8 +14,7 @@ export function useProfileFeedgensQuery(
did: string,
opts?: {enabled?: boolean},
) {
const moderationOpts = useModerationOpts()
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
const enabled = opts?.enabled !== false
const agent = useAgent()
return useInfiniteQuery<
AppBskyFeedGetActorFeeds.OutputSchema,
Expand All @@ -40,21 +38,5 @@ export function useProfileFeedgensQuery(
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
select(data) {
return {
...data,
pages: data.pages.map(page => {
return {
...page,
feeds: page.feeds
// filter by labels
.filter(list => {
const decision = moderateFeedGenerator(list, moderationOpts!)
return !decision.ui('contentList').filter
}),
}
}),
}
},
})
}
37 changes: 10 additions & 27 deletions src/state/queries/profile-lists.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {AppBskyGraphGetLists, moderateUserList} from '@atproto/api'
import {AppBskyGraphGetLists} from '@atproto/api'
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'

import {useAgent} from '#/state/session'
import {useModerationOpts} from '../preferences/moderation-opts'

const PAGE_SIZE = 30
type RQPageParam = string | undefined
Expand All @@ -11,8 +10,7 @@ const RQKEY_ROOT = 'profile-lists'
export const RQKEY = (did: string) => [RQKEY_ROOT, did]

export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
const moderationOpts = useModerationOpts()
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
const enabled = opts?.enabled !== false
const agent = useAgent()
return useInfiniteQuery<
AppBskyGraphGetLists.OutputSchema,
Expand All @@ -29,32 +27,17 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
cursor: pageParam,
})

return res.data
// Starter packs use a reference list, which we do not want to show on profiles. At some point we could probably
// just filter this out on the backend instead of in the client.
return {
...res.data,
lists: res.data.lists.filter(
l => l.purpose !== 'app.bsky.graph.defs#referencelist',
),
}
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
enabled,
select(data) {
return {
...data,
pages: data.pages.map(page => {
return {
...page,
lists: page.lists
/*
* Starter packs use a reference list, which we do not want to
* show on profiles. At some point we could probably just filter
* this out on the backend instead of in the client.
*/
.filter(l => l.purpose !== 'app.bsky.graph.defs#referencelist')
// filter by labels
.filter(list => {
const decision = moderateUserList(list, moderationOpts!)
return !decision.ui('contentList').filter
}),
}
}),
}
},
})
}
Loading

0 comments on commit 370f680

Please sign in to comment.