mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
Fix: System messages would break replies.
Fix: Show correct time format on left side of messages.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import dayjs from "dayjs";
|
||||
import styled, { css } from "styled-components";
|
||||
import { decodeTime } from "ulid";
|
||||
|
||||
@@ -7,6 +6,8 @@ import { Text } from "preact-i18n";
|
||||
import { MessageObject } from "../../../context/revoltjs/util";
|
||||
|
||||
import Tooltip from "../Tooltip";
|
||||
import { useDictionary } from "../../../lib/i18n";
|
||||
import { dayjs } from "../../../context/Locale";
|
||||
|
||||
export interface BaseMessageProps {
|
||||
head?: boolean;
|
||||
@@ -170,13 +171,15 @@ export function MessageDetail({
|
||||
message: MessageObject;
|
||||
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("H:mm")}
|
||||
{dayjs(decodeTime(message._id)).format(dict.dayjs.timeFormat)}
|
||||
<i className="copyBracket">]</i>
|
||||
</time>
|
||||
<span className="edited">
|
||||
@@ -191,7 +194,7 @@ export function MessageDetail({
|
||||
<>
|
||||
<time>
|
||||
<i className="copyBracket">[</i>
|
||||
{dayjs(decodeTime(message._id)).format("H:mm")}
|
||||
{dayjs(decodeTime(message._id)).format(dict.dayjs.timeFormat)}
|
||||
<i className="copyBracket">]</i>
|
||||
</time>
|
||||
</>
|
||||
|
||||
@@ -9,6 +9,8 @@ import { useUser } from "../../../../context/revoltjs/hooks";
|
||||
|
||||
import Markdown from "../../../markdown/Markdown";
|
||||
import UserShort from "../../user/UserShort";
|
||||
import { SYSTEM_USER_ID } from "revolt.js";
|
||||
import { SystemMessage } from "../SystemMessage";
|
||||
|
||||
interface Props {
|
||||
channel: string;
|
||||
@@ -84,10 +86,13 @@ export function MessageReply({ index, channel, id }: Props) {
|
||||
{message.attachments && message.attachments.length > 0 && (
|
||||
<File size={16} />
|
||||
)}
|
||||
<Markdown
|
||||
disallowBigEmoji
|
||||
content={(message.content as string).replace(/\n/g, " ")}
|
||||
/>
|
||||
{ message.author === SYSTEM_USER_ID ?
|
||||
<SystemMessage message={message} /> :
|
||||
<Markdown
|
||||
disallowBigEmoji
|
||||
content={(message.content as string).replace(/\n/g, " ")}
|
||||
/>
|
||||
}
|
||||
</ReplyBase>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import IconButton from "../../../ui/IconButton";
|
||||
import Markdown from "../../../markdown/Markdown";
|
||||
import UserShort from "../../user/UserShort";
|
||||
import { ReplyBase } from "../attachments/MessageReply";
|
||||
import { SystemMessage } from "../SystemMessage";
|
||||
import { SYSTEM_USER_ID } from "revolt.js";
|
||||
|
||||
interface Props {
|
||||
channel: string;
|
||||
@@ -100,13 +102,13 @@ export default function ReplyBar({ channel, replies, setReplies }: Props) {
|
||||
message.attachments.length > 0 && (
|
||||
<File size={16} />
|
||||
)}
|
||||
<Markdown
|
||||
disallowBigEmoji
|
||||
content={(message.content as string).replace(
|
||||
/\n/g,
|
||||
" ",
|
||||
)}
|
||||
/>
|
||||
{ message.author === SYSTEM_USER_ID ?
|
||||
<SystemMessage message={message} /> :
|
||||
<Markdown
|
||||
disallowBigEmoji
|
||||
content={(message.content as string).replace(/\n/g, " ")}
|
||||
/>
|
||||
}
|
||||
</ReplyBase>
|
||||
<span class="actions">
|
||||
<IconButton
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import styled, { css } from "styled-components";
|
||||
import { dayjs } from "../../context/Locale";
|
||||
|
||||
const Base = styled.div<{ unread?: boolean }>`
|
||||
height: 0;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import dayjs from "dayjs";
|
||||
import dayJS from "dayjs";
|
||||
export const dayjs = dayJS;
|
||||
|
||||
import calendar from "dayjs/plugin/calendar";
|
||||
import format from "dayjs/plugin/localizedFormat";
|
||||
import update from "dayjs/plugin/updateLocale";
|
||||
@@ -143,12 +145,11 @@ function Locale({ children, locale }: Props) {
|
||||
// TODO: clean this up and use the built in Intl API
|
||||
function transformLanguage(source: { [key: string]: any }) {
|
||||
const obj = defaultsDeep(source, definition);
|
||||
|
||||
const dayjs = obj.dayjs;
|
||||
const defaults = dayjs.defaults;
|
||||
|
||||
const twelvehour = defaults?.twelvehour === "yes" || true;
|
||||
const separator: "/" | "-" | "." = defaults?.date_separator ?? "/";
|
||||
const separator: string = defaults?.date_separator ?? "/";
|
||||
const date: "traditional" | "simplified" | "ISO8601" =
|
||||
defaults?.date_format ?? "traditional";
|
||||
|
||||
@@ -159,19 +160,22 @@ function Locale({ children, locale }: Props) {
|
||||
};
|
||||
|
||||
dayjs["sameElse"] = DATE_FORMATS[date];
|
||||
dayjs["timeFormat"] = twelvehour ? "hh:mm A" : "HH:mm";
|
||||
|
||||
Object.keys(dayjs)
|
||||
.filter((k) => typeof dayjs[k] === 'string')
|
||||
.forEach(
|
||||
(k) =>
|
||||
(dayjs[k] = dayjs[k].replace(
|
||||
/{{time}}/g,
|
||||
twelvehour ? "LT" : "HH:mm",
|
||||
dayjs["timeFormat"],
|
||||
)),
|
||||
);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
dayjs.updateLocale("en", { calendar: { ...definition.dayjs, sameDay: 'sussy baka' } });
|
||||
useEffect(() => {
|
||||
if (locale === "en") {
|
||||
const defn = transformLanguage(definition);
|
||||
@@ -193,7 +197,7 @@ function Locale({ children, locale }: Props) {
|
||||
dayjs.updateLocale(target, { calendar: defn.dayjs });
|
||||
}
|
||||
|
||||
dayjs.locale(dayjs_locale.default);
|
||||
dayjs.locale(target, dayjs_locale.default);
|
||||
setDefinition(defn);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -12,11 +12,21 @@ interface Props {
|
||||
fields: Fields;
|
||||
}
|
||||
|
||||
export interface Dictionary {
|
||||
dayjs: {
|
||||
defaults: {
|
||||
twelvehour: 'yes' | 'no';
|
||||
separator: string;
|
||||
date: "traditional" | "simplified" | "ISO8601";
|
||||
},
|
||||
timeFormat: string
|
||||
};
|
||||
[key: string]: Object | string;
|
||||
}
|
||||
|
||||
export interface IntlType {
|
||||
intl: {
|
||||
dictionary: {
|
||||
[key: string]: Object | string;
|
||||
};
|
||||
dictionary: Dictionary;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,3 +70,8 @@ export function useTranslation() {
|
||||
return (id: string, fields?: Object, plural?: number, fallback?: string) =>
|
||||
translate(id, "", intl.dictionary, fields, plural, fallback);
|
||||
}
|
||||
|
||||
export function useDictionary() {
|
||||
const { intl } = useContext(IntlContext) as unknown as IntlType;
|
||||
return intl.dictionary;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
Safari,
|
||||
Windows,
|
||||
} from "@styled-icons/simple-icons";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { decodeTime } from "ulid";
|
||||
@@ -24,6 +24,7 @@ import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
||||
import Button from "../../../components/ui/Button";
|
||||
import Preloader from "../../../components/ui/Preloader";
|
||||
import Tip from "../../../components/ui/Tip";
|
||||
import { dayjs } from "../../../context/Locale";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user