/* * 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 definePlugin from "@utils/types"; import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack"; import { Heading, RelationshipStore, Text } from "@webpack/common"; const containerWrapper = findByPropsLazy("memberSinceWrapper"); const container = findByPropsLazy("memberSince"); const getCreatedAtDate = findByCodeLazy('month:"short",day:"numeric"'); const locale = findByPropsLazy("getLocale"); const section = findLazy((m: any) => m.section !== void 0 && m.heading !== void 0 && Object.values(m).length === 2); export default definePlugin({ name: "FriendsSince", description: "Shows when you became friends with someone in the user popout", authors: [Devs.Elvyra, Devs.Antti], patches: [ // DM User Sidebar { find: ".PANEL}),nicknameIcons", replacement: { match: /USER_PROFILE_MEMBER_SINCE,.{0,100}userId:(\i\.id)}\)}\)/, replace: "$&,$self.friendsSinceNew({userId:$1,isSidebar:true})" } }, // User Profile Modal { find: "action:\"PRESS_APP_CONNECTION\"", replacement: { match: /USER_PROFILE_MEMBER_SINCE,.{0,100}userId:(\i\.id),.{0,100}}\)}\),/, replace: "$&,$self.friendsSinceNew({userId:$1,isSidebar:false})," } } ], getFriendSince(userId: string) { try { if (!RelationshipStore.isFriend(userId)) return null; return RelationshipStore.getSince(userId); } catch (err) { new Logger("FriendsSince").error(err); return null; } }, friendsSinceNew: ErrorBoundary.wrap(({ userId, isSidebar }: { userId: string; isSidebar: boolean; }) => { if (!RelationshipStore.isFriend(userId)) return null; const friendsSince = RelationshipStore.getSince(userId); if (!friendsSince) return null; return (
Friends Since { isSidebar ? ( {getCreatedAtDate(friendsSince, locale.getLocale())} ) : (
{!!getCurrentChannel()?.guild_id && ( )} {getCreatedAtDate(friendsSince, locale.getLocale())}
) }
); }, { noop: true }), });