Skip to content

Commit 42b3ae8

Browse files
authored
ViewIcons: fix conflicts with profile/group modal (#3720)
1 parent a040c8d commit 42b3ae8

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/plugins/viewIcons/index.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { openImageModal } from "@utils/discord";
2424
import definePlugin, { OptionType } from "@utils/types";
2525
import type { Channel, Guild, User } from "@vencord/discord-types";
2626
import { GuildMemberStore, IconUtils, Menu } from "@webpack/common";
27+
import type { MouseEvent } from "react";
2728

2829

2930
interface UserContextProps {
@@ -68,10 +69,18 @@ const settings = definePluginSettings({
6869
}
6970
});
7071

71-
const openAvatar = (url: string) => openImage(url, 512, 512);
72-
const openBanner = (url: string) => openImage(url, 1024);
72+
const openAvatar = (url: string, event?: MouseEvent) => openImage({ url, width: 512, height: 512, event });
73+
const openBanner = (url: string, event?: MouseEvent) => openImage({ url, width: 1024, event });
7374

74-
function openImage(url: string, width: number, height?: number) {
75+
interface OpenImageProps {
76+
url: string;
77+
width: number;
78+
height?: number;
79+
event?: MouseEvent;
80+
}
81+
82+
function openImage({ url, width, height, event }: OpenImageProps) {
83+
event?.stopPropagation();
7584
const u = new URL(url, window.location.href);
7685

7786
const format = url.startsWith("/")
@@ -224,7 +233,7 @@ export default definePlugin({
224233
find: 'backgroundColor:"COMPLETE"',
225234
replacement: {
226235
match: /(overflow:"visible",.{0,125}?!1\),)style:{(?=.+?backgroundImage:null!=(\i)\?`url\(\$\{\2\}\))/,
227-
replace: (_, rest, bannerSrc) => `${rest}onClick:()=>${bannerSrc}!=null&&$self.openBanner(${bannerSrc}),style:{cursor:${bannerSrc}!=null?"pointer":void 0,`
236+
replace: (_, rest, bannerSrc) => `${rest}onClick:vcEvent=>${bannerSrc}!=null&&$self.openBanner(${bannerSrc}, vcEvent),style:{cursor:${bannerSrc}!=null?"pointer":void 0,`
228237
}
229238
},
230239
// Group DMs top small & large icon
@@ -233,23 +242,23 @@ export default definePlugin({
233242
replacement: {
234243
match: /null==\i\.icon\?.+?src:(\(0,\i\.\i\).+?\))(?=[,}])/,
235244
// We have to check that icon is not an unread GDM in the server bar
236-
replace: (m, iconUrl) => `${m},onClick:()=>arguments[0]?.size!=="SIZE_48"&&$self.openAvatar(${iconUrl})`
245+
replace: (m, iconUrl) => `${m},onClick:vcEvent=>arguments[0]?.size!=="SIZE_48"&&$self.openAvatar(${iconUrl},vcEvent)`
237246
}
238247
},
239248
// User DMs top small icon
240249
{
241250
find: ".channel.getRecipientId(),",
242251
replacement: {
243252
match: /(?=,src:(\i.getAvatarURL\(.+?[)]))/,
244-
replace: (_, avatarUrl) => `,onClick:()=>$self.openAvatar(${avatarUrl})`
253+
replace: (_, avatarUrl) => `,onClick:vcEvent=>$self.openAvatar(${avatarUrl},vcEvent)`
245254
}
246255
},
247256
// User Dms top large icon
248257
{
249258
find: ".EMPTY_GROUP_DM)",
250259
replacement: {
251260
match: /(?<=SIZE_80,)(?=src:(.+?\))[,}])/,
252-
replace: (_, avatarUrl) => `onClick:()=>$self.openAvatar(${avatarUrl}),`
261+
replace: (_, avatarUrl) => `onClick:vcEvent=>$self.openAvatar(${avatarUrl},vcEvent),`
253262
}
254263
}
255264
]

0 commit comments

Comments
 (0)