Plugin

ReplyTimestamp

Shows a timestamp on replied-message previews

Chat Appearance
index.tsx
Download

Source

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