Plugin

ReplyTimestamp

Shows a timestamp on replied-message previews

Chat Appearance
index.tsx
Download

Source

src/plugins/replyTimestamp/index.tsx
1import "./style.css";
2
3import ErrorBoundary from "@components/ErrorBoundary";
4import { Devs } from "@utils/constants";
5import definePlugin from "@utils/types";
6import type { Message } from "@vencord/discord-types";
7import { findCssClassesLazy } from "@webpack";
8import { DateUtils, Timestamp } from "@webpack/common";
9import type { HTMLAttributes } from "react";
10
11const MessageClasses = findCssClassesLazy("separator", "latin24CompactTimeStamp");
12
13function Sep(props: HTMLAttributes<HTMLElement>) {
14 return <i className={MessageClasses.separator} aria-hidden={true} {...props} />;
15}
16
17const enum ReferencedMessageState {
18 LOADED = 0,
19 NOT_LOADED = 1,
20 DELETED = 2,
21}
22
23type ReferencedMessage = { state: ReferencedMessageState.LOADED; message: Message; } | { state: ReferencedMessageState.NOT_LOADED | ReferencedMessageState.DELETED; };
24
25function ReplyTimestamp({
26 referencedMessage,
27 baseMessage,
28}: {
29 referencedMessage: ReferencedMessage,
30 baseMessage: Message;
31}) {
32 if (referencedMessage.state !== ReferencedMessageState.LOADED) return null;
33 const refTimestamp = referencedMessage.message.timestamp as any;
34 const baseTimestamp = baseMessage.timestamp as any;
35 return (
36 <Timestamp
37 className="vc-reply-timestamp"
38 compact={DateUtils.isSameDay(refTimestamp, baseTimestamp)}
39 timestamp={refTimestamp}
40 isInline={false}
41 >
42 <Sep>[</Sep>
43 {DateUtils.isSameDay(refTimestamp, baseTimestamp)
44 ? DateUtils.dateFormat(refTimestamp, "LT")
45 : DateUtils.calendarFormat(refTimestamp)
46 }
47 <Sep>]</Sep>
48 </Timestamp>
49 );
50}
51
52export default definePlugin({
53 name: "ReplyTimestamp",
54 description: "Shows a timestamp on replied-message previews",
55 tags: ["Chat", "Appearance"],
56 authors: [Devs.Kyuuhachi],
57
58 patches: [
59 {
60 // Same find as in ValidReply
61 find: "#{intl::REPLY_QUOTE_MESSAGE_NOT_LOADED}",
62 replacement: {
63 match: /\.onClickReply,.+?}\),(?=\i,\i,\i\])/,
64 replace: "$&$self.ReplyTimestamp(arguments[0]),"
65 }
66 }
67 ],
68
69 ReplyTimestamp: ErrorBoundary.wrap(ReplyTimestamp, { noop: true }),
70});
71