Message / Album: Fix video auto-play

This commit is contained in:
Alexander Zinchuk 2021-11-27 17:41:49 +01:00
parent d7e6ebfe06
commit 7e7eabdc42
3 changed files with 20 additions and 12 deletions

View File

@ -6,11 +6,16 @@ import { IAlbum, ISettings } from '../../../types';
import { AlbumRectPart, IAlbumLayout } from './helpers/calculateAlbumLayout';
import { getMessageContent } from '../../../modules/helpers';
import { withGlobal } from '../../../lib/teact/teactn';
import { getGlobal, withGlobal } from '../../../lib/teact/teactn';
import { pick } from '../../../util/iteratees';
import withSelectControl from './hocs/withSelectControl';
import { ObserveFn } from '../../../hooks/useIntersectionObserver';
import { selectActiveDownloadIds, selectTheme } from '../../../modules/selectors';
import {
selectActiveDownloadIds,
selectCanAutoLoadMedia,
selectCanAutoPlayMedia,
selectTheme,
} from '../../../modules/selectors';
import Photo from './Photo';
import Video from './Video';
@ -23,8 +28,6 @@ const VideoWithSelect = withSelectControl(Video);
type OwnProps = {
album: IAlbum;
observeIntersection: ObserveFn;
canAutoLoad?: boolean;
canAutoPlay?: boolean;
hasCustomAppendix?: boolean;
lastSyncTime?: number;
isOwn: boolean;
@ -43,8 +46,6 @@ type DispatchProps = Pick<GlobalActions, 'cancelSendingMessage'>;
const Album: FC<OwnProps & StateProps & DispatchProps> = ({
album,
observeIntersection,
canAutoLoad,
canAutoPlay,
hasCustomAppendix,
lastSyncTime,
isOwn,
@ -67,6 +68,10 @@ const Album: FC<OwnProps & StateProps & DispatchProps> = ({
const uploadProgress = fileUpload?.progress;
const { dimensions, sides } = albumLayout.layout[index];
// Ignoring global updates is a known drawback here
const canAutoLoad = selectCanAutoLoadMedia(getGlobal(), message);
const canAutoPlay = selectCanAutoPlayMedia(getGlobal(), message);
if (photo) {
const shouldAffectAppendix = hasCustomAppendix && (
// eslint-disable-next-line no-bitwise

View File

@ -508,8 +508,6 @@ const Message: FC<OwnProps & StateProps & DispatchProps> = ({
album={album!}
albumLayout={albumLayout!}
observeIntersection={observeIntersectionForMedia}
canAutoLoad={canAutoLoadMedia}
canAutoPlay={canAutoPlayMedia}
isOwn={isOwn}
hasCustomAppendix={hasCustomAppendix}
lastSyncTime={lastSyncTime}
@ -892,7 +890,7 @@ export default memo(withGlobal<OwnProps>(
threadId,
isDownloading,
isPinnedList: messageListType === 'pinned',
canAutoLoadMedia: chat ? selectCanAutoLoadMedia(global, message, chat, sender) : undefined,
canAutoLoadMedia: selectCanAutoLoadMedia(global, message),
canAutoPlayMedia: selectCanAutoPlayMedia(global, message),
autoLoadFileMaxSizeMb: global.settings.byKey.autoLoadFileMaxSizeMb,
shouldLoopStickers: selectShouldLoopStickers(global),

View File

@ -734,9 +734,14 @@ export function selectNewestMessageWithBotKeyboardButtons(
return messageId ? chatMessages[messageId] : undefined;
}
export function selectCanAutoLoadMedia(
global: GlobalState, message: ApiMessage, chat: ApiChat, sender?: ApiChat | ApiUser,
) {
export function selectCanAutoLoadMedia(global: GlobalState, message: ApiMessage) {
const chat = selectChat(global, message.chatId);
if (!chat) {
return undefined;
}
const sender = selectSender(global, message);
const isPhoto = Boolean(getMessagePhoto(message) || getMessageWebPagePhoto(message));
const isVideo = Boolean(getMessageVideo(message) || getMessageWebPageVideo(message));
const isFile = Boolean(getMessageAudio(message) || getMessageVoice(message) || getMessageDocument(message));