From 7e7eabdc422733bd449054e1949607221593113f Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 27 Nov 2021 17:41:49 +0100 Subject: [PATCH] Message / Album: Fix video auto-play --- src/components/middle/message/Album.tsx | 17 +++++++++++------ src/components/middle/message/Message.tsx | 4 +--- src/modules/selectors/messages.ts | 11 ++++++++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/middle/message/Album.tsx b/src/components/middle/message/Album.tsx index 581be4ec..da7b2118 100644 --- a/src/components/middle/message/Album.tsx +++ b/src/components/middle/message/Album.tsx @@ -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; const Album: FC = ({ album, observeIntersection, - canAutoLoad, - canAutoPlay, hasCustomAppendix, lastSyncTime, isOwn, @@ -67,6 +68,10 @@ const Album: FC = ({ 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 diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 15238291..2c3f4a9c 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -508,8 +508,6 @@ const Message: FC = ({ album={album!} albumLayout={albumLayout!} observeIntersection={observeIntersectionForMedia} - canAutoLoad={canAutoLoadMedia} - canAutoPlay={canAutoPlayMedia} isOwn={isOwn} hasCustomAppendix={hasCustomAppendix} lastSyncTime={lastSyncTime} @@ -892,7 +890,7 @@ export default memo(withGlobal( 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), diff --git a/src/modules/selectors/messages.ts b/src/modules/selectors/messages.ts index fa9b5f33..7f31a10f 100644 --- a/src/modules/selectors/messages.ts +++ b/src/modules/selectors/messages.ts @@ -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));