From f9924d555acea0d197809a8e28449240fc6a8f04 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EdVraz@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:31:36 +0100 Subject: [PATCH] new Plugin: FriendsSince ~ shows friend date in profiles (#2240) * feat: Create friendsSince plugin * chore: add devs entry * fix text * Update src/plugins/friendsSince/index.tsx Co-authored-by: V * refactor: Put element into its own section * feat: add section to user profile in DMs * escape { * fixes * Add README * Wrap in ErrorBoundary --------- Co-authored-by: V --- src/plugins/friendsSince/README.md | 5 +++ src/plugins/friendsSince/index.tsx | 60 ++++++++++++++++++++++++++++++ src/utils/constants.ts | 4 ++ 3 files changed, 69 insertions(+) create mode 100644 src/plugins/friendsSince/README.md create mode 100644 src/plugins/friendsSince/index.tsx diff --git a/src/plugins/friendsSince/README.md b/src/plugins/friendsSince/README.md new file mode 100644 index 00000000..ccbb09b6 --- /dev/null +++ b/src/plugins/friendsSince/README.md @@ -0,0 +1,5 @@ +# FriendsSince + +Shows when you became friends with someone in the user popout + +![](https://github.com/Vendicated/Vencord/assets/45497981/bb258188-ab48-4c4d-9858-1e90ba41e926) diff --git a/src/plugins/friendsSince/index.tsx b/src/plugins/friendsSince/index.tsx new file mode 100644 index 00000000..ab3320df --- /dev/null +++ b/src/plugins/friendsSince/index.tsx @@ -0,0 +1,60 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { React, RelationshipStore } from "@webpack/common"; + +const { Heading, Text } = findByPropsLazy("Heading", "Text"); +const container = findByPropsLazy("memberSinceContainer"); +const { getCreatedAtDate } = findByPropsLazy("getCreatedAtDate"); +const clydeMoreInfo = findByPropsLazy("clydeMoreInfo"); +const locale = findByPropsLazy("getLocale"); +const lastSection = findByPropsLazy("lastSection"); + +export default definePlugin({ + name: "FriendsSince", + description: "Shows when you became friends with someone in the user popout", + authors: [Devs.Elvyra], + patches: [ + { + find: ".AnalyticsSections.USER_PROFILE}", + replacement: { + match: /\i.default,\{userId:(\i.id).{0,30}}\)/, + replace: "$&,$self.friendsSince({ userId: $1 })" + } + }, + { + find: ".UserPopoutUpsellSource.PROFILE_PANEL,", + replacement: { + match: /\i.default,\{userId:(\i)}\)/, + replace: "$&,$self.friendsSince({ userId: $1 })" + } + } + ], + + friendsSince: ErrorBoundary.wrap(({ userId }: { userId: string; }) => { + const friendsSince = RelationshipStore.getSince(userId); + if (!friendsSince) return null; + + return ( +
+ + Friends Since + + +
+ + {getCreatedAtDate(friendsSince, locale.getLocale())} + +
+
+ ); + }, { noop: true }) +}); + diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d213ce27..081eed34 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -422,6 +422,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ Kyuuhachi: { name: "Kyuuhachi", id: 236588665420251137n, + }, + Elvyra: { + name: "Elvyra", + id: 708275751816003615n, } } satisfies Record);