From f55584beb0e295018d49799b630c10cbeffa5b73 Mon Sep 17 00:00:00 2001
From: Rico040 <93081680+Rico040@users.noreply.github.com>
Date: Tue, 21 May 2024 20:42:16 +1000
Subject: [PATCH] Picture Links: stupid compatibility patch for older versions
of discord
---
plugins/picture-links/src/index.tsx | 44 ++++++++++++++++++++---------
1 file changed, 31 insertions(+), 13 deletions(-)
diff --git a/plugins/picture-links/src/index.tsx b/plugins/picture-links/src/index.tsx
index 367c46a..a873090 100644
--- a/plugins/picture-links/src/index.tsx
+++ b/plugins/picture-links/src/index.tsx
@@ -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");
@@ -77,19 +76,38 @@ const unpatchBanner = after("default", ProfileBanner, ([{ bannerSource }], res)
return openModal(url, nativeEvent)}>{res};
});
-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 (
- openModal(url, nativeEvent)}>
- {res}
-
- );
-});
+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 (
+ openModal(url, nativeEvent)}>
+ {res}
+
+ );
+ });
+} 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 (
+ openModal(url, nativeEvent)}>
+ {res}
+
+ );
+ });
+}
export function onUnload() {
unpatchAvatar();