UnsuppressEmbeds: Support dms
This commit is contained in:
parent
eaeb60308e
commit
a1fabcdf0a
1 changed files with 24 additions and 26 deletions
|
@ -24,34 +24,32 @@ import { Menu, PermissionsBits, PermissionStore, RestAPI, UserStore } from "@web
|
||||||
|
|
||||||
const EMBED_SUPPRESSED = 1 << 2;
|
const EMBED_SUPPRESSED = 1 << 2;
|
||||||
|
|
||||||
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
|
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { channel, message: { author, embeds, flags, id: messageId } }) => () => {
|
||||||
const { message: { author, embeds, flags } } = props;
|
|
||||||
|
|
||||||
const isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0;
|
const isEmbedSuppressed = (flags & EMBED_SUPPRESSED) !== 0;
|
||||||
const hasEmbedPerms = !!(PermissionStore.getChannelPermissions({ id: props.channel.id }) & PermissionsBits.EMBED_LINKS);
|
if (!isEmbedSuppressed && !embeds.length) return;
|
||||||
|
|
||||||
return () => {
|
const hasEmbedPerms = channel.isPrivate() || !!(PermissionStore.getChannelPermissions({ id: channel.id }) & PermissionsBits.EMBED_LINKS);
|
||||||
if (!isEmbedSuppressed && !embeds.length) return;
|
if (author.id === UserStore.getCurrentUser().id && !hasEmbedPerms) return;
|
||||||
if (author.id === UserStore.getCurrentUser().id && !hasEmbedPerms) return;
|
|
||||||
const menuGroup = findGroupChildrenByChildId("delete", children);
|
const menuGroup = findGroupChildrenByChildId("delete", children);
|
||||||
const deleteItem = menuGroup?.findIndex(i => i?.props?.id === "delete");
|
const deleteIndex = menuGroup?.findIndex(i => i?.props?.id === "delete");
|
||||||
if (!deleteItem || !menuGroup) return;
|
if (!deleteIndex || !menuGroup) return;
|
||||||
menuGroup.splice(deleteItem - 1, 0, (
|
|
||||||
<Menu.MenuItem
|
menuGroup.splice(deleteIndex - 1, 0, (
|
||||||
id="unsuppress-embeds"
|
<Menu.MenuItem
|
||||||
key="unsuppress-embeds"
|
id="unsuppress-embeds"
|
||||||
label={isEmbedSuppressed ? "Unsuppress Embeds" : "Suppress Embeds"}
|
key="unsuppress-embeds"
|
||||||
color={isEmbedSuppressed ? undefined : "danger"}
|
label={isEmbedSuppressed ? "Unsuppress Embeds" : "Suppress Embeds"}
|
||||||
icon={isEmbedSuppressed ? ImageVisible : ImageInvisible}
|
color={isEmbedSuppressed ? undefined : "danger"}
|
||||||
action={() => {
|
icon={isEmbedSuppressed ? ImageVisible : ImageInvisible}
|
||||||
RestAPI.patch({
|
action={() =>
|
||||||
url: `/channels/${props.channel.id}/messages/${props.message.id}`,
|
RestAPI.patch({
|
||||||
body: { flags: isEmbedSuppressed ? flags & ~EMBED_SUPPRESSED : flags | EMBED_SUPPRESSED }
|
url: `/channels/${channel.id}/messages/${messageId}`,
|
||||||
});
|
body: { flags: isEmbedSuppressed ? flags & ~EMBED_SUPPRESSED : flags | EMBED_SUPPRESSED }
|
||||||
}}
|
})
|
||||||
/>
|
}
|
||||||
));
|
/>
|
||||||
};
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
Loading…
Reference in a new issue