From 04a86490a5e20419639e3222145711c271655f66 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 18 May 2024 00:36:50 -0300 Subject: [PATCH] FriendsSince: Show in user profile modal --- src/plugins/friendsSince/index.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/plugins/friendsSince/index.tsx b/src/plugins/friendsSince/index.tsx index fb431b5..8ad9dc7 100644 --- a/src/plugins/friendsSince/index.tsx +++ b/src/plugins/friendsSince/index.tsx @@ -7,6 +7,8 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { getCurrentChannel } from "@utils/discord"; +import { Logger } from "@utils/Logger"; +import { classes } from "@utils/misc"; import definePlugin from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { Heading, React, RelationshipStore, Text } from "@webpack/common"; @@ -22,6 +24,7 @@ export default definePlugin({ description: "Shows when you became friends with someone in the user popout", authors: [Devs.Elvyra], patches: [ + // User popup { find: ".AnalyticsSections.USER_PROFILE}", replacement: { @@ -29,16 +32,34 @@ export default definePlugin({ replace: "$&,$self.friendsSince({ userId: $1 })" } }, + // User DMs "User Profile" popup in the right { find: ".UserPopoutUpsellSource.PROFILE_PANEL,", replacement: { match: /\i.default,\{userId:(\i)}\)/, replace: "$&,$self.friendsSince({ userId: $1 })" } + }, + // User Profile Modal + { + find: ".userInfoSectionHeader,", + replacement: { + match: /(\.Messages\.USER_PROFILE_MEMBER_SINCE.+?userId:(.+?),textClassName:)(\i\.userInfoText)}\)/, + replace: (_, rest, userId, textClassName) => `${rest}!$self.getFriendSince(${userId}) ? ${textClassName} : void 0 }), $self.friendsSince({ userId: ${userId}, textClassName: ${textClassName} })` + } } ], - friendsSince: ErrorBoundary.wrap(({ userId }: { userId: string; }) => { + getFriendSince(userId: string) { + try { + return RelationshipStore.getSince(userId); + } catch (err) { + new Logger("FriendsSince").error(err); + return null; + } + }, + + friendsSince: ErrorBoundary.wrap(({ userId, textClassName }: { userId: string; textClassName?: string; }) => { const friendsSince = RelationshipStore.getSince(userId); if (!friendsSince) return null; @@ -61,7 +82,7 @@ export default definePlugin({ )} - + {getCreatedAtDate(friendsSince, locale.getLocale())} @@ -69,4 +90,3 @@ export default definePlugin({ ); }, { noop: true }) }); -