Plugin
ReplyTimestamp
Shows a timestamp on replied-message previews
1
import "./style.css";2
3
import ErrorBoundary from "@components/ErrorBoundary";4
import { Devs } from "@utils/constants";5
import definePlugin from "@utils/types";6
import type { Message } from "@vencord/discord-types";7
import { findCssClassesLazy } from "@webpack";8
import { DateUtils, Timestamp } from "@webpack/common";9
import type { HTMLAttributes } from "react";10
11
const MessageClasses = findCssClassesLazy("separator", "latin24CompactTimeStamp");12
13
function Sep(props: HTMLAttributes<HTMLElement>) {14
return <i className={MessageClasses.separator} aria-hidden={true} {...props} />;15
}16
17
const enum ReferencedMessageState {18
LOADED = 0,19
NOT_LOADED = 1,20
DELETED = 2,21
}22
23
type ReferencedMessage = { state: ReferencedMessageState.LOADED; message: Message; } | { state: ReferencedMessageState.NOT_LOADED | ReferencedMessageState.DELETED; };24
25
function 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
<Timestamp37
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
52
export 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 ValidReply61
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