import { Text } from "preact-i18n"; import classNames from "classnames"; import styles from "./Friend.module.scss"; import { useContext } from "preact/hooks"; import { Children } from "../../types/Preact"; import IconButton from "../../components/ui/IconButton"; import { attachContextMenu } from "preact-context-menu"; import { X, Plus } from "@styled-icons/boxicons-regular"; import { User, Users } from "revolt.js/dist/api/objects"; import { stopPropagation } from "../../lib/stopPropagation"; import { VoiceOperationsContext } from "../../context/Voice"; import UserIcon from "../../components/common/user/UserIcon"; import UserStatus from '../../components/common/user/UserStatus'; import { PhoneCall, Envelope } from "@styled-icons/boxicons-solid"; import { useIntermediate } from "../../context/intermediate/Intermediate"; import { AppContext, OperationsContext } from "../../context/revoltjs/RevoltClient"; interface Props { user: User; } export function Friend({ user }: Props) { const client = useContext(AppContext); const { openScreen } = useIntermediate(); const { openDM } = useContext(OperationsContext); const { connect } = useContext(VoiceOperationsContext); const actions: Children[] = []; let subtext: Children = null; if (user.relationship === Users.Relationship.Friend) { subtext = actions.push( <> stopPropagation(ev, openDM(user._id).then(connect))}> stopPropagation(ev, openDM(user._id))}> ); } if (user.relationship === Users.Relationship.Incoming) { actions.push( stopPropagation(ev, client.users.addFriend(user.username))}> ); subtext = ; } if (user.relationship === Users.Relationship.Outgoing) { subtext = ; } if ( user.relationship === Users.Relationship.Friend || user.relationship === Users.Relationship.Outgoing || user.relationship === Users.Relationship.Incoming ) { actions.push( stopPropagation(ev, client.users.removeFriend(user._id))}> ); } if (user.relationship === Users.Relationship.Blocked) { actions.push( stopPropagation(ev, client.users.unblockUser(user._id))}> ); } return (
openScreen({ id: 'profile', user_id: user._id })} onContextMenu={attachContextMenu('Menu', { user: user._id })}>
@{user.username} {subtext && ( {subtext} )}
{actions}
); }