From d3acd7edc7d7972888f06ea6c919587d11e825ff Mon Sep 17 00:00:00 2001 From: Kyuuhachi <1547062+Kyuuhachi@users.noreply.github.com> Date: Wed, 8 May 2024 03:32:09 +0200 Subject: [PATCH] new plugin ReplyTimestamp: show timestamps of replied messages (#2296) Co-authored-by: vee --- src/plugins/replyTimestamp/README.md | 5 ++ src/plugins/replyTimestamp/index.tsx | 77 ++++++++++++++++++++++++++++ src/plugins/replyTimestamp/style.css | 3 ++ 3 files changed, 85 insertions(+) create mode 100644 src/plugins/replyTimestamp/README.md create mode 100644 src/plugins/replyTimestamp/index.tsx create mode 100644 src/plugins/replyTimestamp/style.css diff --git a/src/plugins/replyTimestamp/README.md b/src/plugins/replyTimestamp/README.md new file mode 100644 index 000000000..b7952bf3a --- /dev/null +++ b/src/plugins/replyTimestamp/README.md @@ -0,0 +1,5 @@ +# ReplyTimestamp + +Shows timestamps on the previews of replied-to messages. Pretty simple. + +![](https://github.com/Vendicated/Vencord/assets/1547062/62e2b67a-e567-4c7a-884d-4640f897f7e0) diff --git a/src/plugins/replyTimestamp/index.tsx b/src/plugins/replyTimestamp/index.tsx new file mode 100644 index 000000000..05ec28b1b --- /dev/null +++ b/src/plugins/replyTimestamp/index.tsx @@ -0,0 +1,77 @@ +/* + * 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 { findByPropsLazy } from "@webpack"; +import { Timestamp } from "@webpack/common"; +import type { Message } from "discord-types/general"; +import type { HTMLAttributes } from "react"; + +const { getMessageTimestampId } = findByPropsLazy("getMessageTimestampId"); +const { calendarFormat, dateFormat, isSameDay } = findByPropsLazy("calendarFormat", "dateFormat", "isSameDay", "accessibilityLabelCalendarFormat"); +const MessageClasses = findByPropsLazy("separator", "latin24CompactTimeStamp"); + +function Sep(props: HTMLAttributes) { + return ; +} + +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 ( + + [ + {isSameDay(refTimestamp, baseTimestamp) + ? dateFormat(refTimestamp, "LT") + : calendarFormat(refTimestamp) + } + ] + + ); +} + +export default definePlugin({ + name: "ReplyTimestamp", + description: "Shows a timestamp on replied-message previews", + authors: [Devs.Kyuuhachi], + + patches: [ + { + find: "renderSingleLineMessage:function()", + replacement: { + match: /(?<="aria-label":\i,children:\[)(?=\i,\i,\i\])/, + replace: "$self.ReplyTimestamp(arguments[0])," + } + } + ], + + ReplyTimestamp: ErrorBoundary.wrap(ReplyTimestamp, { noop: true }), +}); diff --git a/src/plugins/replyTimestamp/style.css b/src/plugins/replyTimestamp/style.css new file mode 100644 index 000000000..f42371717 --- /dev/null +++ b/src/plugins/replyTimestamp/style.css @@ -0,0 +1,3 @@ +.vc-reply-timestamp { + margin-right: 0.25em; +}