diff --git a/src/plugins/mutualGroupDMs.tsx b/src/plugins/mutualGroupDMs.tsx new file mode 100644 index 00000000..6d6dc528 --- /dev/null +++ b/src/plugins/mutualGroupDMs.tsx @@ -0,0 +1,104 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + + +import { Devs } from "@utils/constants"; +import { isNonNullish } from "@utils/guards"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { Avatar, ChannelStore, Clickable, RelationshipStore, ScrollerThin, UserStore } from "@webpack/common"; +import { Channel, User } from "discord-types/general"; + +const SelectedChannelActionCreators = findByPropsLazy("selectPrivateChannel"); +const AvatarUtils = findByPropsLazy("getChannelIconURL"); +const UserUtils = findByPropsLazy("getGlobalName"); + +const ProfileListClasses = findByPropsLazy("emptyIconFriends", "emptyIconGuilds"); +const GuildLabelClasses = findByPropsLazy("guildNick", "guildAvatarWithoutIcon"); + +function getGroupDMName(channel: Channel) { + return channel.name || + channel.recipients + .map(UserStore.getUser) + .filter(isNonNullish) + .map(c => RelationshipStore.getNickname(c.id) || UserUtils.getName(c)) + .join(", "); +} + +export default definePlugin({ + name: "MutualGroupDMs", + description: "Shows mutual group dms in profiles", + authors: [Devs.amia], + + patches: [ + { + find: ".Messages.USER_PROFILE_MODAL", // Note: the module is lazy-loaded + replacement: [ + { + match: /(?<=\.MUTUAL_GUILDS\}\),)(?=(\i\.bot).{0,20}(\(0,\i\.jsx\)\(.{0,100}id:))/, + replace: '$1?null:$2"MUTUAL_GDMS",children:"Mutual Groups"}),' + }, + { + match: /(?<={user:(\i),onClose:(\i)}\);)(?=case \i\.\i\.MUTUAL_FRIENDS)/, + replace: "case \"MUTUAL_GDMS\":return $self.renderMutualGDMs($1,$2);" + } + ] + } + ], + + renderMutualGDMs(user: User, onClose: () => void) { + const entries = ChannelStore.getSortedPrivateChannels().filter(c => c.isGroupDM() && c.recipients.includes(user.id)).map(c => ( + { + onClose(); + SelectedChannelActionCreators.selectPrivateChannel(c.id); + }} + > + + +
+
{getGroupDMName(c)}
+
{c.recipients.length} Members
+
+
+ )); + + return ( + + {entries.length > 0 + ? entries + : ( +
+
+
No group dms in common
+
+ ) + } +
+ ); + } +}); diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 8b07b6c2..f308cff2 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -44,6 +44,9 @@ export let Popout: t.Popout; export let Dialog: t.Dialog; export let TabBar: any; export let Paginator: t.Paginator; +export let ScrollerThin: t.ScrollerThin; +export let Clickable: t.Clickable; +export let Avatar: t.Avatar; // token lagger real /** css colour resolver stuff, no clue what exactly this does, just copied usage from Discord */ export let useToken: t.useToken; @@ -54,6 +57,6 @@ export const Flex = waitForComponent("Flex", ["Justify", "Align", "Wrap" export const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent") as Record; waitFor("FormItem", m => { - ({ useToken, Card, Button, FormSwitch: Switch, Tooltip, TextInput, TextArea, Text, Select, SearchableSelect, Slider, ButtonLooks, TabBar, Popout, Dialog, Paginator } = m); + ({ useToken, Card, Button, FormSwitch: Switch, Tooltip, TextInput, TextArea, Text, Select, SearchableSelect, Slider, ButtonLooks, TabBar, Popout, Dialog, Paginator, ScrollerThin, Clickable, Avatar } = m); Forms = m; }); diff --git a/src/webpack/common/types/components.d.ts b/src/webpack/common/types/components.d.ts index 161e0682..7bc313c3 100644 --- a/src/webpack/common/types/components.d.ts +++ b/src/webpack/common/types/components.d.ts @@ -397,3 +397,46 @@ export type Paginator = ComponentType<{ onPageChange?(page: number): void; hideMaxPage?: boolean; }>; + +export type ScrollerThin = ComponentType>; + +export type Clickable = ComponentType>; + +export type Avatar = ComponentType>;