From ba8cab05138e02ac09a95f70edcdef5f5ddec314 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 18 Nov 2022 18:34:27 -0600 Subject: [PATCH 01/50] Sensitive video refactor Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1190 --- app/soapbox/components/status-media.tsx | 16 +-- .../ui/components/modals/media-modal.tsx | 1 - .../ui/components/modals/video-modal.tsx | 1 - app/soapbox/features/video/index.tsx | 111 ++++-------------- 4 files changed, 30 insertions(+), 99 deletions(-) diff --git a/app/soapbox/components/status-media.tsx b/app/soapbox/components/status-media.tsx index 71177cb122..c4f809425a 100644 --- a/app/soapbox/components/status-media.tsx +++ b/app/soapbox/components/status-media.tsx @@ -10,6 +10,7 @@ import { useAppDispatch, useSettings } from 'soapbox/hooks'; import { addAutoPlay } from 'soapbox/utils/media'; import type { List as ImmutableList } from 'immutable'; +import type VideoType from 'soapbox/features/video'; import type { Status, Attachment } from 'soapbox/types/entities'; interface IStatusMedia { @@ -66,10 +67,6 @@ const StatusMedia: React.FC = ({ dispatch(openModal('MEDIA', { media, status, index })); }; - const openVideo = (media: Attachment, time: number): void => { - dispatch(openModal('VIDEO', { media, time })); - }; - if (size > 0 && firstAttachment) { if (muted) { media = ( @@ -105,20 +102,17 @@ const StatusMedia: React.FC = ({ ); } else { media = ( - - {(Component: any) => ( + + {(Component: typeof VideoType) => ( )} diff --git a/app/soapbox/features/ui/components/modals/media-modal.tsx b/app/soapbox/features/ui/components/modals/media-modal.tsx index 6ed8ef4356..0551c61c4c 100644 --- a/app/soapbox/features/ui/components/modals/media-modal.tsx +++ b/app/soapbox/features/ui/components/modals/media-modal.tsx @@ -197,7 +197,6 @@ const MediaModal: React.FC = (props) => { width={width} height={height} startTime={time} - onCloseVideo={onClose} detailed link={link} alt={attachment.description} diff --git a/app/soapbox/features/ui/components/modals/video-modal.tsx b/app/soapbox/features/ui/components/modals/video-modal.tsx index 58ddea245d..f323a397ed 100644 --- a/app/soapbox/features/ui/components/modals/video-modal.tsx +++ b/app/soapbox/features/ui/components/modals/video-modal.tsx @@ -37,7 +37,6 @@ const VideoModal: React.FC = ({ status, account, media, time, onClo blurhash={media.blurhash} src={media.url} startTime={time} - onCloseVideo={onClose} link={link} detailed alt={media.description} diff --git a/app/soapbox/features/video/index.tsx b/app/soapbox/features/video/index.tsx index f418714bd6..71aaae65da 100644 --- a/app/soapbox/features/video/index.tsx +++ b/app/soapbox/features/video/index.tsx @@ -2,17 +2,14 @@ import classNames from 'clsx'; import debounce from 'lodash/debounce'; import throttle from 'lodash/throttle'; import React, { useCallback, useEffect, useRef, useState } from 'react'; -import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; +import { defineMessages, useIntl } from 'react-intl'; import Blurhash from 'soapbox/components/blurhash'; import Icon from 'soapbox/components/icon'; -import { useSettings } from 'soapbox/hooks'; import { isPanoramic, isPortrait, minimumAspectRatio, maximumAspectRatio } from 'soapbox/utils/media-aspect-ratio'; import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen'; -import type { Attachment } from 'soapbox/types/entities'; - const DEFAULT_HEIGHT = 300; type Position = { x: number, y: number }; @@ -107,15 +104,11 @@ interface IVideo { alt?: string, width?: number, height?: number, - sensitive?: boolean, startTime?: number, - onOpenVideo?: (attachment: Attachment, time: number) => void, - onCloseVideo?: () => void, detailed?: boolean, inline?: boolean, cacheWidth?: (width: number) => void, visible?: boolean, - onToggleVisibility?: () => void, blurhash?: string, link?: React.ReactNode, aspectRatio?: number, @@ -125,23 +118,18 @@ interface IVideo { const Video: React.FC = ({ width, visible = false, - sensitive = false, detailed = false, cacheWidth, - onToggleVisibility, startTime, src, height, alt, - onCloseVideo, inline, aspectRatio = 16 / 9, link, blurhash, }) => { const intl = useIntl(); - const settings = useSettings(); - const displayMedia = settings.get('displayMedia') as string | undefined; const player = useRef(null); const video = useRef(null); @@ -157,7 +145,6 @@ const Video: React.FC = ({ const [fullscreen, setFullscreen] = useState(false); const [hovered, setHovered] = useState(false); const [muted, setMuted] = useState(false); - const [revealed, setRevealed] = useState(visible !== undefined ? visible : (displayMedia !== 'hide_all' && !sensitive || displayMedia === 'show_all')); const [buffer, setBuffer] = useState(0); const setDimensions = () => { @@ -342,7 +329,6 @@ const Video: React.FC = ({ // If we are in fullscreen mode, we don't want any hotkeys // interacting with the UI that's not visible - if (fullscreen) { e.preventDefault(); e.stopPropagation(); @@ -411,16 +397,6 @@ const Video: React.FC = ({ } }; - const toggleReveal: React.MouseEventHandler = (e) => { - e.stopPropagation(); - - if (onToggleVisibility) { - onToggleVisibility(); - } else { - setRevealed(!revealed); - } - }; - const handleLoadedData = () => { if (video.current && startTime) { video.current.currentTime = startTime; @@ -459,14 +435,6 @@ const Video: React.FC = ({ playerStyle.height = height || DEFAULT_HEIGHT; } - let warning; - - if (sensitive) { - warning = ; - } else { - warning = ; - } - useEffect(() => { document.addEventListener('fullscreenchange', handleFullscreenChange, true); document.addEventListener('webkitfullscreenchange', handleFullscreenChange, true); @@ -488,21 +456,15 @@ const Video: React.FC = ({ }, []); useEffect(() => { - if (visible) { - setRevealed(true); - } - }, [visible]); - - useEffect(() => { - if (!revealed) { + if (!visible) { video.current?.pause(); } - }, [revealed]); + }, [visible]); return (
= ({ onKeyDown={handleKeyDown} tabIndex={0} > - - - {revealed && ( -