import { X } from "@styled-icons/boxicons-regular"; import { Crown } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; import { Presence } from "revolt-api/types/Users"; import { Channel } from "revolt.js/dist/maps/Channels"; import { User } from "revolt.js/dist/maps/Users"; import styles from "./Item.module.scss"; import classNames from "classnames"; import { Ref } from "preact"; import { refContextMenu } from "preact-context-menu"; import { Localizer, Text } from "preact-i18n"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { stopPropagation } from "../../../lib/stopPropagation"; import { useIntermediate } from "../../../context/intermediate/Intermediate"; import ChannelIcon from "../../common/ChannelIcon"; import Tooltip from "../../common/Tooltip"; import UserIcon from "../../common/user/UserIcon"; import { Username } from "../../common/user/UserShort"; import UserStatus from "../../common/user/UserStatus"; import IconButton from "../../ui/IconButton"; import { Children } from "../../../types/Preact"; type CommonProps = Omit< JSX.HTMLAttributes, "children" | "as" > & { active?: boolean; alert?: "unread" | "mention"; alertCount?: number; margin?: boolean; muted?: boolean; }; type UserProps = CommonProps & { user: User; context?: Channel; channel?: Channel; }; // TODO: Gray out blocked names. export const UserButton = observer((props: UserProps) => { const { active, alert, margin, alertCount, user, context, channel, ...divProps } = props; const { openScreen } = useIntermediate(); return (
}>
{
{typeof channel?.last_message?.content === "string" && alert ? ( channel.last_message.content.slice(0, 32) ) : ( )}
}
{context?.channel_type === "Group" && context.owner_id === user._id && ( }> )} {alert && (
{alertCount}
)} {!isTouchscreenDevice && channel && ( stopPropagation(e) && openScreen({ id: "special_prompt", type: "close_dm", target: channel, }) }> )}
); }); type ChannelProps = CommonProps & { channel: Channel; user?: User; compact?: boolean; }; export const ChannelButton = observer((props: ChannelProps) => { const { active, alert, alertCount, channel, user, compact, muted, ...divProps } = props; if (channel.channel_type === "SavedMessages") throw "Invalid channel type."; if (channel.channel_type === "DirectMessage") { if (typeof user === "undefined") throw "No user provided."; return ; } const { openScreen } = useIntermediate(); const alerting = alert && !muted && !active; return (
}>
{channel.name}
{channel.channel_type === "Group" && (
{typeof channel.last_message?.content === "string" && alert && !muted ? ( channel.last_message.content.slice(0, 32) ) : ( )}
)}
{alerting && (
{alertCount}
)} {!isTouchscreenDevice && channel.channel_type === "Group" && ( openScreen({ id: "special_prompt", type: "leave_group", target: channel, }) }> )}
); }); type ButtonProps = CommonProps & { onClick?: () => void; children?: Children; className?: string; compact?: boolean; }; export default function ButtonItem(props: ButtonProps) { const { active, alert, alertCount, onClick, className, children, compact, ...divProps } = props; return (
{children}
{alert && (
{alertCount}
)}
); }