2024-03-11 15:31:36 +00:00
|
|
|
/*
|
|
|
|
* 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";
|
2024-04-09 00:52:21 +00:00
|
|
|
import { getCurrentChannel } from "@utils/discord";
|
2024-05-18 03:36:50 +00:00
|
|
|
import { Logger } from "@utils/Logger";
|
|
|
|
import { classes } from "@utils/misc";
|
2024-03-11 15:31:36 +00:00
|
|
|
import definePlugin from "@utils/types";
|
2024-04-26 21:31:22 +00:00
|
|
|
import { findByPropsLazy } from "@webpack";
|
2024-05-02 13:38:53 +00:00
|
|
|
import { Heading, React, RelationshipStore, Text } from "@webpack/common";
|
2024-03-11 15:31:36 +00:00
|
|
|
|
2024-04-26 21:31:22 +00:00
|
|
|
const container = findByPropsLazy("memberSinceWrapper");
|
2024-03-11 15:31:36 +00:00
|
|
|
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: [
|
2024-05-18 03:36:50 +00:00
|
|
|
// User popup
|
2024-03-11 15:31:36 +00:00
|
|
|
{
|
2024-06-19 01:04:15 +00:00
|
|
|
find: ".USER_PROFILE}};return",
|
2024-03-11 15:31:36 +00:00
|
|
|
replacement: {
|
2024-06-19 01:04:15 +00:00
|
|
|
match: /\i.\i,\{userId:(\i.id).{0,30}}\)/,
|
2024-03-11 15:31:36 +00:00
|
|
|
replace: "$&,$self.friendsSince({ userId: $1 })"
|
|
|
|
}
|
|
|
|
},
|
2024-05-18 03:36:50 +00:00
|
|
|
// User DMs "User Profile" popup in the right
|
2024-03-11 15:31:36 +00:00
|
|
|
{
|
2024-06-19 01:04:15 +00:00
|
|
|
find: ".PROFILE_PANEL,",
|
2024-03-11 15:31:36 +00:00
|
|
|
replacement: {
|
2024-06-19 01:04:15 +00:00
|
|
|
match: /\i.\i,\{userId:([^,]+?)}\)/,
|
2024-03-11 15:31:36 +00:00
|
|
|
replace: "$&,$self.friendsSince({ userId: $1 })"
|
|
|
|
}
|
2024-05-18 03:36:50 +00:00
|
|
|
},
|
|
|
|
// 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} })`
|
|
|
|
}
|
2024-03-11 15:31:36 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
2024-05-18 03:36:50 +00:00
|
|
|
getFriendSince(userId: string) {
|
|
|
|
try {
|
2024-05-26 16:24:02 +00:00
|
|
|
if (!RelationshipStore.isFriend(userId)) return null;
|
|
|
|
|
2024-05-18 03:36:50 +00:00
|
|
|
return RelationshipStore.getSince(userId);
|
|
|
|
} catch (err) {
|
|
|
|
new Logger("FriendsSince").error(err);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
friendsSince: ErrorBoundary.wrap(({ userId, textClassName }: { userId: string; textClassName?: string; }) => {
|
2024-05-26 16:24:02 +00:00
|
|
|
if (!RelationshipStore.isFriend(userId)) return null;
|
|
|
|
|
2024-03-11 15:31:36 +00:00
|
|
|
const friendsSince = RelationshipStore.getSince(userId);
|
|
|
|
if (!friendsSince) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={lastSection.section}>
|
|
|
|
<Heading variant="eyebrow" className={clydeMoreInfo.title}>
|
|
|
|
Friends Since
|
|
|
|
</Heading>
|
|
|
|
|
2024-04-26 21:31:22 +00:00
|
|
|
<div className={container.memberSinceWrapper}>
|
2024-04-09 00:52:21 +00:00
|
|
|
{!!getCurrentChannel()?.guild_id && (
|
|
|
|
<svg
|
|
|
|
aria-hidden="true"
|
|
|
|
width="16"
|
|
|
|
height="16"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
fill="var(--interactive-normal)"
|
|
|
|
>
|
|
|
|
<path d="M13 10a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z" />
|
|
|
|
<path d="M3 5v-.75C3 3.56 3.56 3 4.25 3s1.24.56 1.33 1.25C6.12 8.65 9.46 12 13 12h1a8 8 0 0 1 8 8 2 2 0 0 1-2 2 .21.21 0 0 1-.2-.15 7.65 7.65 0 0 0-1.32-2.3c-.15-.2-.42-.06-.39.17l.25 2c.02.15-.1.28-.25.28H9a2 2 0 0 1-2-2v-2.22c0-1.57-.67-3.05-1.53-4.37A15.85 15.85 0 0 1 3 5Z" />
|
|
|
|
</svg>
|
|
|
|
)}
|
2024-05-18 03:36:50 +00:00
|
|
|
<Text variant="text-sm/normal" className={classes(clydeMoreInfo.body, textClassName)}>
|
2024-03-11 15:31:36 +00:00
|
|
|
{getCreatedAtDate(friendsSince, locale.getLocale())}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}, { noop: true })
|
|
|
|
});
|