Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 62 lines 1.8 kB view raw
1import React from 'react' 2import { 3 BskyAgent, 4 DEFAULT_LABEL_SETTINGS, 5 interpretLabelValueDefinitions, 6} from '@atproto/api' 7 8import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities' 9import {useLabelersDetailedInfoQuery} from '../labeler' 10import {usePreferencesQuery} from './index' 11 12/** 13 * More strict than our default settings for logged in users. 14 */ 15export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: typeof DEFAULT_LABEL_SETTINGS = 16 Object.fromEntries( 17 Object.entries(DEFAULT_LABEL_SETTINGS).map(([key, _pref]) => [key, 'hide']), 18 ) 19 20export function useMyLabelersQuery({ 21 excludeNonConfigurableLabelers = false, 22}: { 23 excludeNonConfigurableLabelers?: boolean 24} = {}) { 25 const prefs = usePreferencesQuery() 26 let dids = Array.from( 27 new Set( 28 BskyAgent.appLabelers.concat( 29 prefs.data?.moderationPrefs.labelers.map(l => l.did) || [], 30 ), 31 ), 32 ) 33 if (excludeNonConfigurableLabelers) { 34 dids = dids.filter(did => !isNonConfigurableModerationAuthority(did)) 35 } 36 const labelers = useLabelersDetailedInfoQuery({dids}) 37 const isLoading = prefs.isLoading || labelers.isLoading 38 const error = prefs.error || labelers.error 39 return React.useMemo(() => { 40 return { 41 isLoading, 42 error, 43 data: labelers.data, 44 refetch: labelers.refetch, 45 } 46 }, [labelers, isLoading, error]) 47} 48 49export function useLabelDefinitionsQuery() { 50 const labelers = useMyLabelersQuery() 51 return React.useMemo(() => { 52 return { 53 labelDefs: Object.fromEntries( 54 (labelers.data || []).map(labeler => [ 55 labeler.creator.did, 56 interpretLabelValueDefinitions(labeler), 57 ]), 58 ), 59 labelers: labelers.data || [], 60 } 61 }, [labelers]) 62}