A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): hide flagged media for viewers who block it
Hampus1b257cdd6936
diff --git a/fluxer_app/src/features/channel/components/embeds/attachments/AttachmentMosaic.tsx b/fluxer_app/src/features/channel/components/embeds/attachments/AttachmentMosaic.tsxindex 2ccc969ed..9adf240f6 100644--- a/fluxer_app/src/features/channel/components/embeds/attachments/AttachmentMosaic.tsx+++ b/fluxer_app/src/features/channel/components/embeds/attachments/AttachmentMosaic.tsx@@ -5,11 +5,13 @@ import {ExpiryFootnote} from '@app/features/app/components/shared/ExpiryFootnoteimport {AttachmentLayoutGrid} from '@app/features/channel/components/embeds/attachments/AttachmentLayoutGrid';import {AttachmentSingleMedia} from '@app/features/channel/components/embeds/attachments/AttachmentSingleMedia';import {isMediaAttachment} from '@app/features/channel/components/MessageAttachmentUtils';+import {isSensitiveMediaBlocked} from '@app/features/messaging/hooks/useMatureMedia';import type {Message} from '@app/features/messaging/models/MessagingMessage';import {formatAttachmentDate, getEarliestAttachmentExpiry} from '@app/features/messaging/utils/AttachmentExpiryUtils';import {getMosaicMediaDimensions} from '@app/features/messaging/utils/MediaDimensionConfig';import {remFromPx} from '@app/features/theme/layout/RemFromPx';import styles from '@app/features/theme/styles/AttachmentMosaic.module.css';+import {MessageAttachmentFlags} from '@fluxer/constants/src/ChannelConstants';import type {MessageAttachment} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';import {msg} from '@lingui/core/macro';import {useLingui} from '@lingui/react/macro';@@ -53,7 +55,17 @@ interface AttachmentMosaicStyle extends CSSProperties {const AttachmentMosaicComponent: FC<AttachmentMosaicProps> = observer(({attachments, message, hideExpiryFootnote, isPreview, snapshotIndex, onDelete}) => {const {i18n} = useLingui();- const mediaAttachments = useMemo(() => attachments.filter(isMediaAttachment), [attachments]);+ const blocksAllMedia = isSensitiveMediaBlocked(false, message?.channelId);+ const blocksFlaggedMedia = isSensitiveMediaBlocked(true, message?.channelId);+ const mediaAttachments = useMemo(+ () =>+ attachments.filter((attachment) => {+ if (!isMediaAttachment(attachment)) return false;+ const flagged = attachment.nsfw || (attachment.flags & MessageAttachmentFlags.CONTAINS_EXPLICIT_MEDIA) !== 0;+ return !(flagged ? blocksFlaggedMedia : blocksAllMedia);+ }),+ [attachments, blocksAllMedia, blocksFlaggedMedia],+ );const mosaicDimensions = getMosaicMediaDimensions();const mosaicStyle: AttachmentMosaicStyle = {'--attachment-media-max-height': remFromPx(mosaicDimensions.maxHeight),diff --git a/fluxer_app/src/features/channel/components/embeds/media/EmbedGifv.tsx b/fluxer_app/src/features/channel/components/embeds/media/EmbedGifv.tsxindex bf73a828a..1cdc8c612 100644--- a/fluxer_app/src/features/channel/components/embeds/media/EmbedGifv.tsx+++ b/fluxer_app/src/features/channel/components/embeds/media/EmbedGifv.tsx@@ -583,7 +583,13 @@ export const EmbedGifv: FC<const handleVideoError = useAttachmentRefreshOnError(videoProxyURL);const [containerElement, setContainerElement] = useState<HTMLDivElement | null>(null);const {isPointerInside, hasFocusInside} = useMediaSurfaceInteraction(containerElement);- const {shouldBlur, gateReason, canReveal, reveal: revealSensitiveMedia} = useMatureMedia(nsfw, channelId);+ const {+ shouldBlur,+ shouldBlock,+ gateReason,+ canReveal,+ reveal: revealSensitiveMedia,+ } = useMatureMedia(nsfw, channelId);const {ref: visibilityRef,loadMedia: shouldLoadMedia,@@ -685,6 +691,10 @@ export const EmbedGifv: FC<safePause(video);}, [shouldPlay]);+ if (shouldBlock) {+ return null;+ }+return (<GifEmbedShelltype="gifv"@@ -811,7 +821,13 @@ export const EmbedGif: FC<const mediaCalculator = useEmbedMediaCalculator(layoutConstraints);const [containerElement, setContainerElement] = useState<HTMLDivElement | null>(null);const {isPointerInside, hasFocusInside} = useMediaSurfaceInteraction(containerElement);- const {shouldBlur, gateReason, canReveal, reveal: revealSensitiveMedia} = useMatureMedia(nsfw, channelId);+ const {+ shouldBlur,+ shouldBlock,+ gateReason,+ canReveal,+ reveal: revealSensitiveMedia,+ } = useMatureMedia(nsfw, channelId);const {ref: visibilityRef,loadMedia: shouldLoadMedia,@@ -923,6 +939,10 @@ export const EmbedGif: FC<[baseProxyURL],);+ if (shouldBlock) {+ return null;+ }+return (<GifEmbedShelltype="gif"diff --git a/fluxer_app/src/features/channel/components/embeds/media/EmbedImage.tsx b/fluxer_app/src/features/channel/components/embeds/media/EmbedImage.tsxindex 3df55d290..5c4b13dd0 100644--- a/fluxer_app/src/features/channel/components/embeds/media/EmbedImage.tsx+++ b/fluxer_app/src/features/channel/components/embeds/media/EmbedImage.tsx@@ -274,7 +274,13 @@ export const EmbedImage: FC<EmbedImageProps> = observer(}) => {const {i18n} = useLingui();const messageViewContext = useMaybeMessageViewContext();- const {shouldBlur, gateReason, canReveal, reveal: revealSensitiveMedia} = useMatureMedia(nsfw, channelId);+ const {+ shouldBlur,+ shouldBlock,+ gateReason,+ canReveal,+ reveal: revealSensitiveMedia,+ } = useMatureMedia(nsfw, channelId);const shouldAnimateImage = useShouldAnimate({kind: 'gif', isAnimated: animated});const {style: containerStyle, dimensions} = imageCalculator.calculate({width, height},@@ -440,6 +446,9 @@ export const EmbedImage: FC<EmbedImageProps> = observer(const handleCloseMediaSheet = useCallback(() => {setMediaSheetOpen(false);}, []);+ if (shouldBlock) {+ return null;+ }if (shouldBlur) {return (<divdiff --git a/fluxer_app/src/features/channel/components/embeds/media/EmbedVideo.tsx b/fluxer_app/src/features/channel/components/embeds/media/EmbedVideo.tsxindex 4243b9cf6..0e2166152 100644--- a/fluxer_app/src/features/channel/components/embeds/media/EmbedVideo.tsx+++ b/fluxer_app/src/features/channel/components/embeds/media/EmbedVideo.tsx@@ -250,7 +250,13 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(detachMediaElementSource(inlineVideo);};}, [isPlayingInline]);- const {shouldBlur, gateReason, canReveal, reveal: revealSensitiveMedia} = useMatureMedia(nsfw, channelId);+ const {+ shouldBlur,+ shouldBlock,+ gateReason,+ canReveal,+ reveal: revealSensitiveMedia,+ } = useMatureMedia(nsfw, channelId);const shouldLoadMedia = isNearViewport && !shouldBlur;const defaultName =title || deriveDefaultNameFromMessage({message, attachmentId, embedIndex, url: embedUrl || src, proxyUrl: src});@@ -507,22 +513,13 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(const handleMediaPointerEnter = useCallback(() => {setMetadataProbeArmed(true);}, []);- const containerStyles: React.CSSProperties = isMobile- ? {- aspectRatio,- width: remFromPx(dimensions.width),- maxWidth: '100%',- }- : fillContainer- ? {- width: '100%',- height: '100%',- }- : {- width: remFromPx(dimensions.width),- maxWidth: '100%',- aspectRatio,- };+ let containerStyles: React.CSSProperties = {aspectRatio, width: remFromPx(dimensions.width), maxWidth: '100%'};+ if (!isMobile && fillContainer) {+ containerStyles = {width: '100%', height: '100%'};+ }+ if (shouldBlock) {+ return null;+ }if (shouldBlur) {return (<divdiff --git a/fluxer_app/src/features/messaging/hooks/useMatureMedia.ts b/fluxer_app/src/features/messaging/hooks/useMatureMedia.tsindex 82c490b7b..b499e3f9e 100644--- a/fluxer_app/src/features/messaging/hooks/useMatureMedia.ts+++ b/fluxer_app/src/features/messaging/hooks/useMatureMedia.ts@@ -51,13 +51,27 @@ function getSensitiveFilterLevel(channelId: string | undefined): number {return SensitiveMediaFilterLevel.SHOW;}+function isEffectiveMatureMedia(mature: boolean | undefined, channelId: string | undefined): boolean {+ const hasGateableContext = channelId ? GuildMatureContentAgree.isGatedContent({channelId}) : false;+ return (+ DeveloperOptions.forceMatureMedia ||+ DeveloperOptions.mockMatureMediaGateReason !== 'none' ||+ !!mature ||+ hasGateableContext+ );+}++export function isSensitiveMediaBlocked(mature: boolean | undefined, channelId: string | undefined): boolean {+ return (+ isEffectiveMatureMedia(mature, channelId) && getSensitiveFilterLevel(channelId) === SensitiveMediaFilterLevel.BLOCK+ );+}+export function useMatureMedia(mature: boolean | undefined, channelId: string | undefined): MatureMediaResult {const mockMatureMediaGateReason = DeveloperOptions.mockMatureMediaGateReason;const forceMatureMedia = DeveloperOptions.forceMatureMedia;const [isRevealed, setIsRevealed] = useState(false);- const hasGateableContext = channelId ? GuildMatureContentAgree.isGatedContent({channelId}) : false;- const effectiveMatureMedia =- forceMatureMedia || mockMatureMediaGateReason !== 'none' || !!mature || hasGateableContext;+ const effectiveMatureMedia = isEffectiveMatureMedia(mature, channelId);const gateReasonFromState = GuildMatureContentAgree.getGateReason({channelId: channelId ?? null});let gateReason: MatureContentGateReason;if (mockMatureMediaGateReason !== 'none') {