Fix: distinguish between post media and quotes with the moderation hider (#2075)
* Fix: distinguish between post media and quotes with the moderation hider * Type fixeszio/stable
parent
a46059ca46
commit
37cafb080b
|
@ -1,4 +1,4 @@
|
||||||
import {ModerationCause, ProfileModeration} from '@atproto/api'
|
import {ModerationCause, ProfileModeration, PostModeration} from '@atproto/api'
|
||||||
|
|
||||||
export interface ModerationCauseDescription {
|
export interface ModerationCauseDescription {
|
||||||
name: string
|
name: string
|
||||||
|
@ -92,6 +92,25 @@ export function getProfileModerationCauses(
|
||||||
}) as ModerationCause[]
|
}) as ModerationCause[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPostMediaBlurred(
|
||||||
|
decisions: PostModeration['decisions'],
|
||||||
|
): boolean {
|
||||||
|
return decisions.post.blurMedia
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isQuoteBlurred(
|
||||||
|
decisions: PostModeration['decisions'],
|
||||||
|
): boolean {
|
||||||
|
return (
|
||||||
|
decisions.quote?.blur ||
|
||||||
|
decisions.quote?.blurMedia ||
|
||||||
|
decisions.quote?.filter ||
|
||||||
|
decisions.quotedAccount?.blur ||
|
||||||
|
decisions.quotedAccount?.filter ||
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function isCauseALabelOnUri(
|
export function isCauseALabelOnUri(
|
||||||
cause: ModerationCause | undefined,
|
cause: ModerationCause | undefined,
|
||||||
uri: string,
|
uri: string,
|
||||||
|
|
|
@ -351,11 +351,14 @@ let PostThreadItemLoaded = ({
|
||||||
{post.embed && (
|
{post.embed && (
|
||||||
<ContentHider
|
<ContentHider
|
||||||
moderation={moderation.embed}
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
|
ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
|
||||||
|
ignoreQuoteDecisions
|
||||||
style={s.mb10}>
|
style={s.mb10}>
|
||||||
<PostEmbeds
|
<PostEmbeds
|
||||||
embed={post.embed}
|
embed={post.embed}
|
||||||
moderation={moderation.embed}
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
/>
|
/>
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
)}
|
)}
|
||||||
|
@ -526,10 +529,14 @@ let PostThreadItemLoaded = ({
|
||||||
{post.embed && (
|
{post.embed && (
|
||||||
<ContentHider
|
<ContentHider
|
||||||
style={styles.contentHider}
|
style={styles.contentHider}
|
||||||
moderation={moderation.embed}>
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
|
ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
|
||||||
|
ignoreQuoteDecisions>
|
||||||
<PostEmbeds
|
<PostEmbeds
|
||||||
embed={post.embed}
|
embed={post.embed}
|
||||||
moderation={moderation.embed}
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
/>
|
/>
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -196,8 +196,14 @@ function PostInner({
|
||||||
{post.embed ? (
|
{post.embed ? (
|
||||||
<ContentHider
|
<ContentHider
|
||||||
moderation={moderation.embed}
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
|
ignoreQuoteDecisions
|
||||||
style={styles.contentHider}>
|
style={styles.contentHider}>
|
||||||
<PostEmbeds embed={post.embed} moderation={moderation.embed} />
|
<PostEmbeds
|
||||||
|
embed={post.embed}
|
||||||
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
|
/>
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
) : null}
|
) : null}
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
|
|
|
@ -320,9 +320,15 @@ let FeedItemInner = ({
|
||||||
<ContentHider
|
<ContentHider
|
||||||
testID="contentHider-embed"
|
testID="contentHider-embed"
|
||||||
moderation={moderation.embed}
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
|
ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
|
||||||
|
ignoreQuoteDecisions
|
||||||
style={styles.embed}>
|
style={styles.embed}>
|
||||||
<PostEmbeds embed={post.embed} moderation={moderation.embed} />
|
<PostEmbeds
|
||||||
|
embed={post.embed}
|
||||||
|
moderation={moderation.embed}
|
||||||
|
moderationDecisions={moderation.decisions}
|
||||||
|
/>
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
) : null}
|
) : null}
|
||||||
</ContentHider>
|
</ContentHider>
|
||||||
|
|
|
@ -2,25 +2,30 @@ import React from 'react'
|
||||||
import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {ModerationUI} from '@atproto/api'
|
import {ModerationUI, PostModeration} from '@atproto/api'
|
||||||
import {Text} from '../text/Text'
|
import {Text} from '../text/Text'
|
||||||
import {ShieldExclamation} from 'lib/icons'
|
import {ShieldExclamation} from 'lib/icons'
|
||||||
import {describeModerationCause} from 'lib/moderation'
|
import {describeModerationCause} from 'lib/moderation'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
|
import {isPostMediaBlurred} from 'lib/moderation'
|
||||||
|
|
||||||
export function ContentHider({
|
export function ContentHider({
|
||||||
testID,
|
testID,
|
||||||
moderation,
|
moderation,
|
||||||
|
moderationDecisions,
|
||||||
ignoreMute,
|
ignoreMute,
|
||||||
|
ignoreQuoteDecisions,
|
||||||
style,
|
style,
|
||||||
childContainerStyle,
|
childContainerStyle,
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
testID?: string
|
testID?: string
|
||||||
moderation: ModerationUI
|
moderation: ModerationUI
|
||||||
|
moderationDecisions?: PostModeration['decisions']
|
||||||
ignoreMute?: boolean
|
ignoreMute?: boolean
|
||||||
|
ignoreQuoteDecisions?: boolean
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
childContainerStyle?: StyleProp<ViewStyle>
|
childContainerStyle?: StyleProp<ViewStyle>
|
||||||
}>) {
|
}>) {
|
||||||
|
@ -29,7 +34,11 @@ export function ContentHider({
|
||||||
const [override, setOverride] = React.useState(false)
|
const [override, setOverride] = React.useState(false)
|
||||||
const {openModal} = useModalControls()
|
const {openModal} = useModalControls()
|
||||||
|
|
||||||
if (!moderation.blur || (ignoreMute && moderation.cause?.type === 'muted')) {
|
if (
|
||||||
|
!moderation.blur ||
|
||||||
|
(ignoreMute && moderation.cause?.type === 'muted') ||
|
||||||
|
shouldIgnoreQuote(moderationDecisions, ignoreQuoteDecisions)
|
||||||
|
) {
|
||||||
return (
|
return (
|
||||||
<View testID={testID} style={[styles.outer, style]}>
|
<View testID={testID} style={[styles.outer, style]}>
|
||||||
{children}
|
{children}
|
||||||
|
@ -99,6 +108,16 @@ export function ContentHider({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldIgnoreQuote(
|
||||||
|
decisions: PostModeration['decisions'] | undefined,
|
||||||
|
ignore: boolean | undefined,
|
||||||
|
): boolean {
|
||||||
|
if (!decisions || !ignore) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return !isPostMediaBlurred(decisions)
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
outer: {
|
outer: {
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
AppBskyGraphDefs,
|
AppBskyGraphDefs,
|
||||||
ModerationUI,
|
ModerationUI,
|
||||||
|
PostModeration,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {Link} from '../Link'
|
import {Link} from '../Link'
|
||||||
import {ImageLayoutGrid} from '../images/ImageLayoutGrid'
|
import {ImageLayoutGrid} from '../images/ImageLayoutGrid'
|
||||||
|
@ -28,8 +29,9 @@ import {getYoutubeVideoId} from 'lib/strings/url-helpers'
|
||||||
import {MaybeQuoteEmbed} from './QuoteEmbed'
|
import {MaybeQuoteEmbed} from './QuoteEmbed'
|
||||||
import {AutoSizedImage} from '../images/AutoSizedImage'
|
import {AutoSizedImage} from '../images/AutoSizedImage'
|
||||||
import {ListEmbed} from './ListEmbed'
|
import {ListEmbed} from './ListEmbed'
|
||||||
import {isCauseALabelOnUri} from 'lib/moderation'
|
import {isCauseALabelOnUri, isQuoteBlurred} from 'lib/moderation'
|
||||||
import {FeedSourceCard} from 'view/com/feeds/FeedSourceCard'
|
import {FeedSourceCard} from 'view/com/feeds/FeedSourceCard'
|
||||||
|
import {ContentHider} from '../moderation/ContentHider'
|
||||||
|
|
||||||
type Embed =
|
type Embed =
|
||||||
| AppBskyEmbedRecord.View
|
| AppBskyEmbedRecord.View
|
||||||
|
@ -41,10 +43,12 @@ type Embed =
|
||||||
export function PostEmbeds({
|
export function PostEmbeds({
|
||||||
embed,
|
embed,
|
||||||
moderation,
|
moderation,
|
||||||
|
moderationDecisions,
|
||||||
style,
|
style,
|
||||||
}: {
|
}: {
|
||||||
embed?: Embed
|
embed?: Embed
|
||||||
moderation: ModerationUI
|
moderation: ModerationUI
|
||||||
|
moderationDecisions?: PostModeration['decisions']
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
}) {
|
}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
|
@ -55,14 +59,17 @@ export function PostEmbeds({
|
||||||
// =
|
// =
|
||||||
if (AppBskyEmbedRecordWithMedia.isView(embed)) {
|
if (AppBskyEmbedRecordWithMedia.isView(embed)) {
|
||||||
const isModOnQuote =
|
const isModOnQuote =
|
||||||
AppBskyEmbedRecord.isViewRecord(embed.record.record) &&
|
(AppBskyEmbedRecord.isViewRecord(embed.record.record) &&
|
||||||
isCauseALabelOnUri(moderation.cause, embed.record.record.uri)
|
isCauseALabelOnUri(moderation.cause, embed.record.record.uri)) ||
|
||||||
|
(moderationDecisions && isQuoteBlurred(moderationDecisions))
|
||||||
const mediaModeration = isModOnQuote ? {} : moderation
|
const mediaModeration = isModOnQuote ? {} : moderation
|
||||||
const quoteModeration = isModOnQuote ? moderation : {}
|
const quoteModeration = isModOnQuote ? moderation : {}
|
||||||
return (
|
return (
|
||||||
<View style={[styles.stackContainer, style]}>
|
<View style={[styles.stackContainer, style]}>
|
||||||
<PostEmbeds embed={embed.media} moderation={mediaModeration} />
|
<PostEmbeds embed={embed.media} moderation={mediaModeration} />
|
||||||
<MaybeQuoteEmbed embed={embed.record} moderation={quoteModeration} />
|
<ContentHider moderation={quoteModeration}>
|
||||||
|
<MaybeQuoteEmbed embed={embed.record} moderation={quoteModeration} />
|
||||||
|
</ContentHider>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue