Skip to content

Commit

Permalink
Additional moderation (#5172)
Browse files Browse the repository at this point in the history
* Set up additional mod authorities

* Filter out non-configurable mod authorities

* WIP

* Working

* Cleanup, add mod

* Cleanup

* Add more debug logs

* Tweak logs

* Filter out imperative labels from typeaheads

* Filter hideable content from notifications

* Add api

* Fall back in dev

* Remove space

* Use prod endpoint

* Add tiny notice

* Add notice to labeler card, show all labelers
  • Loading branch information
estrattonbailey authored Sep 20, 2024
1 parent 395edfe commit c85a271
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 65 deletions.
76 changes: 45 additions & 31 deletions src/App.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import {Provider as A11yProvider} from '#/state/a11y'
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
import {Provider as DialogStateProvider} from '#/state/dialogs'
import {listenSessionDropped} from '#/state/events'
import {
beginResolveGeolocation,
ensureGeolocationResolved,
Provider as GeolocationProvider,
} from '#/state/geolocation'
import {Provider as InvitesStateProvider} from '#/state/invites'
import {Provider as LightboxStateProvider} from '#/state/lightbox'
import {MessagesProvider} from '#/state/messages'
Expand Down Expand Up @@ -66,6 +71,11 @@ import {BackgroundNotificationPreferencesProvider} from '../modules/expo-backgro

SplashScreen.preventAutoHideAsync()

/**
* Begin geolocation ASAP
*/
beginResolveGeolocation()

function InnerApp() {
const [isReady, setIsReady] = React.useState(false)
const {currentAccount} = useSession()
Expand Down Expand Up @@ -158,7 +168,9 @@ function App() {
const [isReady, setReady] = useState(false)

React.useEffect(() => {
initPersistedState().then(() => setReady(true))
Promise.all([initPersistedState(), ensureGeolocationResolved()]).then(() =>
setReady(true),
)
}, [])

if (!isReady) {
Expand All @@ -170,36 +182,38 @@ function App() {
* that is set up in the InnerApp component above.
*/
return (
<A11yProvider>
<KeyboardProvider enabled={false} statusBarTranslucent={true}>
<SessionProvider>
<PrefsStateProvider>
<I18nProvider>
<ShellStateProvider>
<InvitesStateProvider>
<ModalStateProvider>
<DialogStateProvider>
<LightboxStateProvider>
<PortalProvider>
<StarterPackProvider>
<SafeAreaProvider
initialMetrics={initialWindowMetrics}>
<IntentDialogProvider>
<InnerApp />
</IntentDialogProvider>
</SafeAreaProvider>
</StarterPackProvider>
</PortalProvider>
</LightboxStateProvider>
</DialogStateProvider>
</ModalStateProvider>
</InvitesStateProvider>
</ShellStateProvider>
</I18nProvider>
</PrefsStateProvider>
</SessionProvider>
</KeyboardProvider>
</A11yProvider>
<GeolocationProvider>
<A11yProvider>
<KeyboardProvider enabled={false} statusBarTranslucent={true}>
<SessionProvider>
<PrefsStateProvider>
<I18nProvider>
<ShellStateProvider>
<InvitesStateProvider>
<ModalStateProvider>
<DialogStateProvider>
<LightboxStateProvider>
<PortalProvider>
<StarterPackProvider>
<SafeAreaProvider
initialMetrics={initialWindowMetrics}>
<IntentDialogProvider>
<InnerApp />
</IntentDialogProvider>
</SafeAreaProvider>
</StarterPackProvider>
</PortalProvider>
</LightboxStateProvider>
</DialogStateProvider>
</ModalStateProvider>
</InvitesStateProvider>
</ShellStateProvider>
</I18nProvider>
</PrefsStateProvider>
</SessionProvider>
</KeyboardProvider>
</A11yProvider>
</GeolocationProvider>
)
}

Expand Down
66 changes: 40 additions & 26 deletions src/App.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import {Provider as A11yProvider} from '#/state/a11y'
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
import {Provider as DialogStateProvider} from '#/state/dialogs'
import {listenSessionDropped} from '#/state/events'
import {
beginResolveGeolocation,
ensureGeolocationResolved,
Provider as GeolocationProvider,
} from '#/state/geolocation'
import {Provider as InvitesStateProvider} from '#/state/invites'
import {Provider as LightboxStateProvider} from '#/state/lightbox'
import {MessagesProvider} from '#/state/messages'
Expand Down Expand Up @@ -54,6 +59,11 @@ import {Provider as IntentDialogProvider} from '#/components/intents/IntentDialo
import {Provider as PortalProvider} from '#/components/Portal'
import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider'

/**
* Begin geolocation ASAP
*/
beginResolveGeolocation()

function InnerApp() {
const [isReady, setIsReady] = React.useState(false)
const {currentAccount} = useSession()
Expand Down Expand Up @@ -148,7 +158,9 @@ function App() {
const [isReady, setReady] = useState(false)

React.useEffect(() => {
initPersistedState().then(() => setReady(true))
Promise.all([initPersistedState(), ensureGeolocationResolved()]).then(() =>
setReady(true),
)
}, [])

if (!isReady) {
Expand All @@ -160,31 +172,33 @@ function App() {
* that is set up in the InnerApp component above.
*/
return (
<A11yProvider>
<SessionProvider>
<PrefsStateProvider>
<I18nProvider>
<ShellStateProvider>
<InvitesStateProvider>
<ModalStateProvider>
<DialogStateProvider>
<LightboxStateProvider>
<PortalProvider>
<StarterPackProvider>
<IntentDialogProvider>
<InnerApp />
</IntentDialogProvider>
</StarterPackProvider>
</PortalProvider>
</LightboxStateProvider>
</DialogStateProvider>
</ModalStateProvider>
</InvitesStateProvider>
</ShellStateProvider>
</I18nProvider>
</PrefsStateProvider>
</SessionProvider>
</A11yProvider>
<GeolocationProvider>
<A11yProvider>
<SessionProvider>
<PrefsStateProvider>
<I18nProvider>
<ShellStateProvider>
<InvitesStateProvider>
<ModalStateProvider>
<DialogStateProvider>
<LightboxStateProvider>
<PortalProvider>
<StarterPackProvider>
<IntentDialogProvider>
<InnerApp />
</IntentDialogProvider>
</StarterPackProvider>
</PortalProvider>
</LightboxStateProvider>
</DialogStateProvider>
</ModalStateProvider>
</InvitesStateProvider>
</ShellStateProvider>
</I18nProvider>
</PrefsStateProvider>
</SessionProvider>
</A11yProvider>
</GeolocationProvider>
)
}

Expand Down
28 changes: 24 additions & 4 deletions src/components/LabelingServiceCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {sanitizeHandle} from '#/lib/strings/handles'
import {useLabelerInfoQuery} from '#/state/queries/labeler'
import {UserAvatar} from '#/view/com/util/UserAvatar'
import {atoms as a, useTheme, ViewStyleProp} from '#/alf'
import {Flag_Stroke2_Corner0_Rounded as Flag} from '#/components/icons/Flag'
import {Link as InternalLink, LinkProps} from '#/components/Link'
import {RichText} from '#/components/RichText'
import {Text} from '#/components/Typography'
Expand Down Expand Up @@ -43,21 +44,40 @@ export function Avatar({avatar}: {avatar?: string}) {
}

export function Title({value}: {value: string}) {
return <Text style={[a.text_md, a.font_bold]}>{value}</Text>
return <Text style={[a.text_md, a.font_bold, a.leading_tight]}>{value}</Text>
}

export function Description({value, handle}: {value?: string; handle: string}) {
return value ? (
<Text numberOfLines={2}>
<RichText value={value} style={[]} />
<RichText value={value} style={[a.leading_snug]} />
</Text>
) : (
<Text>
<Text style={[a.leading_snug]}>
<Trans>By {sanitizeHandle(handle, '@')}</Trans>
</Text>
)
}

export function RegionalNotice() {
const t = useTheme()
return (
<View
style={[
a.flex_row,
a.align_center,
a.gap_xs,
a.pt_2xs,
{marginLeft: -2},
]}>
<Flag fill={t.atoms.text_contrast_low.color} size="sm" />
<Text style={[a.italic, a.leading_snug]}>
<Trans>Required in your region</Trans>
</Text>
</View>
)
}

export function LikeCount({count}: {count: number}) {
const t = useTheme()
return (
Expand Down Expand Up @@ -85,7 +105,7 @@ export function Content({children}: React.PropsWithChildren<{}>) {
a.align_center,
a.justify_between,
]}>
<View style={[a.gap_xs, a.flex_1]}>{children}</View>
<View style={[a.gap_2xs, a.flex_1]}>{children}</View>

<ChevronRight size="md" style={[a.z_10, t.atoms.text_contrast_low]} />
</View>
Expand Down
14 changes: 14 additions & 0 deletions src/lib/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export function isJustAMute(modui: ModerationUI): boolean {
return modui.filters.length === 1 && modui.filters[0].type === 'muted'
}

export function moduiContainsHideableOffense(modui: ModerationUI): boolean {
const label = modui.filters.at(0)
if (label && label.type === 'label') {
return labelIsHideableOffense(label.label)
}
return false
}

export function labelIsHideableOffense(
label: ComAtprotoLabelDefs.Label,
): boolean {
return ['!hide', '!takedown'].includes(label.val)
}

export function getLabelingServiceTitle({
displayName,
handle,
Expand Down
6 changes: 5 additions & 1 deletion src/screens/Moderation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useFocusEffect} from '@react-navigation/native'

import {useAnalytics} from '#/lib/analytics/analytics'
import {getLabelingServiceTitle} from '#/lib/moderation'
import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types'
import {logger} from '#/logger'
Expand All @@ -22,8 +23,8 @@ import {
useProfileUpdateMutation,
} from '#/state/queries/profile'
import {useSession} from '#/state/session'
import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities'
import {useSetMinimalShellMode} from '#/state/shell'
import {useAnalytics} from 'lib/analytics/analytics'
import {ViewHeader} from '#/view/com/util/ViewHeader'
import {CenteredView} from '#/view/com/util/Views'
import {ScrollView} from '#/view/com/util/Views'
Expand Down Expand Up @@ -455,6 +456,9 @@ export function ModerationScreenInner({
value={labeler.creator.description}
handle={labeler.creator.handle}
/>
{isNonConfigurableModerationAuthority(
labeler.creator.did,
) && <LabelingService.RegionalNotice />}
</LabelingService.Content>
</LabelingService.Outer>
)}
Expand Down
Loading

0 comments on commit c85a271

Please sign in to comment.