HideAttachments: correctly support forwarded Messages (#3587)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Zordan 2025-08-06 17:26:00 +03:00 committed by GitHub
parent a2253cb4ae
commit 36c15d619e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 12 deletions

View file

@ -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<string>) => 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);

View file

@ -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;