From 79cbfe96c8a444a51644d366ec6ecae00ad6a735 Mon Sep 17 00:00:00 2001
From: jamesbt365 <jamesbt365@gmail.com>
Date: Fri, 24 Jan 2025 23:56:39 +0000
Subject: [PATCH] HideAttachments, UnsupressEmbeds: Work with forwarded
 messages (#2928)

---
 src/plugins/hideAttachments/index.tsx  |  8 +++++++-
 src/plugins/unsuppressEmbeds/index.tsx | 10 ++++++++--
 src/webpack/common/types/utils.d.ts    |  6 +++++-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/plugins/hideAttachments/index.tsx b/src/plugins/hideAttachments/index.tsx
index e122e3cb5..39935d038 100644
--- a/src/plugins/hideAttachments/index.tsx
+++ b/src/plugins/hideAttachments/index.tsx
@@ -21,6 +21,7 @@ import { ImageInvisible, ImageVisible } from "@components/Icons";
 import { Devs } from "@utils/constants";
 import definePlugin from "@utils/types";
 import { ChannelStore } from "@webpack/common";
+import { MessageSnapshot } from "@webpack/types";
 
 let style: HTMLStyleElement;
 
@@ -39,7 +40,12 @@ export default definePlugin({
     authors: [Devs.Ven],
 
     renderMessagePopoverButton(msg) {
-        if (!msg.attachments.length && !msg.embeds.length && !msg.stickerItems.length) return null;
+        // @ts-ignore - discord-types lags behind discord.
+        const hasAttachmentsInShapshots = msg.messageSnapshots.some(
+            (snapshot: MessageSnapshot) => snapshot?.message.attachments.length
+        );
+
+        if (!msg.attachments.length && !msg.embeds.length && !msg.stickerItems.length && !hasAttachmentsInShapshots) return null;
 
         const isHidden = hiddenMessages.has(msg.id);
 
diff --git a/src/plugins/unsuppressEmbeds/index.tsx b/src/plugins/unsuppressEmbeds/index.tsx
index 16debf711..2df64b72e 100644
--- a/src/plugins/unsuppressEmbeds/index.tsx
+++ b/src/plugins/unsuppressEmbeds/index.tsx
@@ -21,12 +21,18 @@ import { ImageInvisible, ImageVisible } from "@components/Icons";
 import { Devs } from "@utils/constants";
 import definePlugin from "@utils/types";
 import { Constants, Menu, PermissionsBits, PermissionStore, RestAPI, UserStore } from "@webpack/common";
+import { MessageSnapshot } from "@webpack/types";
+
 
 const EMBED_SUPPRESSED = 1 << 2;
 
-const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { channel, message: { author, embeds, flags, id: messageId } }) => {
+const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { channel, message: { author, messageSnapshots, embeds, flags, id: messageId } }) => {
     const isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0;
-    if (!isEmbedSuppressed && !embeds.length) return;
+    const hasEmbedsInSnapshots = messageSnapshots.some(
+        (snapshot: MessageSnapshot) => snapshot?.message.embeds.length
+    );
+
+    if (!isEmbedSuppressed && !embeds.length && !hasEmbedsInSnapshots) return;
 
     const hasEmbedPerms = channel.isPrivate() || !!(PermissionStore.getChannelPermissions({ id: channel.id }) & PermissionsBits.EMBED_LINKS);
     if (author.id === UserStore.getCurrentUser().id && !hasEmbedPerms) return;
diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts
index de1ce1829..cfea5d760 100644
--- a/src/webpack/common/types/utils.d.ts
+++ b/src/webpack/common/types/utils.d.ts
@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { Channel, Guild, GuildMember, User } from "discord-types/general";
+import { Channel, Guild, GuildMember, Message, User } from "discord-types/general";
 import type { ReactNode } from "react";
 import { LiteralUnion } from "type-fest";
 
@@ -133,6 +133,10 @@ export type Permissions = "CREATE_INSTANT_INVITE"
 
 export type PermissionsBits = Record<Permissions, bigint>;
 
+export interface MessageSnapshot {
+    message: Message;
+}
+
 export interface Locale {
     name: string;
     value: string;