import React, { FC } from '../../../lib/teact/teact'; import { getDispatch, withGlobal } from '../../../lib/teact/teactn'; import { ApiChat, ApiUser } from '../../../api/types'; import { selectUser } from '../../../modules/selectors'; type OwnProps = { userId?: string; username?: string; children: any; }; type StateProps = { userOrChat?: ApiUser | ApiChat; }; const MentionLink: FC = ({ username, userOrChat, children, }) => { const { openChat, openChatByUsername, } = getDispatch(); const handleClick = () => { if (userOrChat) { openChat({ id: userOrChat.id }); } else if (username) { openChatByUsername({ username: username.substring(1) }); } }; return ( {children} ); }; export default withGlobal( (global, { userId }): StateProps => { return { userOrChat: userId ? selectUser(global, userId) : undefined, }; }, )(MentionLink);