diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-12-14 10:31:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 10:31:49 -0800 |
commit | 075ffdf583c5393b896d22dd179d03208311ef4a (patch) | |
tree | ad86e90d2e2f0dd5a9e2f9f72292e5dcec6a59a0 /src/state/queries/actor-autocomplete.ts | |
parent | 7fd79702371e3d7829be2188c2212c090bf76670 (diff) | |
download | voidsky-075ffdf583c5393b896d22dd179d03208311ef4a.tar.zst |
PWI behavior updates (#2207)
* Enable PWI * Disable access to feeds on PWI * Remove feeds nav item from drawer when signed out * Replace discover feed on home with a CTA * Wire up the sign in and create account buttons to go straight to their respective screens * Give a custom ScreenHider interface for no-pwi * Add side borders on desktop to the screen hider * Filter accounts in the autocomplete according to mod settings * Trim replies in the post thread that are pwi opt-out * Show 'learn more' on the content hider when no-override is enabled * Apply the moderation filter on profile cards * Disable post search on logged-out view * Update locale files * Bump api pkg * Ensure feeds with no posts don't show as NSFPublic * Fix types --------- Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/state/queries/actor-autocomplete.ts')
-rw-r--r-- | src/state/queries/actor-autocomplete.ts | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/state/queries/actor-autocomplete.ts b/src/state/queries/actor-autocomplete.ts index fbd1b38f9..fe207371d 100644 --- a/src/state/queries/actor-autocomplete.ts +++ b/src/state/queries/actor-autocomplete.ts @@ -1,16 +1,27 @@ import React from 'react' -import {AppBskyActorDefs} from '@atproto/api' +import {AppBskyActorDefs, ModerationOpts, moderateProfile} from '@atproto/api' import {useQuery, useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' import {getAgent} from '#/state/session' import {useMyFollowsQuery} from '#/state/queries/my-follows' import {STALE} from '#/state/queries' +import { + DEFAULT_LOGGED_OUT_PREFERENCES, + getModerationOpts, + useModerationOpts, +} from './preferences' + +const DEFAULT_MOD_OPTS = getModerationOpts({ + userDid: '', + preferences: DEFAULT_LOGGED_OUT_PREFERENCES, +}) export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix] export function useActorAutocompleteQuery(prefix: string) { const {data: follows, isFetching} = useMyFollowsQuery() + const moderationOpts = useModerationOpts() return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({ staleTime: STALE.MINUTES.ONE, @@ -22,9 +33,20 @@ export function useActorAutocompleteQuery(prefix: string) { limit: 8, }) : undefined - return computeSuggestions(prefix, follows, res?.data.actors) + return res?.data.actors || [] }, enabled: !isFetching, + select: React.useCallback( + (data: AppBskyActorDefs.ProfileViewBasic[]) => { + return computeSuggestions( + prefix, + follows, + data, + moderationOpts || DEFAULT_MOD_OPTS, + ) + }, + [prefix, follows, moderationOpts], + ), }) } @@ -32,6 +54,7 @@ export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn> export function useActorAutocompleteFn() { const queryClient = useQueryClient() const {data: follows} = useMyFollowsQuery() + const moderationOpts = useModerationOpts() return React.useCallback( async ({query, limit = 8}: {query: string; limit?: number}) => { @@ -54,9 +77,14 @@ export function useActorAutocompleteFn() { } } - return computeSuggestions(query, follows, res?.data.actors) + return computeSuggestions( + query, + follows, + res?.data.actors, + moderationOpts || DEFAULT_MOD_OPTS, + ) }, - [follows, queryClient], + [follows, queryClient, moderationOpts], ) } @@ -64,6 +92,7 @@ function computeSuggestions( prefix: string, follows: AppBskyActorDefs.ProfileViewBasic[] | undefined, searched: AppBskyActorDefs.ProfileViewBasic[] = [], + moderationOpts: ModerationOpts, ) { let items: AppBskyActorDefs.ProfileViewBasic[] = [] if (follows) { @@ -76,10 +105,14 @@ function computeSuggestions( handle: item.handle, displayName: item.displayName, avatar: item.avatar, + labels: item.labels, }) } } - return items + return items.filter(profile => { + const mod = moderateProfile(profile, moderationOpts) + return !mod.account.filter + }) } function prefixMatch( |