import React, { FC, memo, useCallback, } from '../../../lib/teact/teact'; import { withGlobal } from '../../../lib/teact/teactn'; import { GlobalActions } from '../../../global/types'; import { ApiChat, ApiCountryCode, ApiUser } from '../../../api/types'; import { SettingsScreens } from '../../../types'; import { CHAT_HEIGHT_PX } from '../../../config'; import { formatPhoneNumberWithCode } from '../../../util/phoneNumber'; import { pick } from '../../../util/iteratees'; import { getChatTitle, getUserFullName, isChatPrivate, } from '../../../modules/helpers'; import renderText from '../../common/helpers/renderText'; import buildClassName from '../../../util/buildClassName'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; import FloatingActionButton from '../../ui/FloatingActionButton'; import Avatar from '../../common/Avatar'; import Loading from '../../ui/Loading'; type OwnProps = { isActive?: boolean; onScreenSelect: (screen: SettingsScreens) => void; onReset: () => void; }; type StateProps = { chatsByIds: Record; usersByIds: Record; blockedIds: number[]; phoneCodeList: ApiCountryCode[]; }; type DispatchProps = Pick; const SettingsPrivacyBlockedUsers: FC = ({ isActive, onScreenSelect, onReset, chatsByIds, usersByIds, blockedIds, phoneCodeList, unblockContact, }) => { const handleUnblockClick = useCallback((contactId: number) => { unblockContact({ contactId }); }, [unblockContact]); const lang = useLang(); useHistoryBack(isActive, onReset, onScreenSelect, SettingsScreens.PrivacyBlockedUsers); function renderContact(contactId: number, i: number, viewportOffset: number) { const isPrivate = isChatPrivate(contactId); const user = isPrivate ? usersByIds[contactId] : undefined; const chat = !isPrivate ? chatsByIds[contactId] : undefined; const className = buildClassName( 'Chat chat-item-clickable blocked-list-item small-icon', isPrivate ? 'private' : 'group', ); return ( { handleUnblockClick(contactId); }, }]} style={`top: ${(viewportOffset + i) * CHAT_HEIGHT_PX}px;`} >

{renderText((isPrivate ? getUserFullName(user) : getChatTitle(lang, chat!)) || '')}

{user?.phoneNumber && (
{formatPhoneNumberWithCode(phoneCodeList, user.phoneNumber)}
)} {user && !user.phoneNumber && user.username && (
@{user.username}
)}
); } return (

{lang('BlockedUsersInfo')}

{blockedIds?.length ? (
{blockedIds!.map((contactId, i) => renderContact(contactId, i, 0))}
) : blockedIds && !blockedIds.length ? (
List is empty
) : ( )}
{ }} className="not-implemented" ariaLabel="Add a blocked user" >
); }; export default memo(withGlobal( (global): StateProps => { const { chats: { byId: chatsByIds, }, users: { byId: usersByIds, }, blocked: { ids, }, countryList: { phoneCodes: phoneCodeList, }, } = global; return { chatsByIds, usersByIds, blockedIds: ids, phoneCodeList, }; }, (setGlobal, actions): DispatchProps => pick(actions, ['unblockContact']), )(SettingsPrivacyBlockedUsers));