2021-07-09 17:08:00 -04:00
|
|
|
import { Reply } from "@styled-icons/boxicons-regular";
|
|
|
|
import { File } from "@styled-icons/boxicons-solid";
|
2021-07-29 10:51:19 -04:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-07-10 10:57:29 -04:00
|
|
|
import { useHistory } from "react-router-dom";
|
2021-07-30 15:24:53 -04:00
|
|
|
import { RelationshipStatus } from "revolt-api/types/Users";
|
2021-07-06 14:29:27 -04:00
|
|
|
import { SYSTEM_USER_ID } from "revolt.js";
|
2021-07-30 15:24:53 -04:00
|
|
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
|
|
|
import { Message } from "revolt.js/dist/maps/Messages";
|
2021-07-05 06:23:23 -04:00
|
|
|
import styled, { css } from "styled-components";
|
|
|
|
|
|
|
|
import { Text } from "preact-i18n";
|
2021-07-10 13:06:21 -04:00
|
|
|
import { useLayoutEffect, useState } from "preact/hooks";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-23 13:26:41 -04:00
|
|
|
import { useRenderState } from "../../../../lib/renderer/Singleton";
|
|
|
|
|
2021-07-29 11:55:07 -04:00
|
|
|
import { useClient } from "../../../../context/revoltjs/RevoltClient";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import Markdown from "../../../markdown/Markdown";
|
|
|
|
import UserShort from "../../user/UserShort";
|
2021-07-06 14:29:09 -04:00
|
|
|
import { SystemMessage } from "../SystemMessage";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-23 13:26:41 -04:00
|
|
|
interface Props {
|
2021-07-30 15:24:53 -04:00
|
|
|
channel: Channel;
|
2021-07-05 06:25:20 -04:00
|
|
|
index: number;
|
|
|
|
id: string;
|
2021-06-23 13:26:41 -04:00
|
|
|
}
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
export const ReplyBase = styled.div<{
|
2021-07-05 06:25:20 -04:00
|
|
|
head?: boolean;
|
|
|
|
fail?: boolean;
|
|
|
|
preview?: boolean;
|
2021-07-05 06:23:23 -04:00
|
|
|
}>`
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 4px;
|
2021-07-25 09:18:48 -04:00
|
|
|
min-width: 0;
|
2021-07-05 06:25:20 -04:00
|
|
|
display: flex;
|
2021-07-09 15:46:35 -04:00
|
|
|
margin-inline-start: 30px;
|
|
|
|
margin-inline-end: 12px;
|
|
|
|
margin-bottom: 4px;
|
2021-07-05 06:25:20 -04:00
|
|
|
font-size: 0.8em;
|
|
|
|
user-select: none;
|
|
|
|
align-items: center;
|
|
|
|
color: var(--secondary-foreground);
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-09 05:10:36 -04:00
|
|
|
* {
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
|
2021-07-09 15:46:35 -04:00
|
|
|
.user {
|
2021-08-04 08:48:33 -04:00
|
|
|
gap: 6px;
|
2021-07-25 09:18:48 -04:00
|
|
|
display: flex;
|
2021-07-09 15:46:35 -04:00
|
|
|
flex-shrink: 0;
|
|
|
|
font-weight: 600;
|
2021-07-25 09:18:48 -04:00
|
|
|
overflow: visible;
|
2021-07-09 15:46:35 -04:00
|
|
|
align-items: center;
|
|
|
|
|
2021-07-09 15:56:09 -04:00
|
|
|
span {
|
|
|
|
cursor: pointer;
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 15:46:35 -04:00
|
|
|
/*&::before {
|
|
|
|
position:relative;
|
|
|
|
width: 50px;
|
|
|
|
height: 2px;
|
|
|
|
background: red;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2021-07-09 05:10:36 -04:00
|
|
|
.content {
|
|
|
|
gap: 4px;
|
|
|
|
display: flex;
|
2021-07-09 05:15:32 -04:00
|
|
|
cursor: pointer;
|
2021-07-09 05:10:36 -04:00
|
|
|
align-items: center;
|
|
|
|
flex-direction: row;
|
2021-07-09 15:56:09 -04:00
|
|
|
transition: filter 1s ease-in-out;
|
2021-07-10 10:57:29 -04:00
|
|
|
transition: transform ease-in-out 0.1s;
|
2021-07-09 15:56:09 -04:00
|
|
|
filter: brightness(1);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
filter: brightness(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
transform: translateY(1px);
|
|
|
|
}
|
2021-07-09 05:10:36 -04:00
|
|
|
|
2021-07-09 05:15:32 -04:00
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2021-07-09 17:08:00 -04:00
|
|
|
|
2021-08-04 08:48:33 -04:00
|
|
|
/*> span > p {
|
2021-07-09 17:08:00 -04:00
|
|
|
display: flex;
|
2021-08-04 08:48:33 -04:00
|
|
|
}*/
|
2021-07-09 05:10:36 -04:00
|
|
|
}
|
2021-06-26 04:45:07 -04:00
|
|
|
|
2021-07-09 05:10:36 -04:00
|
|
|
> svg:first-child {
|
2021-07-05 06:25:20 -04:00
|
|
|
flex-shrink: 0;
|
|
|
|
transform: scaleX(-1);
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.fail &&
|
|
|
|
css`
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
`}
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.head &&
|
|
|
|
css`
|
|
|
|
margin-top: 12px;
|
|
|
|
`}
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.preview &&
|
|
|
|
css`
|
|
|
|
margin-left: 0;
|
|
|
|
`}
|
2021-06-23 13:26:41 -04:00
|
|
|
`;
|
|
|
|
|
2021-07-29 10:51:19 -04:00
|
|
|
export const MessageReply = observer(({ index, channel, id }: Props) => {
|
2021-07-30 15:24:53 -04:00
|
|
|
const view = useRenderState(channel._id);
|
2021-07-05 06:25:20 -04:00
|
|
|
if (view?.type !== "RENDER") return null;
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-30 15:24:53 -04:00
|
|
|
const [message, setMessage] = useState<Message | undefined>(undefined);
|
|
|
|
|
2021-07-09 05:10:36 -04:00
|
|
|
useLayoutEffect(() => {
|
|
|
|
// ! FIXME: We should do this through the message renderer, so it can fetch it from cache if applicable.
|
|
|
|
const m = view.messages.find((x) => x._id === id);
|
|
|
|
|
|
|
|
if (m) {
|
|
|
|
setMessage(m);
|
|
|
|
} else {
|
2021-07-30 15:24:53 -04:00
|
|
|
channel.fetchMessage(id).then(setMessage);
|
2021-07-09 05:10:36 -04:00
|
|
|
}
|
2021-07-10 10:57:29 -04:00
|
|
|
}, [view.messages]);
|
2021-07-09 05:10:36 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (!message) {
|
|
|
|
return (
|
|
|
|
<ReplyBase head={index === 0} fail>
|
|
|
|
<Reply size={16} />
|
|
|
|
<span>
|
|
|
|
<Text id="app.main.channel.misc.failed_load" />
|
|
|
|
</span>
|
|
|
|
</ReplyBase>
|
|
|
|
);
|
|
|
|
}
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-09 05:10:36 -04:00
|
|
|
const history = useHistory();
|
2021-06-23 13:26:41 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<ReplyBase head={index === 0}>
|
|
|
|
<Reply size={16} />
|
2021-07-30 15:24:53 -04:00
|
|
|
{message.author?.relationship === RelationshipStatus.Blocked ? (
|
2021-07-10 13:06:21 -04:00
|
|
|
<>
|
|
|
|
<Text id="app.main.channel.misc.blocked_user" />
|
|
|
|
</>
|
2021-07-10 10:57:29 -04:00
|
|
|
) : (
|
2021-07-09 05:10:36 -04:00
|
|
|
<>
|
2021-07-30 15:24:53 -04:00
|
|
|
{message.author_id === SYSTEM_USER_ID ? (
|
2021-07-09 05:10:36 -04:00
|
|
|
<SystemMessage message={message} hideInfo />
|
2021-07-10 10:57:29 -04:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<div className="user">
|
2021-07-30 15:24:53 -04:00
|
|
|
<UserShort user={message.author} size={16} />
|
2021-07-10 10:57:29 -04:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className="content"
|
|
|
|
onClick={() => {
|
2021-07-31 10:11:58 -04:00
|
|
|
const channel = message.channel!;
|
2021-07-30 15:24:53 -04:00
|
|
|
if (
|
|
|
|
channel.channel_type === "TextChannel"
|
|
|
|
) {
|
2021-07-31 10:11:58 -04:00
|
|
|
console.log(
|
|
|
|
`/server/${channel.server_id}/channel/${channel._id}/${message._id}`,
|
|
|
|
);
|
2021-07-10 10:57:29 -04:00
|
|
|
history.push(
|
2021-07-31 08:50:29 -04:00
|
|
|
`/server/${channel.server_id}/channel/${channel._id}/${message._id}`,
|
2021-07-10 10:57:29 -04:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
history.push(
|
2021-07-31 10:11:58 -04:00
|
|
|
`/channel/${channel._id}/${message._id}`,
|
2021-07-10 10:57:29 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}}>
|
2021-08-03 16:42:06 -04:00
|
|
|
{message.attachments && (
|
|
|
|
<>
|
|
|
|
<File size={16} />
|
|
|
|
<em>{message.attachments.length > 1 ?
|
|
|
|
"Sent multiple attachments" :
|
|
|
|
"Sent an attachment"}</em>
|
|
|
|
</>
|
2021-07-10 10:57:29 -04:00
|
|
|
)}
|
|
|
|
<Markdown
|
|
|
|
disallowBigEmoji
|
|
|
|
content={(
|
|
|
|
message.content as string
|
|
|
|
).replace(/\n/g, " ")}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2021-07-09 05:10:36 -04:00
|
|
|
</>
|
2021-07-10 10:57:29 -04:00
|
|
|
)}
|
2021-07-05 06:25:20 -04:00
|
|
|
</ReplyBase>
|
|
|
|
);
|
2021-07-29 10:51:19 -04:00
|
|
|
});
|