import type { FC } from '../../../lib/teact/teact'; import React, { memo } from '../../../lib/teact/teact'; import type { ApiMessage } from '../../../api/types'; import { getActions } from '../../../global'; import { getGamePreviewPhotoHash, getGamePreviewVideoHash, getMessageText } from '../../../global/helpers'; import useMedia from '../../../hooks/useMedia'; import Skeleton from '../../ui/placeholder/Skeleton'; import './Game.scss'; const DEFAULT_PREVIEW_DIMENSIONS = { width: 480, height: 270, }; type OwnProps = { message: ApiMessage; canAutoLoadMedia?: boolean; }; const Game: FC = ({ message, canAutoLoadMedia, }) => { const { clickBotInlineButton } = getActions(); const game = message.content.game!; const { title, description, } = game; const photoHash = getGamePreviewPhotoHash(game); const videoHash = getGamePreviewVideoHash(game); const photoBlobUrl = useMedia(photoHash, !canAutoLoadMedia); const videoBlobUrl = useMedia(videoHash, !canAutoLoadMedia); const handleGameClick = () => { clickBotInlineButton({ messageId: message.id, button: message.inlineButtons![0][0], }); }; return (
{!photoBlobUrl && !videoBlobUrl && ( )} {photoBlobUrl && ( {title} )} {videoBlobUrl && (
{title}
{!getMessageText(message) &&
{description}
}
); }; export default memo(Game);