HideAttachments: correctly support forwarded Messages (#3587)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
a2253cb4ae
commit
36c15d619e
3 changed files with 13 additions and 12 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue