Skip to content

Commit

Permalink
Picture Links: stupid compatibility patch for older versions of discord
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico040 committed May 21, 2024
1 parent b5870b9 commit f55584b
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions plugins/picture-links/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 { openMediaModal } = findByProps("openMediaModal");
const { hideActionSheet } = findByProps("hideActionSheet");
const { getChannelId } = findByStoreName("SelectedChannelStore");
Expand Down Expand Up @@ -77,19 +76,38 @@ const unpatchBanner = after("default", ProfileBanner, ([{ bannerSource }], res)
return <Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>{res}</Pressable>;
});

var unpatchGuildIcon = after("default", GuildIcon, ([{ size, guild }], res) => {
if (size !== "XLARGE" || guild?.icon == null) 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>
);
});
var unpatchGuildIcon

if (typeof findByName("GuildIcon").prototype.render !== "undefined") {
// Compatibility patch with older versions
const GuildIcon = findByName("GuildIcon");
unpatchGuildIcon = after("render", GuildIcon.prototype, function (_, res) {
if (this.props?.size !== "XLARGE") return;
const url = this.props?.guild?.getIconURL?.(4096);
if (!url) return res;

return (
<Pressable onPress={({ nativeEvent }) => openModal(url, nativeEvent)}>
{res}
</Pressable>
);
});
} else {
// Patch for newer versions
const GuildIcon = findByName("GuildIcon", false);
unpatchGuildIcon = after("default", GuildIcon, ([{ size, guild }], res) => {
if (size !== "XLARGE" || guild?.icon == null) 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>
);
});
}

export function onUnload() {
unpatchAvatar();
Expand Down

0 comments on commit f55584b

Please sign in to comment.