Fix types
This commit is contained in:
@@ -6,17 +6,10 @@ 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'
|
||||
import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences'
|
||||
import {isInvalidHandle} from '#/lib/strings/handles'
|
||||
|
||||
const DEFAULT_MOD_OPTS = getModerationOpts({
|
||||
userDid: '',
|
||||
preferences: DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||
})
|
||||
const DEFAULT_MOD_OPTS = DEFAULT_LOGGED_OUT_PREFERENCES.moderationOpts
|
||||
|
||||
export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix]
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import {STALE} from '#/state/queries'
|
||||
import {precacheFeedPostProfiles} from './profile'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const'
|
||||
import {getModerationOpts} from '#/state/queries/preferences/moderation'
|
||||
import {KnownError} from '#/view/com/posts/FeedErrorMessage'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
import {useModerationOpts} from './preferences'
|
||||
@@ -429,11 +428,10 @@ function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
||||
let somePostsPassModeration = false
|
||||
|
||||
for (const item of feed) {
|
||||
const moderationOpts = getModerationOpts({
|
||||
userDid: '',
|
||||
preferences: DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||
})
|
||||
const moderation = moderatePost(item.post, moderationOpts)
|
||||
const moderation = moderatePost(
|
||||
item.post,
|
||||
DEFAULT_LOGGED_OUT_PREFERENCES.moderationOpts,
|
||||
)
|
||||
|
||||
if (!moderation.content.filter) {
|
||||
// we have a sfw post
|
||||
|
||||
@@ -29,21 +29,16 @@ export const DEFAULT_PROD_FEEDS = {
|
||||
|
||||
export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = {
|
||||
birthDate: new Date('2022-11-17'), // TODO(pwi)
|
||||
adultContentEnabled: false,
|
||||
feeds: {
|
||||
saved: [],
|
||||
pinned: [],
|
||||
unpinned: [],
|
||||
},
|
||||
// labels are undefined until set by user
|
||||
contentLabels: {
|
||||
nsfw: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.nsfw,
|
||||
nudity: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.nudity,
|
||||
suggestive: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.suggestive,
|
||||
gore: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.gore,
|
||||
hate: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.hate,
|
||||
spam: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.spam,
|
||||
impersonation: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.impersonation,
|
||||
moderationOpts: {
|
||||
userDid: '',
|
||||
adultContentEnabled: false,
|
||||
labelGroups: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES,
|
||||
mods: [],
|
||||
},
|
||||
feedViewPrefs: DEFAULT_HOME_FEED_PREFS,
|
||||
threadViewPrefs: DEFAULT_THREAD_VIEW_PREFS,
|
||||
|
||||
@@ -4,20 +4,17 @@ import {LabelPreference, BskyFeedViewPreference} from '@atproto/api'
|
||||
|
||||
import {track} from '#/lib/analytics/analytics'
|
||||
import {getAge} from '#/lib/strings/time'
|
||||
import {useSession, getAgent} from '#/state/session'
|
||||
import {DEFAULT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {
|
||||
ConfigurableLabelGroup,
|
||||
UsePreferencesQueryResponse,
|
||||
ThreadViewPreferences,
|
||||
} from '#/state/queries/preferences/types'
|
||||
import {temp__migrateLabelPref} from '#/state/queries/preferences/util'
|
||||
import {
|
||||
DEFAULT_HOME_FEED_PREFS,
|
||||
DEFAULT_THREAD_VIEW_PREFS,
|
||||
DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||
} from '#/state/queries/preferences/const'
|
||||
import {getModerationOpts} from '#/state/queries/preferences/moderation'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useHiddenPosts} from '#/state/preferences/hidden-posts'
|
||||
|
||||
@@ -50,32 +47,6 @@ export function usePreferencesQuery() {
|
||||
return !res.feeds.pinned?.includes(f)
|
||||
}) || [],
|
||||
},
|
||||
// labels are undefined until set by user
|
||||
contentLabels: {
|
||||
nsfw: temp__migrateLabelPref(
|
||||
res.contentLabels?.nsfw || DEFAULT_LABEL_PREFERENCES.nsfw,
|
||||
),
|
||||
nudity: temp__migrateLabelPref(
|
||||
res.contentLabels?.nudity || DEFAULT_LABEL_PREFERENCES.nudity,
|
||||
),
|
||||
suggestive: temp__migrateLabelPref(
|
||||
res.contentLabels?.suggestive ||
|
||||
DEFAULT_LABEL_PREFERENCES.suggestive,
|
||||
),
|
||||
gore: temp__migrateLabelPref(
|
||||
res.contentLabels?.gore || DEFAULT_LABEL_PREFERENCES.gore,
|
||||
),
|
||||
hate: temp__migrateLabelPref(
|
||||
res.contentLabels?.hate || DEFAULT_LABEL_PREFERENCES.hate,
|
||||
),
|
||||
spam: temp__migrateLabelPref(
|
||||
res.contentLabels?.spam || DEFAULT_LABEL_PREFERENCES.spam,
|
||||
),
|
||||
impersonation: temp__migrateLabelPref(
|
||||
res.contentLabels?.impersonation ||
|
||||
DEFAULT_LABEL_PREFERENCES.impersonation,
|
||||
),
|
||||
},
|
||||
feedViewPrefs: {
|
||||
...DEFAULT_HOME_FEED_PREFS,
|
||||
...(res.feedViewPrefs.home || {}),
|
||||
@@ -93,23 +64,18 @@ export function usePreferencesQuery() {
|
||||
}
|
||||
|
||||
export function useModerationOpts() {
|
||||
const {currentAccount} = useSession()
|
||||
const prefs = usePreferencesQuery()
|
||||
const hiddenPosts = useHiddenPosts()
|
||||
const opts = useMemo(() => {
|
||||
if (!prefs.data) {
|
||||
return
|
||||
}
|
||||
const moderationOpts = getModerationOpts({
|
||||
userDid: currentAccount?.did || '',
|
||||
preferences: prefs.data,
|
||||
})
|
||||
|
||||
const moderationOpts = prefs.data.moderationOpts
|
||||
return {
|
||||
...moderationOpts,
|
||||
hiddenPosts,
|
||||
}
|
||||
}, [currentAccount?.did, prefs.data, hiddenPosts])
|
||||
}, [prefs.data, hiddenPosts])
|
||||
return opts
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import {
|
||||
LabelPreference,
|
||||
ComAtprotoLabelDefs,
|
||||
ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {ComAtprotoLabelDefs, DEFAULT_LABEL_GROUP_SETTINGS} from '@atproto/api'
|
||||
|
||||
import {
|
||||
LabelGroup,
|
||||
ConfigurableLabelGroup,
|
||||
UsePreferencesQueryResponse,
|
||||
} from '#/state/queries/preferences/types'
|
||||
|
||||
export type Label = ComAtprotoLabelDefs.Label
|
||||
@@ -21,36 +16,18 @@ export type LabelGroupConfig = {
|
||||
values: string[]
|
||||
}
|
||||
|
||||
export const DEFAULT_LABEL_PREFERENCES: Record<
|
||||
ConfigurableLabelGroup,
|
||||
LabelPreference
|
||||
> = {
|
||||
nsfw: 'hide',
|
||||
nudity: 'warn',
|
||||
suggestive: 'warn',
|
||||
gore: 'warn',
|
||||
hate: 'hide',
|
||||
spam: 'hide',
|
||||
impersonation: 'hide',
|
||||
}
|
||||
|
||||
/**
|
||||
* More strict than our default settings for logged in users.
|
||||
*
|
||||
* TODO(pwi)
|
||||
*/
|
||||
export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: Record<
|
||||
ConfigurableLabelGroup,
|
||||
LabelPreference
|
||||
> = {
|
||||
nsfw: 'hide',
|
||||
nudity: 'hide',
|
||||
suggestive: 'hide',
|
||||
gore: 'hide',
|
||||
hate: 'hide',
|
||||
spam: 'hide',
|
||||
impersonation: 'hide',
|
||||
}
|
||||
export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: typeof DEFAULT_LABEL_GROUP_SETTINGS =
|
||||
Object.fromEntries(
|
||||
Object.entries(DEFAULT_LABEL_GROUP_SETTINGS).map(([key, _pref]) => [
|
||||
key,
|
||||
'hide',
|
||||
]),
|
||||
)
|
||||
|
||||
export const CONFIGURABLE_LABEL_GROUPS: Record<
|
||||
ConfigurableLabelGroup,
|
||||
@@ -110,44 +87,3 @@ export const CONFIGURABLE_LABEL_GROUPS: Record<
|
||||
values: ['impersonation'],
|
||||
},
|
||||
}
|
||||
|
||||
export function getModerationOpts({
|
||||
userDid,
|
||||
preferences,
|
||||
}: {
|
||||
userDid: string
|
||||
preferences: UsePreferencesQueryResponse
|
||||
}): ModerationOpts {
|
||||
return {
|
||||
userDid: userDid,
|
||||
adultContentEnabled: preferences.adultContentEnabled,
|
||||
labels: {
|
||||
porn: preferences.contentLabels.nsfw,
|
||||
sexual: preferences.contentLabels.suggestive,
|
||||
nudity: preferences.contentLabels.nudity,
|
||||
nsfl: preferences.contentLabels.gore,
|
||||
corpse: preferences.contentLabels.gore,
|
||||
gore: preferences.contentLabels.gore,
|
||||
torture: preferences.contentLabels.gore,
|
||||
'self-harm': preferences.contentLabels.gore,
|
||||
'intolerant-race': preferences.contentLabels.hate,
|
||||
'intolerant-gender': preferences.contentLabels.hate,
|
||||
'intolerant-sexual-orientation': preferences.contentLabels.hate,
|
||||
'intolerant-religion': preferences.contentLabels.hate,
|
||||
intolerant: preferences.contentLabels.hate,
|
||||
'icon-intolerant': preferences.contentLabels.hate,
|
||||
spam: preferences.contentLabels.spam,
|
||||
impersonation: preferences.contentLabels.impersonation,
|
||||
scam: 'warn',
|
||||
},
|
||||
labelers: [
|
||||
{
|
||||
labeler: {
|
||||
did: '',
|
||||
displayName: 'Bluesky Social',
|
||||
},
|
||||
labels: {},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
BskyPreferences,
|
||||
LabelPreference,
|
||||
BskyThreadViewPreference,
|
||||
BskyFeedViewPreference,
|
||||
} from '@atproto/api'
|
||||
@@ -35,12 +34,6 @@ export type UsePreferencesQueryResponse = Omit<
|
||||
BskyPreferences,
|
||||
'contentLabels' | 'feedViewPrefs' | 'feeds'
|
||||
> & {
|
||||
/*
|
||||
* Content labels previously included 'show', which has been deprecated in
|
||||
* favor of 'ignore'. The API can return legacy data from the database, and
|
||||
* we clean up the data in `usePreferencesQuery`.
|
||||
*/
|
||||
contentLabels: Record<ConfigurableLabelGroup, LabelPreference>
|
||||
feedViewPrefs: BskyFeedViewPreference & {
|
||||
lab_mergeFeedEnabled?: boolean
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import {LabelPreference} from '@atproto/api'
|
||||
|
||||
/**
|
||||
* Content labels previously included 'show', which has been deprecated in
|
||||
* favor of 'ignore'. The API can return legacy data from the database, and
|
||||
* we clean up the data in `usePreferencesQuery`.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function temp__migrateLabelPref(
|
||||
pref: LabelPreference | 'show',
|
||||
): LabelPreference {
|
||||
// @ts-ignore
|
||||
if (pref === 'show') return 'ignore'
|
||||
return pref
|
||||
}
|
||||
Reference in New Issue
Block a user