Make auto-play video optional config

This commit is contained in:
Chewbacca 2022-11-11 10:21:32 -05:00
parent 4a4e0daa1a
commit 5c6ae4d6da
5 changed files with 18 additions and 3 deletions

View File

@ -319,6 +319,7 @@
"poll_button.add_poll": "Add a poll", "poll_button.add_poll": "Add a poll",
"poll_button.remove_poll": "Remove poll", "poll_button.remove_poll": "Remove poll",
"preferences.fields.auto_play_gif_label": "Auto-play animated GIFs", "preferences.fields.auto_play_gif_label": "Auto-play animated GIFs",
"preferences.fields.auto_play_video_label": "Auto-play videos",
"preferences.fields.boost_modal_label": "Show confirmation dialog before reposting", "preferences.fields.boost_modal_label": "Show confirmation dialog before reposting",
"preferences.fields.delete_modal_label": "Show confirmation dialog before deleting a post", "preferences.fields.delete_modal_label": "Show confirmation dialog before deleting a post",
"preferences.fields.demetricator_label": "Use Demetricator", "preferences.fields.demetricator_label": "Use Demetricator",

View File

@ -6,7 +6,7 @@ import PlaceholderCard from 'soapbox/features/placeholder/components/placeholder
import Card from 'soapbox/features/status/components/card'; import Card from 'soapbox/features/status/components/card';
import Bundle from 'soapbox/features/ui/components/bundle'; import Bundle from 'soapbox/features/ui/components/bundle';
import { MediaGallery, Video, Audio } from 'soapbox/features/ui/util/async-components'; import { MediaGallery, Video, Audio } from 'soapbox/features/ui/util/async-components';
import { useAppDispatch } from 'soapbox/hooks'; import { useAppDispatch, useSettings } from 'soapbox/hooks';
import { addAutoPlay } from 'soapbox/utils/media'; import { addAutoPlay } from 'soapbox/utils/media';
import type { List as ImmutableList } from 'immutable'; import type { List as ImmutableList } from 'immutable';
@ -34,6 +34,9 @@ const StatusMedia: React.FC<IStatusMedia> = ({
onToggleVisibility = () => { }, onToggleVisibility = () => { },
}) => { }) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const settings = useSettings();
const shouldAutoPlayVideo = settings.get('autoPlayVideo');
const [mediaWrapperWidth, setMediaWrapperWidth] = useState<number | undefined>(undefined); const [mediaWrapperWidth, setMediaWrapperWidth] = useState<number | undefined>(undefined);
const size = status.media_attachments.size; const size = status.media_attachments.size;
@ -94,7 +97,9 @@ const StatusMedia: React.FC<IStatusMedia> = ({
ref={setRef} ref={setRef}
className='status-card__image status-card-video' className='status-card__image status-card-video'
style={height ? { height } : undefined} style={height ? { height } : undefined}
dangerouslySetInnerHTML={{ __html: addAutoPlay(status.card.html) }} dangerouslySetInnerHTML={{
__html: shouldAutoPlayVideo ? addAutoPlay(status.card.html) : status.card.html,
}}
/> />
</div> </div>
); );

View File

@ -193,6 +193,10 @@ const Preferences = () => {
<SettingToggle settings={settings} settingPath={['autoPlayGif']} onChange={onToggleChange} /> <SettingToggle settings={settings} settingPath={['autoPlayGif']} onChange={onToggleChange} />
</ListItem> </ListItem>
<ListItem label={<FormattedMessage id='preferences.fields.auto_play_video_label' defaultMessage='Auto-play videos' />}>
<SettingToggle settings={settings} settingPath={['autoPlayVideo']} onChange={onToggleChange} />
</ListItem>
{features.spoilers && <ListItem label={<FormattedMessage id='preferences.fields.expand_spoilers_label' defaultMessage='Always expand posts marked with content warnings' />}> {features.spoilers && <ListItem label={<FormattedMessage id='preferences.fields.expand_spoilers_label' defaultMessage='Always expand posts marked with content warnings' />}>
<SettingToggle settings={settings} settingPath={['expandSpoilers']} onChange={onToggleChange} /> <SettingToggle settings={settings} settingPath={['expandSpoilers']} onChange={onToggleChange} />
</ListItem>} </ListItem>}

View File

@ -5,6 +5,7 @@ import React, { useState, useEffect } from 'react';
import Blurhash from 'soapbox/components/blurhash'; import Blurhash from 'soapbox/components/blurhash';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import { HStack, Stack, Text } from 'soapbox/components/ui'; import { HStack, Stack, Text } from 'soapbox/components/ui';
import { useSettings } from 'soapbox/hooks';
import { normalizeAttachment } from 'soapbox/normalizers'; import { normalizeAttachment } from 'soapbox/normalizers';
import { addAutoPlay } from 'soapbox/utils/media'; import { addAutoPlay } from 'soapbox/utils/media';
@ -41,6 +42,9 @@ const Card: React.FC<ICard> = ({
onOpenMedia, onOpenMedia,
horizontal, horizontal,
}): JSX.Element => { }): JSX.Element => {
const settings = useSettings();
const shouldAutoPlayVideo = settings.get('autoPlayVideo');
const [width, setWidth] = useState(defaultWidth); const [width, setWidth] = useState(defaultWidth);
const [embedded, setEmbedded] = useState(false); const [embedded, setEmbedded] = useState(false);
@ -88,7 +92,7 @@ const Card: React.FC<ICard> = ({
}; };
const renderVideo = () => { const renderVideo = () => {
const content = { __html: addAutoPlay(card.html) }; const content = { __html: shouldAutoPlayVideo ? addAutoPlay(card.html) : card.html };
const ratio = getRatio(card); const ratio = getRatio(card);
const height = width / ratio; const height = width / ratio;

View File

@ -790,6 +790,7 @@
"poll_button.remove_poll": "Remove poll", "poll_button.remove_poll": "Remove poll",
"pre_header.close": "Close", "pre_header.close": "Close",
"preferences.fields.auto_play_gif_label": "Auto-play animated GIFs", "preferences.fields.auto_play_gif_label": "Auto-play animated GIFs",
"preferences.fields.auto_play_video_label": "Auto-play videos",
"preferences.fields.autoload_more_label": "Automatically load more items when scrolled to the bottom of the page", "preferences.fields.autoload_more_label": "Automatically load more items when scrolled to the bottom of the page",
"preferences.fields.autoload_timelines_label": "Automatically load new posts when scrolled to the top of the page", "preferences.fields.autoload_timelines_label": "Automatically load new posts when scrolled to the top of the page",
"preferences.fields.boost_modal_label": "Show confirmation dialog before reposting", "preferences.fields.boost_modal_label": "Show confirmation dialog before reposting",