import { X, Plus } from "@styled-icons/boxicons-regular"; import { PhoneCall, Envelope, UserX } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; import { useHistory } from "react-router-dom"; import { RelationshipStatus } from "revolt-api/types/Users"; import { User } from "revolt.js/dist/maps/Users"; import styles from "./Friend.module.scss"; import classNames from "classnames"; import { attachContextMenu } from "preact-context-menu"; import { Text } from "preact-i18n"; import { useContext } from "preact/hooks"; import { stopPropagation } from "../../lib/stopPropagation"; import { voiceState } from "../../lib/vortex/VoiceState"; import { useIntermediate } from "../../context/intermediate/Intermediate"; import UserIcon from "../../components/common/user/UserIcon"; import UserStatus from "../../components/common/user/UserStatus"; import IconButton from "../../components/ui/IconButton"; import { Children } from "../../types/Preact"; interface Props { user: User; } export const Friend = observer(({ user }: Props) => { const history = useHistory(); const { openScreen } = useIntermediate(); const actions: Children[] = []; let subtext: Children = null; if (user.relationship === RelationshipStatus.Friend) { subtext = ; actions.push( <> stopPropagation( ev, user .openDM() .then(voiceState.connect) .then((x) => history.push(`/channel/${x._id}`)), ) }> stopPropagation( ev, user .openDM() .then((channel) => history.push(`/channel/${channel._id}`), ), ) }> , ); } if (user.relationship === RelationshipStatus.Incoming) { actions.push( stopPropagation(ev, user.addFriend())}> , ); subtext = ; } if (user.relationship === RelationshipStatus.Outgoing) { subtext = ; } if ( user.relationship === RelationshipStatus.Friend || user.relationship === RelationshipStatus.Outgoing || user.relationship === RelationshipStatus.Incoming ) { actions.push( stopPropagation( ev, user.relationship === RelationshipStatus.Friend ? openScreen({ id: "special_prompt", type: "unfriend_user", target: user, }) : user.removeFriend(), ) }> , ); } if (user.relationship === RelationshipStatus.Blocked) { actions.push( stopPropagation(ev, user.unblockUser())}> , ); } return (
openScreen({ id: "profile", user_id: user._id })} onContextMenu={attachContextMenu("Menu", { user: user._id })}>
{user.username} {subtext && {subtext}}
{actions}
); });