import type { FC } from '../../../lib/teact/teact'; import React, { memo } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiBotVerification } from '../../../api/types'; import { selectPeerFullInfo, } from '../../../global/selectors'; import useTimeout from '../../../hooks/schedulers/useTimeout'; import useLastCallback from '../../../hooks/useLastCallback'; import useHeaderPane, { type PaneState } from '../hooks/useHeaderPane'; import CustomEmoji from '../../common/CustomEmoji'; import styles from './BotVerificationPane.module.scss'; type OwnProps = { peerId: string; onPaneStateChange?: (state: PaneState) => void; }; type StateProps = { wasShown: boolean; botVerification?: ApiBotVerification; }; const BOT_VERIFICATION_ICON_SIZE = 16; const DISPLAY_DURATION_MS = 5000; // 5 sec const BotVerificationPane: FC = ({ peerId, wasShown, botVerification, onPaneStateChange, }) => { const isOpen = Boolean(!wasShown && botVerification); const { markBotVerificationInfoShown, } = getActions(); const { ref, shouldRender } = useHeaderPane({ isOpen, onStateChange: onPaneStateChange, }); const markAsShowed = useLastCallback(() => { markBotVerificationInfoShown({ peerId }); }); useTimeout(markAsShowed, !wasShown ? DISPLAY_DURATION_MS : undefined); if (!shouldRender || !botVerification) return undefined; return (
{botVerification.description}
); }; export default memo(withGlobal( (global, { peerId }): StateProps => { const peerFullInfo = selectPeerFullInfo(global, peerId); const botVerification = peerFullInfo?.botVerification; const wasShown = global.settings.botVerificationShownPeerIds.includes(peerId); return { botVerification, wasShown, }; }, )(BotVerificationPane));