aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-06-16 19:28:30 +0200
committerV <vendicated@riseup.net>2023-06-16 19:28:30 +0200
commita1fabcdf0aa665c7ee0254c1d7f257e5262a954d (patch)
treea0306e481e98abaf26a4f4ae241861b89bbed83a
parenteaeb60308ee03f2340a1474c7eb75fd29fc49a90 (diff)
downloadVencord-a1fabcdf0aa665c7ee0254c1d7f257e5262a954d.tar.gz
Vencord-a1fabcdf0aa665c7ee0254c1d7f257e5262a954d.tar.bz2
Vencord-a1fabcdf0aa665c7ee0254c1d7f257e5262a954d.zip
UnsuppressEmbeds: Support dms
-rw-r--r--src/plugins/unsuppressEmbeds.tsx (renamed from src/plugins/UnsuppressEmbeds.tsx)50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/plugins/UnsuppressEmbeds.tsx b/src/plugins/unsuppressEmbeds.tsx
index 99735c7..a219607 100644
--- a/src/plugins/UnsuppressEmbeds.tsx
+++ b/src/plugins/unsuppressEmbeds.tsx
@@ -24,34 +24,32 @@ import { Menu, PermissionsBits, PermissionStore, RestAPI, UserStore } from "@web
const EMBED_SUPPRESSED = 1 << 2;
-const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
- const { message: { author, embeds, flags } } = props;
-
+const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { channel, message: { author, embeds, flags, id: messageId } }) => () => {
const isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0;
- const hasEmbedPerms = !!(PermissionStore.getChannelPermissions({ id: props.channel.id }) & PermissionsBits.EMBED_LINKS);
+ if (!isEmbedSuppressed && !embeds.length) return;
+
+ const hasEmbedPerms = channel.isPrivate() || !!(PermissionStore.getChannelPermissions({ id: channel.id }) & PermissionsBits.EMBED_LINKS);
+ if (author.id === UserStore.getCurrentUser().id && !hasEmbedPerms) return;
+
+ const menuGroup = findGroupChildrenByChildId("delete", children);
+ const deleteIndex = menuGroup?.findIndex(i => i?.props?.id === "delete");
+ if (!deleteIndex || !menuGroup) return;
- return () => {
- if (!isEmbedSuppressed && !embeds.length) return;
- if (author.id === UserStore.getCurrentUser().id && !hasEmbedPerms) return;
- const menuGroup = findGroupChildrenByChildId("delete", children);
- const deleteItem = menuGroup?.findIndex(i => i?.props?.id === "delete");
- if (!deleteItem || !menuGroup) return;
- menuGroup.splice(deleteItem - 1, 0, (
- <Menu.MenuItem
- id="unsuppress-embeds"
- key="unsuppress-embeds"
- label={isEmbedSuppressed ? "Unsuppress Embeds" : "Suppress Embeds"}
- color={isEmbedSuppressed ? undefined : "danger"}
- icon={isEmbedSuppressed ? ImageVisible : ImageInvisible}
- action={() => {
- RestAPI.patch({
- url: `/channels/${props.channel.id}/messages/${props.message.id}`,
- body: { flags: isEmbedSuppressed ? flags & ~EMBED_SUPPRESSED : flags | EMBED_SUPPRESSED }
- });
- }}
- />
- ));
- };
+ menuGroup.splice(deleteIndex - 1, 0, (
+ <Menu.MenuItem
+ id="unsuppress-embeds"
+ key="unsuppress-embeds"
+ label={isEmbedSuppressed ? "Unsuppress Embeds" : "Suppress Embeds"}
+ color={isEmbedSuppressed ? undefined : "danger"}
+ icon={isEmbedSuppressed ? ImageVisible : ImageInvisible}
+ action={() =>
+ RestAPI.patch({
+ url: `/channels/${channel.id}/messages/${messageId}`,
+ body: { flags: isEmbedSuppressed ? flags & ~EMBED_SUPPRESSED : flags | EMBED_SUPPRESSED }
+ })
+ }
+ />
+ ));
};
export default definePlugin({