Skip to content

Commit

Permalink
buhh
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico040 committed May 13, 2024
1 parent fa7dea2 commit 2203189
Showing 1 changed file with 63 additions and 60 deletions.
123 changes: 63 additions & 60 deletions plugins/picture-links/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,94 @@ import { ReactNative } from "@vendetta/metro/common";
const { Pressable } = findByProps("Button", "Text", "View");
const ProfileBanner = findByName("ProfileBanner", false);
const HeaderAvatar = findByName("HeaderAvatar", false);
const GuildIcon = findByName("GuildIcon", false);
const GuildIcon = findByName("GuildName", false)
const { openMediaModal } = findByProps("openMediaModal");
const { hideActionSheet } = findByProps("hideActionSheet");
const { getChannelId } = findByStoreName("SelectedChannelStore");
const { getGuildId } = findByStoreName("SelectedGuildStore");

function getImageSize(uri: string): Promise<{width: number, height: number}> {
return new Promise((resolve, reject) => {
ReactNative.Image.getSize(
uri,
(width, height) => resolve({width, height}),
(error) => reject(error)
);
});
return new Promise((resolve, reject) => {
ReactNative.Image.getSize(
uri,
(width, height) => resolve({width, height}),
(error) => reject(error)
);
});
}

async function openModal(src: string, event) {
const { width, height } = await getImageSize(src);
const { width, height } = await getImageSize(src);

hideActionSheet(); // hide user sheet
openMediaModal({
initialSources: [{
uri: src,
sourceURI: src,
width,
height,
guildId: getGuildId(),
channelId: getChannelId(),
}],
initialIndex: 0,
originLayout: {
width: 0, // this would ideally be the size of the small pfp but this proved very hard to implement
height: 0,
x: event.pageX,
y: event.pageY,
resizeMode: "fill",
}
});
hideActionSheet(); // hide user sheet
openMediaModal({
initialSources: [{
uri: src,
sourceURI: src,
width,
height,
guildId: getGuildId(),
channelId: getChannelId(),
}],
initialIndex: 0,
originLayout: {
width: 0, // this would ideally be the size of the small pfp but this proved very hard to implement
height: 0,
x: event.pageX,
y: event.pageY,
resizeMode: "fill",
}
});
}

const unpatchAvatar = after("default", HeaderAvatar, ([{ user, style, guildId }], res) => {
const guildSpecific = user.guildMemberAvatars?.[guildId] && `https://cdn.discordapp.com/guilds/${guildId}/users/${user.id}/avatars/${user.guildMemberAvatars[guildId]}.png?size=4096`;
const image = user?.getAvatarURL?.(false, 4096, true);
if (!image) return res;
const guildSpecific = user.guildMemberAvatars?.[guildId] && `https://cdn.discordapp.com/guilds/${guildId}/users/${user.id}/avatars/${user.guildMemberAvatars[guildId]}.png?size=4096`;
const image = user?.getAvatarURL?.(false, 4096, true);
if (!image) return res;

const url =
typeof image === "number"
? `https://cdn.discordapp.com/embed/avatars/${Number(BigInt(user.id) >> 22n) % 6}.png`
: image?.replace(".webp", ".png");
const url =
typeof image === "number"
? `https://cdn.discordapp.com/embed/avatars/${Number(BigInt(user.id) >> 22n) % 6}.png`
: image?.replace(".webp", ".png");

delete res.props.style;
delete res.props.style;

return (
<Pressable
onPress={({ nativeEvent }) => openModal(url, nativeEvent)}
onLongPress={({ nativeEvent }) => guildSpecific && openModal(guildSpecific, nativeEvent)}
style={style}>
{res}
</Pressable>
);
return (
<Pressable
onPress={({ nativeEvent }) => openModal(url, nativeEvent)}
onLongPress={({ nativeEvent }) => guildSpecific && openModal(guildSpecific, nativeEvent)}
style={style}>
{res}
</Pressable>
);
});

const unpatchBanner = after("default", ProfileBanner, ([{ bannerSource }], res) => {
if (typeof bannerSource?.uri !== "string" || !res) return res;
if (typeof bannerSource?.uri !== "string" || !res) return res;

const url = bannerSource.uri
.replace(/(?:\?size=\d{3,4})?$/, "?size=4096")
.replace(".webp", ".png");
const url = bannerSource.uri
.replace(/(?:\?size=\d{3,4})?$/, "?size=4096")
.replace(".webp", ".png");

return <Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>{res}</Pressable>;
return <Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>{res}</Pressable>;
});

const unpatchGuildIcon = after("default", GuildIcon, ([{ size, guild }], res) => {
if (size !== "XLARGE") return;
const url = `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.png?size=4096`
var unpatchGuildIcon = after("default", GuildIcon, ([{ size, guild }], res) => {
if (size !== "XLARGE") return;
var ext = "png"
if (guild?.icon.includes('a_')) { ext = "gif"; }
const url = `https://cdn.discordapp.com/icons/${guild?.id}/${guild?.icon}.${ext}?size=4096`

return (
<Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>
{res}
</Pressable>
);
return (
<Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>
{res}
</Pressable>
);
});


export function onUnload() {
unpatchAvatar();
unpatchBanner();
unpatchGuildIcon();
unpatchAvatar();
unpatchBanner();
unpatchGuildIcon();
}

0 comments on commit 2203189

Please sign in to comment.