diff --git a/src/plugins/friendsSince/index.tsx b/src/plugins/friendsSince/index.tsx index fb431b52b..8ad9dc7f4 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 }) }); -