From 36c15d619e99645b0f8c93a9b0fae9ae8a54a2f0 Mon Sep 17 00:00:00 2001 From: Zordan <92729699+zordythezordan@users.noreply.github.com> Date: Wed, 6 Aug 2025 17:26:00 +0300 Subject: [PATCH] HideAttachments: correctly support forwarded Messages (#3587) Co-authored-by: V --- .../discord-types/src/common/messages/Message.d.ts | 3 +++ src/plugins/hideAttachments/index.tsx | 11 ++++------- src/plugins/unsuppressEmbeds/index.tsx | 11 ++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/discord-types/src/common/messages/Message.d.ts b/packages/discord-types/src/common/messages/Message.d.ts index 38010caf..41de8816 100644 --- a/packages/discord-types/src/common/messages/Message.d.ts +++ b/packages/discord-types/src/common/messages/Message.d.ts @@ -83,6 +83,9 @@ export class Message extends DiscordRecord { channel_id: string; message_id: string; } | undefined; + messageSnapshots: { + message: Message; + }[]; nick: unknown; // probably a string nonce: string | undefined; pinned: boolean; diff --git a/src/plugins/hideAttachments/index.tsx b/src/plugins/hideAttachments/index.tsx index 0198a3e1..38213057 100644 --- a/src/plugins/hideAttachments/index.tsx +++ b/src/plugins/hideAttachments/index.tsx @@ -25,7 +25,7 @@ import { ImageInvisible, ImageVisible } from "@components/Icons"; import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; import definePlugin from "@utils/types"; -import { MessageSnapshot } from "@vencord/discord-types"; +import { Message } from "@vencord/discord-types"; import { ChannelStore } from "@webpack/common"; const KEY = "HideAttachments_HiddenIds"; @@ -41,6 +41,8 @@ const saveHiddenMessages = (ids: Set) => set(KEY, ids); migratePluginSettings("HideMedia", "HideAttachments"); +const hasMedia = (msg: Message) => msg.attachments.length > 0 || msg.embeds.length > 0 || msg.stickerItems.length > 0; + export default definePlugin({ name: "HideMedia", description: "Hide attachments and embeds for individual messages via hover button", @@ -56,12 +58,7 @@ export default definePlugin({ }], renderMessagePopoverButton(msg) { - // @ts-expect-error - 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; + if (!hasMedia(msg) && !msg.messageSnapshots.some(s => hasMedia(s.message))) return null; const isHidden = hiddenMessages.has(msg.id); diff --git a/src/plugins/unsuppressEmbeds/index.tsx b/src/plugins/unsuppressEmbeds/index.tsx index e5f8557f..9eecd86d 100644 --- a/src/plugins/unsuppressEmbeds/index.tsx +++ b/src/plugins/unsuppressEmbeds/index.tsx @@ -20,17 +20,18 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/Co import { ImageInvisible, ImageVisible } from "@components/Icons"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; -import { MessageSnapshot } from "@vencord/discord-types"; +import { Channel, Message } from "@vencord/discord-types"; import { Constants, Menu, PermissionsBits, PermissionStore, RestAPI, UserStore } from "@webpack/common"; const EMBED_SUPPRESSED = 1 << 2; -const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { channel, message: { author, messageSnapshots, embeds, flags, id: messageId } }) => { +const messageContextMenuPatch: NavContextMenuPatchCallback = ( + children, + { channel, message: { author, messageSnapshots, embeds, flags, id: messageId } }: { channel: Channel; message: Message; } +) => { const isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0; - const hasEmbedsInSnapshots = messageSnapshots.some( - (snapshot: MessageSnapshot) => snapshot?.message.embeds.length - ); + const hasEmbedsInSnapshots = messageSnapshots.some(s => s.message.embeds.length); if (!isEmbedSuppressed && !embeds.length && !hasEmbedsInSnapshots) return;