/* * 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 { 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"; const container = findByPropsLazy("memberSinceWrapper"); 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: [ // User popup { find: ".AnalyticsSections.USER_PROFILE}", replacement: { match: /\i.default,\{userId:(\i.id).{0,30}}\)/, 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} })` } } ], 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; return (
Friends Since
{!!getCurrentChannel()?.guild_id && ( )} {getCreatedAtDate(friendsSince, locale.getLocale())}
); }, { noop: true }) });