Plugin
ReplyTimestamp
Shows a timestamp on replied-message previews
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import "./style.css";8
9
import ErrorBoundary from "@components/ErrorBoundary";10
import { Devs } from "@utils/constants";11
import definePlugin from "@utils/types";12
import type { Message } from "@vencord/discord-types";13
import { findCssClassesLazy } from "@webpack";14
import { DateUtils, Timestamp } from "@webpack/common";15
import type { HTMLAttributes } from "react";16
17
const MessageClasses = findCssClassesLazy("separator", "latin24CompactTimeStamp");18
19
function Sep(props: HTMLAttributes<HTMLElement>) {20
return <i className={MessageClasses.separator} aria-hidden={true} {...props} />;21
}22
23
const enum ReferencedMessageState {24
LOADED = 0,25
NOT_LOADED = 1,26
DELETED = 2,27
}28
29
type ReferencedMessage = { state: ReferencedMessageState.LOADED; message: Message; } | { state: ReferencedMessageState.NOT_LOADED | ReferencedMessageState.DELETED; };30
31
function 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
<Timestamp43
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
58
export 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 ValidReply67
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