import React, { memo } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { ApiUser } from '../../api/types'; import { ANIMATION_END_DELAY } from '../../config'; import { getUserFirstOrLastName } from '../../global/helpers'; import { selectTabState, selectUser } from '../../global/selectors'; import { LOCAL_TGS_URLS } from './helpers/animatedAssets'; import renderText from './helpers/renderText'; import useLang from '../../hooks/useLang'; import useLastCallback from '../../hooks/useLastCallback'; import Button from '../ui/Button'; import Modal, { ANIMATION_DURATION } from '../ui/Modal'; import Separator from '../ui/Separator'; import AnimatedIconWithPreview from './AnimatedIconWithPreview'; import Icon from './Icon'; import styles from './PrivacySettingsNoticeModal.module.scss'; export type OwnProps = { isOpen: boolean; }; type StateProps = { user?: ApiUser; isReadDate?: boolean; }; const CLOSE_ANIMATION_DURATION = ANIMATION_DURATION + ANIMATION_END_DELAY; const PrivacySettingsNoticeModal = ({ isOpen, isReadDate, user }: OwnProps & StateProps) => { const lang = useLang(); const { updateGlobalPrivacySettings, openPremiumModal, closePrivacySettingsNoticeModal, showNotification, setPrivacyVisibility, loadUser, } = getActions(); const userName = getUserFirstOrLastName(user); const handleShowReadTime = useLastCallback(() => { updateGlobalPrivacySettings({ shouldHideReadMarks: false }); closePrivacySettingsNoticeModal(); setTimeout(() => { showNotification({ message: lang('PremiumReadSet') }); }, CLOSE_ANIMATION_DURATION); }); const handleShowLastSeen = useLastCallback(() => { setPrivacyVisibility({ privacyKey: 'lastSeen', visibility: 'everybody', onSuccess: () => loadUser({ userId: user!.id }), }); closePrivacySettingsNoticeModal(); setTimeout(() => { showNotification({ message: lang('PremiumLastSeenSet') }); }, CLOSE_ANIMATION_DURATION); }); const handleOpenPremium = useLastCallback(() => { closePrivacySettingsNoticeModal(); setTimeout(() => { openPremiumModal(); }, CLOSE_ANIMATION_DURATION); }); const handleClose = useLastCallback(() => { closePrivacySettingsNoticeModal(); }); return (

{lang(isReadDate ? 'PremiumReadHeader1' : 'PremiumLastSeenHeader1')}

{renderText( lang( isReadDate ? 'PremiumReadText1' : 'PremiumLastSeenText1Locked', userName, ), ['simple_markdown'], )}

{lang('PremiumOr')}

{lang('PremiumReadHeader2')}

{renderText( lang(isReadDate ? 'PremiumReadText2' : 'PremiumLastSeenText2', userName), ['simple_markdown'], )}

); }; export default memo( withGlobal((global): StateProps => { const { chatId, isReadDate } = selectTabState(global).privacySettingsNoticeModal || {}; const user = chatId ? selectUser(global, chatId) : undefined; return { user, isReadDate }; })(PrivacySettingsNoticeModal), );