import { At, Reply as ReplyIcon } from "@styled-icons/boxicons-regular"; import { File, XCircle } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; import { Channel } from "revolt.js/dist/maps/Channels"; import { Message } from "revolt.js/dist/maps/Messages"; import styled from "styled-components"; import { Text } from "preact-i18n"; import { StateUpdater, useEffect } from "preact/hooks"; import { internalSubscribe } from "../../../../lib/eventEmitter"; import { getRenderer } from "../../../../lib/renderer/Singleton"; import { dispatch, getState } from "../../../../redux"; import { Reply } from "../../../../redux/reducers/queue"; import { useClient } from "../../../../context/revoltjs/RevoltClient"; import IconButton from "../../../ui/IconButton"; import Markdown from "../../../markdown/Markdown"; import UserShort from "../../user/UserShort"; import { SystemMessage } from "../SystemMessage"; import { ReplyBase } from "../attachments/MessageReply"; interface Props { channel: Channel; replies: Reply[]; setReplies: StateUpdater; } const Base = styled.div` display: flex; height: 30px; padding: 0 12px; user-select: none; align-items: center; background: var(--message-box); > div { flex-grow: 1; margin-bottom: 0; &::before { display: none; } } .toggle { gap: 4px; display: flex; font-size: 12px; align-items: center; font-weight: 600; } .username { display: flex; align-items: center; gap: 6px; font-weight: 600; } .message { display: flex; } .actions { gap: 12px; display: flex; } /*@media (pointer: coarse) { //FIXME: Make action buttons bigger on pointer coarse .actions > svg { height: 25px; } }*/ `; // ! FIXME: Move to global config const MAX_REPLIES = 4; export default observer(({ channel, replies, setReplies }: Props) => { const client = useClient(); useEffect(() => { return internalSubscribe("ReplyBar", "add", (_message) => { const message = _message as Message; if ( replies.length >= MAX_REPLIES || replies.find((x) => x.id === message._id) ) return; setReplies([ ...replies, { id: message._id, mention: message.author_id === client.user!._id ? false : getState().sectionToggle.mention ?? false, }, ]); }); }, [replies, setReplies, client.user]); const renderer = getRenderer(channel); if (renderer.state !== "RENDER") return null; const ids = replies.map((x) => x.id); const messages = renderer.messages.filter((x) => ids.includes(x._id)); return (
{replies.map((reply, index) => { const message = messages.find((x) => reply.id === x._id); // ! FIXME: better solution would be to // ! have a hook for resolving messages from // ! render state along with relevant users // -> which then fetches any unknown messages if (!message) return ( ); return (
{message.attachments && ( <> {message.attachments.length > 1 ? ( ) : ( )} )} {message.author_id === "00000000000000000000000000" ? ( ) : ( )}
{message.author_id !== client.user!._id && ( { let state = false; setReplies( replies.map((_, i) => { if (i === index) { state = !_.mention; return { ..._, mention: !_.mention, }; } return _; }), ); dispatch({ type: "SECTION_TOGGLE_SET", id: "mention", state, }); }}> {" "} {reply.mention ? "ON" : "OFF"} )} setReplies( replies.filter((_, i) => i !== index), ) }> ); })}
); });