mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 18:06:22 +00:00
d19b0aeb5b
Co-authored-by: programminglaboratorys <107296738+programminglaboratorys@users.noreply.github.com> Co-authored-by: Haruka <personal@shiroko.me> Co-authored-by: Amia <9750071+aamiaa@users.noreply.github.com> Co-authored-by: AutumnVN <autumnvnchino@gmail.com> Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com>
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
import "./style.css";
|
|
|
|
import ErrorBoundary from "@components/ErrorBoundary";
|
|
import { Devs } from "@utils/constants";
|
|
import definePlugin from "@utils/types";
|
|
import { filters, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
|
|
import { Timestamp } from "@webpack/common";
|
|
import type { Message } from "discord-types/general";
|
|
import type { HTMLAttributes } from "react";
|
|
|
|
const { calendarFormat, dateFormat, isSameDay } = mapMangledModuleLazy("millisecondsInUnit:", {
|
|
calendarFormat: filters.byCode("sameElse"),
|
|
dateFormat: filters.byCode('":'),
|
|
isSameDay: filters.byCode("Math.abs(+"),
|
|
});
|
|
const MessageClasses = findByPropsLazy("separator", "latin24CompactTimeStamp");
|
|
|
|
function Sep(props: HTMLAttributes<HTMLElement>) {
|
|
return <i className={MessageClasses.separator} aria-hidden={true} {...props} />;
|
|
}
|
|
|
|
const enum ReferencedMessageState {
|
|
LOADED = 0,
|
|
NOT_LOADED = 1,
|
|
DELETED = 2,
|
|
}
|
|
|
|
type ReferencedMessage = { state: ReferencedMessageState.LOADED; message: Message; } | { state: ReferencedMessageState.NOT_LOADED | ReferencedMessageState.DELETED; };
|
|
|
|
function ReplyTimestamp({
|
|
referencedMessage,
|
|
baseMessage,
|
|
}: {
|
|
referencedMessage: ReferencedMessage,
|
|
baseMessage: Message;
|
|
}) {
|
|
if (referencedMessage.state !== ReferencedMessageState.LOADED) return null;
|
|
const refTimestamp = referencedMessage.message.timestamp as any;
|
|
const baseTimestamp = baseMessage.timestamp as any;
|
|
return (
|
|
<Timestamp
|
|
className="vc-reply-timestamp"
|
|
compact={isSameDay(refTimestamp, baseTimestamp)}
|
|
timestamp={refTimestamp}
|
|
isInline={false}
|
|
>
|
|
<Sep>[</Sep>
|
|
{isSameDay(refTimestamp, baseTimestamp)
|
|
? dateFormat(refTimestamp, "LT")
|
|
: calendarFormat(refTimestamp)
|
|
}
|
|
<Sep>]</Sep>
|
|
</Timestamp>
|
|
);
|
|
}
|
|
|
|
export default definePlugin({
|
|
name: "ReplyTimestamp",
|
|
description: "Shows a timestamp on replied-message previews",
|
|
authors: [Devs.Kyuuhachi],
|
|
|
|
patches: [
|
|
{
|
|
find: ".REPLY_QUOTE_MESSAGE_BLOCKED",
|
|
replacement: {
|
|
match: /(?<="aria-label":\i,children:\[)(?=\i,\i,\i\])/,
|
|
replace: "$self.ReplyTimestamp(arguments[0]),"
|
|
}
|
|
}
|
|
],
|
|
|
|
ReplyTimestamp: ErrorBoundary.wrap(ReplyTimestamp, { noop: true }),
|
|
});
|