import type { FC } from '../../../lib/teact/teact'; import { memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiSession } from '../../../api/types'; import buildClassName from '../../../util/buildClassName'; import { formatDateTimeToString } from '../../../util/dates/dateFormat'; import getSessionIcon from './helpers/getSessionIcon'; import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev'; import useOldLang from '../../../hooks/useOldLang'; import Icon from '../../common/icons/Icon'; import Button from '../../ui/Button'; import ListItem from '../../ui/ListItem'; import Modal from '../../ui/Modal'; import Switcher from '../../ui/Switcher'; import styles from './SettingsActiveSession.module.scss'; type OwnProps = { isOpen: boolean; hash?: string; onClose: () => void; }; type StateProps = { session?: ApiSession; }; const SettingsActiveSession: FC = ({ isOpen, session, onClose, }) => { const { changeSessionSettings, terminateAuthorization } = getActions(); const lang = useOldLang(); const renderingSession = useCurrentOrPrev(session, true); const handleSecretChatsStateChange = useCallback(() => { changeSessionSettings({ hash: session!.hash, areSecretChatsEnabled: !session!.areSecretChatsEnabled, }); }, [changeSessionSettings, session]); const handleCallsStateChange = useCallback(() => { changeSessionSettings({ hash: session!.hash, areCallsEnabled: !session!.areCallsEnabled, }); }, [changeSessionSettings, session]); const handleTerminateSessionClick = useCallback(() => { terminateAuthorization({ hash: session!.hash }); onClose(); }, [onClose, session, terminateAuthorization]); if (!renderingSession) { return undefined; } function renderHeader() { return (
{lang('SessionPreview.Title')}
); } return (

{renderingSession?.deviceModel}

{formatDateTimeToString(renderingSession.dateActive * 1000, lang.code)}
{lang('SessionPreview.App')}
{renderingSession?.appName} {' '} {renderingSession?.appVersion} , {' '} {renderingSession?.platform} {' '} {renderingSession?.systemVersion}
{lang('SessionPreview.Ip')}
{renderingSession?.ip}
{lang('SessionPreview.Location')}
{renderingSession && getLocation(renderingSession)}

{lang('SessionPreview.IpDesc')}

{lang('AuthSessions.View.AcceptTitle')}

{lang('SessionPreview.Accept.Secret')} {lang('SessionPreview.Accept.Calls')} ); }; function getLocation(session: ApiSession) { return [session.region, session.country].filter(Boolean).join(', '); } export default memo(withGlobal((global, { hash }) => { return { session: hash ? global.activeSessions.byHash[hash] : undefined, }; })(SettingsActiveSession));