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;
|
channel_id: string;
|
||||||
message_id: string;
|
message_id: string;
|
||||||
} | undefined;
|
} | undefined;
|
||||||
|
messageSnapshots: {
|
||||||
|
message: Message;
|
||||||
|
}[];
|
||||||
nick: unknown; // probably a string
|
nick: unknown; // probably a string
|
||||||
nonce: string | undefined;
|
nonce: string | undefined;
|
||||||
pinned: boolean;
|
pinned: boolean;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import { ImageInvisible, ImageVisible } from "@components/Icons";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { MessageSnapshot } from "@vencord/discord-types";
|
import { Message } from "@vencord/discord-types";
|
||||||
import { ChannelStore } from "@webpack/common";
|
import { ChannelStore } from "@webpack/common";
|
||||||
|
|
||||||
const KEY = "HideAttachments_HiddenIds";
|
const KEY = "HideAttachments_HiddenIds";
|
||||||
|
|
@ -41,6 +41,8 @@ const saveHiddenMessages = (ids: Set<string>) => set(KEY, ids);
|
||||||
|
|
||||||
migratePluginSettings("HideMedia", "HideAttachments");
|
migratePluginSettings("HideMedia", "HideAttachments");
|
||||||
|
|
||||||
|
const hasMedia = (msg: Message) => msg.attachments.length > 0 || msg.embeds.length > 0 || msg.stickerItems.length > 0;
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "HideMedia",
|
name: "HideMedia",
|
||||||
description: "Hide attachments and embeds for individual messages via hover button",
|
description: "Hide attachments and embeds for individual messages via hover button",
|
||||||
|
|
@ -56,12 +58,7 @@ export default definePlugin({
|
||||||
}],
|
}],
|
||||||
|
|
||||||
renderMessagePopoverButton(msg) {
|
renderMessagePopoverButton(msg) {
|
||||||
// @ts-expect-error - discord-types lags behind discord.
|
if (!hasMedia(msg) && !msg.messageSnapshots.some(s => hasMedia(s.message))) return null;
|
||||||
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);
|
const isHidden = hiddenMessages.has(msg.id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,18 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/Co
|
||||||
import { ImageInvisible, ImageVisible } from "@components/Icons";
|
import { ImageInvisible, ImageVisible } from "@components/Icons";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
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";
|
import { Constants, Menu, PermissionsBits, PermissionStore, RestAPI, UserStore } from "@webpack/common";
|
||||||
|
|
||||||
|
|
||||||
const EMBED_SUPPRESSED = 1 << 2;
|
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 isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0;
|
||||||
const hasEmbedsInSnapshots = messageSnapshots.some(
|
const hasEmbedsInSnapshots = messageSnapshots.some(s => s.message.embeds.length);
|
||||||
(snapshot: MessageSnapshot) => snapshot?.message.embeds.length
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isEmbedSuppressed && !embeds.length && !hasEmbedsInSnapshots) return;
|
if (!isEmbedSuppressed && !embeds.length && !hasEmbedsInSnapshots) return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue