import React, { memo } from '../../lib/teact/teact'; import { withGlobal } from '../../global'; import type { FC } from '../../lib/teact/teact'; import type { ApiBotInfo } from '../../api/types'; import { DPR } from '../../util/windowEnvironment'; import renderText from '../common/helpers/renderText'; import { getBotCoverMediaHash, getDocumentMediaHash, getPhotoFullDimensions, getVideoDimensions, } from '../../global/helpers'; import buildStyle from '../../util/buildStyle'; import buildClassName from '../../util/buildClassName'; import { selectBot, selectUserFullInfo } from '../../global/selectors'; import useMedia from '../../hooks/useMedia'; import useLang from '../../hooks/useLang'; import OptimizedVideo from '../ui/OptimizedVideo'; import Skeleton from '../ui/Skeleton'; import styles from './MessageListBotInfo.module.scss'; type OwnProps = { chatId: string; isInMessageList?: boolean; }; type StateProps = { botInfo?: ApiBotInfo; isLoadingBotInfo?: boolean; }; const MessageListBotInfo: FC = ({ botInfo, isLoadingBotInfo, isInMessageList, }) => { const lang = useLang(); const botInfoPhotoUrl = useMedia(botInfo?.photo ? getBotCoverMediaHash(botInfo.photo) : undefined); const botInfoGifUrl = useMedia(botInfo?.gif ? getDocumentMediaHash(botInfo.gif) : undefined); const botInfoDimensions = botInfo?.photo ? getPhotoFullDimensions(botInfo.photo) : botInfo?.gif ? getVideoDimensions(botInfo.gif) : undefined; const botInfoRealDimensions = botInfoDimensions && { width: botInfoDimensions.width / DPR, height: botInfoDimensions.height / DPR, }; const isBotInfoEmpty = botInfo && !botInfo.description && !botInfo.gif && !botInfo.photo; const { width, height } = botInfoRealDimensions || {}; const isEmptyOrLoading = isBotInfoEmpty || isLoadingBotInfo; if (isEmptyOrLoading && isInMessageList) return undefined; return (
{isLoadingBotInfo && {lang('Loading')}} {isBotInfoEmpty && !isLoadingBotInfo && {lang('NoMessages')}} {botInfo && (
{botInfoPhotoUrl && ( Bot info )} {botInfoGifUrl && ( )} {botInfoDimensions && !botInfoPhotoUrl && !botInfoGifUrl && ( )} {botInfo.description && (

{lang('BotInfoTitle')}

{renderText(botInfo.description, ['br', 'emoji', 'links'])}
)}
)}
); }; export default memo(withGlobal( (global, { chatId }) => { const chatBot = selectBot(global, chatId); let isLoadingBotInfo = false; let botInfo; if (chatBot) { const chatBotFullInfo = selectUserFullInfo(global, chatBot.id); if (chatBotFullInfo) { botInfo = chatBotFullInfo.botInfo; } else { isLoadingBotInfo = true; } } return { botInfo, isLoadingBotInfo, }; }, )(MessageListBotInfo));