2021-07-30 17:40:49 -04:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { Message } from "revolt.js/dist/maps/Messages";
|
2021-07-09 04:58:38 -04:00
|
|
|
import styled, { css, keyframes } from "styled-components";
|
2021-06-20 12:31:53 -04:00
|
|
|
import { decodeTime } from "ulid";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
import { Text } from "preact-i18n";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-06 14:29:27 -04:00
|
|
|
import { useDictionary } from "../../../lib/i18n";
|
2021-08-02 08:06:18 -04:00
|
|
|
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
|
2021-07-06 14:29:27 -04:00
|
|
|
|
|
|
|
import { dayjs } from "../../../context/Locale";
|
2021-06-20 12:31:53 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import Tooltip from "../Tooltip";
|
|
|
|
|
2021-06-20 12:31:53 -04:00
|
|
|
export interface BaseMessageProps {
|
2021-07-05 06:25:20 -04:00
|
|
|
head?: boolean;
|
|
|
|
failed?: boolean;
|
|
|
|
mention?: boolean;
|
|
|
|
blocked?: boolean;
|
|
|
|
sending?: boolean;
|
|
|
|
contrast?: boolean;
|
2021-07-09 04:58:38 -04:00
|
|
|
highlight?: boolean;
|
2021-06-20 12:31:53 -04:00
|
|
|
}
|
|
|
|
|
2021-07-09 04:58:38 -04:00
|
|
|
const highlight = keyframes`
|
|
|
|
0% { background: var(--mention); }
|
|
|
|
66% { background: var(--mention); }
|
|
|
|
100% { background: transparent; }
|
|
|
|
`;
|
|
|
|
|
2021-06-20 12:31:53 -04:00
|
|
|
export default styled.div<BaseMessageProps>`
|
2021-07-05 06:25:20 -04:00
|
|
|
display: flex;
|
2021-07-08 15:16:50 -04:00
|
|
|
overflow: none;
|
2021-07-05 06:25:20 -04:00
|
|
|
padding: 0.125rem;
|
|
|
|
flex-direction: row;
|
|
|
|
padding-right: 16px;
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-08-02 08:06:18 -04:00
|
|
|
@media (pointer: coarse) {
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.contrast &&
|
|
|
|
css`
|
|
|
|
padding: 0.3rem;
|
|
|
|
background: var(--hover);
|
2021-07-10 10:42:13 -04:00
|
|
|
border-radius: var(--border-radius);
|
2021-07-05 06:25:20 -04:00
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.head &&
|
|
|
|
css`
|
|
|
|
margin-top: 12px;
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.mention &&
|
|
|
|
css`
|
|
|
|
background: var(--mention);
|
|
|
|
`}
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.blocked &&
|
|
|
|
css`
|
|
|
|
filter: blur(4px);
|
|
|
|
transition: 0.2s ease filter;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
filter: none;
|
|
|
|
}
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.sending &&
|
|
|
|
css`
|
|
|
|
opacity: 0.8;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.failed &&
|
|
|
|
css`
|
|
|
|
color: var(--error);
|
|
|
|
`}
|
2021-06-21 16:11:53 -04:00
|
|
|
|
2021-07-09 04:58:38 -04:00
|
|
|
${(props) =>
|
|
|
|
props.highlight &&
|
|
|
|
css`
|
|
|
|
animation-name: ${highlight};
|
|
|
|
animation-timing-function: ease;
|
|
|
|
animation-duration: 3s;
|
|
|
|
`}
|
|
|
|
|
2021-06-24 11:43:37 -04:00
|
|
|
.detail {
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-08-02 11:25:39 -04:00
|
|
|
flex-shrink: 0;
|
2021-07-05 06:25:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.author {
|
2021-08-02 11:25:39 -04:00
|
|
|
overflow: hidden;
|
2021-07-05 06:25:20 -04:00
|
|
|
cursor: pointer;
|
|
|
|
font-weight: 600 !important;
|
|
|
|
|
2021-08-02 11:25:39 -04:00
|
|
|
display: -webkit-box;
|
|
|
|
-webkit-line-clamp: 1;
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: normal;
|
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.copy {
|
|
|
|
display: block;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--hover);
|
|
|
|
|
|
|
|
time {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const MessageInfo = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
width: 62px;
|
|
|
|
display: flex;
|
|
|
|
flex-shrink: 0;
|
|
|
|
padding-top: 2px;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
.copyBracket {
|
|
|
|
opacity: 0;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
.copyTime {
|
|
|
|
opacity: 0;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
user-select: none;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
transform: translateY(1px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
time {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
time,
|
|
|
|
.edited {
|
|
|
|
margin-top: 1px;
|
|
|
|
cursor: default;
|
|
|
|
display: inline;
|
|
|
|
font-size: 10px;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
|
|
|
|
time,
|
|
|
|
.edited > div {
|
|
|
|
&::selection {
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 17:44:15 -04:00
|
|
|
|
|
|
|
.header {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const MessageContent = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
min-width: 0;
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
// overflow: hidden;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
2021-07-24 14:39:41 -04:00
|
|
|
font-size: var(--text-size);
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
export const DetailBase = styled.div`
|
2021-08-02 11:25:39 -04:00
|
|
|
flex-shrink: 0;
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 4px;
|
|
|
|
font-size: 10px;
|
|
|
|
display: inline-flex;
|
|
|
|
color: var(--tertiary-foreground);
|
2021-07-09 17:44:15 -04:00
|
|
|
|
|
|
|
.edited {
|
|
|
|
cursor: default;
|
|
|
|
&::selection {
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
}
|
2021-06-21 16:11:53 -04:00
|
|
|
`;
|
|
|
|
|
2021-07-30 17:40:49 -04:00
|
|
|
export const MessageDetail = observer(
|
|
|
|
({ message, position }: { message: Message; position: "left" | "top" }) => {
|
|
|
|
const dict = useDictionary();
|
|
|
|
|
|
|
|
if (position === "left") {
|
|
|
|
if (message.edited) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<time className="copyTime">
|
|
|
|
<i className="copyBracket">[</i>
|
|
|
|
{dayjs(decodeTime(message._id)).format(
|
|
|
|
dict.dayjs.timeFormat,
|
|
|
|
)}
|
|
|
|
<i className="copyBracket">]</i>
|
|
|
|
</time>
|
|
|
|
<span className="edited">
|
|
|
|
<Tooltip
|
|
|
|
content={dayjs(message.edited).format("LLLL")}>
|
|
|
|
<Text id="app.main.channel.edited" />
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<>
|
2021-07-30 17:40:49 -04:00
|
|
|
<time>
|
2021-07-05 06:25:20 -04:00
|
|
|
<i className="copyBracket">[</i>
|
2021-07-06 14:29:27 -04:00
|
|
|
{dayjs(decodeTime(message._id)).format(
|
|
|
|
dict.dayjs.timeFormat,
|
|
|
|
)}
|
2021-07-05 06:25:20 -04:00
|
|
|
<i className="copyBracket">]</i>
|
|
|
|
</time>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-07-30 17:40:49 -04:00
|
|
|
|
2021-07-10 10:57:29 -04:00
|
|
|
return (
|
2021-07-30 17:40:49 -04:00
|
|
|
<DetailBase>
|
|
|
|
<time>{dayjs(decodeTime(message._id)).calendar()}</time>
|
|
|
|
{message.edited && (
|
|
|
|
<Tooltip content={dayjs(message.edited).format("LLLL")}>
|
|
|
|
<span className="edited">
|
|
|
|
<Text id="app.main.channel.edited" />
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
</DetailBase>
|
2021-07-10 10:57:29 -04:00
|
|
|
);
|
2021-07-30 17:40:49 -04:00
|
|
|
},
|
|
|
|
);
|