From cddc811c02b37a0dd0bff24b36ff562f42497231 Mon Sep 17 00:00:00 2001 From: nyx <60797172+verticalsync@users.noreply.github.com> Date: Thu, 16 May 2024 08:26:40 +0300 Subject: [PATCH] feat(ViewIcons): Group & User DMs icons support (#2464) --- src/plugins/viewIcons/index.tsx | 58 ++++++++++++++++++++++++++++++--- src/utils/constants.ts | 4 +++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/plugins/viewIcons/index.tsx b/src/plugins/viewIcons/index.tsx index f71777ad..fc74db0f 100644 --- a/src/plugins/viewIcons/index.tsx +++ b/src/plugins/viewIcons/index.tsx @@ -36,6 +36,10 @@ interface GuildContextProps { guild?: Guild; } +interface GroupDMContextProps { + channel: Channel; +} + const settings = definePluginSettings({ format: { type: OptionType.SELECT, @@ -145,10 +149,27 @@ const GuildContext: NavContextMenuPatchCallback = (children, { guild }: GuildCon )); }; +const GroupDMContext: NavContextMenuPatchCallback = (children, { channel }: GroupDMContextProps) => { + if (!channel) return; + + children.splice(-1, 0, ( + + + openImage(IconUtils.getChannelIconURL(channel)!) + } + icon={ImageIcon} + /> + + )); +}; + export default definePlugin({ name: "ViewIcons", - authors: [Devs.Ven, Devs.TheKodeToad, Devs.Nuckyz], - description: "Makes avatars and banners in user profiles clickable, and adds View Icon/Banner entries in the user and server context menu", + authors: [Devs.Ven, Devs.TheKodeToad, Devs.Nuckyz, Devs.nyx], + description: "Makes avatars and banners in user profiles clickable, adds View Icon/Banner entries in the user, server and group channel context menu.", tags: ["ImageUtilities"], settings, @@ -157,11 +178,12 @@ export default definePlugin({ contextMenus: { "user-context": UserContext, - "guild-context": GuildContext + "guild-context": GuildContext, + "gdm-context": GroupDMContext }, patches: [ - // Make pfps clickable + // Profiles Modal pfp { find: "User Profile Modal - Context Menu", replacement: { @@ -169,7 +191,7 @@ export default definePlugin({ replace: "{src:$1,onClick:()=>$self.openImage($1)" } }, - // Make banners clickable + // Banners { find: ".NITRO_BANNER,", replacement: { @@ -180,12 +202,38 @@ export default definePlugin({ 'onClick:ev=>$1&&ev.target.style.backgroundImage&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,' } }, + // User DMs "User Profile" popup in the right { find: ".avatarPositionPanel", replacement: { match: /(?<=avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/, replace: "style:($1)?{cursor:\"pointer\"}:{},onClick:$1?()=>{$self.openImage($2)}" } + }, + // Group DMs top small & large icon + { + find: ".recipients.length>=2", + all: true, + replacement: { + match: /null==\i\.icon\?.+?src:(\(0,\i\.getChannelIconURL\).+?\))(?=[,}])/, + replace: (m, iconUrl) => `${m},onClick:()=>$self.openImage(${iconUrl})` + } + }, + // User DMs top small icon + { + find: /HiddenVisually,{children:\i\.\i\.Messages\.DIRECT_MESSAGE/, + replacement: { + match: /.Avatar,.+?src:(.+?\))(?=[,}])/, + replace: (m, avatarUrl) => `${m},onClick:()=>$self.openImage(${avatarUrl})` + } + }, + // User Dms top large icon + { + find: 'experimentLocation:"empty_messages"', + replacement: { + match: /.Avatar,.+?src:(.+?\))(?=[,}])/, + replace: (m, avatarUrl) => `${m},onClick:()=>$self.openImage(${avatarUrl})` + } } ] }); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index a77edf7d..e6e13bf3 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -490,6 +490,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "ScattrdBlade", id: 678007540608532491n }, + nyx: { + name: "verticalsync", + id: 328165170536775680n + }, } satisfies Record); // iife so #__PURE__ works correctly