Skip to content

Commit

Permalink
Add option to blur message link embeds when the linked message origin…
Browse files Browse the repository at this point in the history
…ates from an age restricted channel
  • Loading branch information
lolsuffocate committed Oct 4, 2024
1 parent 1e01f85 commit 116eac4
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions src/plugins/messageLinkEmbeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ import {
ChannelStore,
Constants,
GuildStore,
i18n,
Icons,
IconUtils,
MessageStore,
Parser,
PermissionsBits,
PermissionStore,
RestAPI,
Text,
UserStore
UserStore,
useState
} from "@webpack/common";
import { Channel, Message } from "discord-types/general";

Expand All @@ -53,6 +56,8 @@ const ChannelMessage = findComponentByCodeLazy("childrenExecutedCommand:", ".hid

const SearchResultClasses = findByPropsLazy("message", "searchResult");
const EmbedClasses = findByPropsLazy("embedAuthorIcon", "embedAuthor", "embedAuthor");
const SpoilerClasses = findByPropsLazy("explicitContentWarning", "explicitContentWarningText", "spoilerContent");
const MosaicClasses = findByPropsLazy("obscured", "hiddenMosaicItem", "hiddenExplicit");

const MessageDisplayCompact = getUserSettingLazy("textAndImages", "messageDisplayCompact")!;

Expand Down Expand Up @@ -97,6 +102,11 @@ const settings = definePluginSettings({
}
]
},
blurNsfw: {
description: "Blur embeds from age restricted channels",
type: OptionType.BOOLEAN,
default: true
},
listMode: {
description: "Whether to use ID list as blacklist or whitelist",
type: OptionType.SELECT,
Expand Down Expand Up @@ -283,6 +293,55 @@ function getChannelLabelAndIconUrl(channel: Channel) {
return ["Server", IconUtils.getGuildIconURL(GuildStore.getGuild(channel.guild_id))];
}

function Spoiler(props: { children: JSX.Element }) : JSX.Element {
const [visible, setVisible] = useState(false);
const {
explicitContentWarning,
explicitContentWarningText,
spoilerContent,
spoilerContainer,
hidden,
spoilerInnerContainer,
obscureButtonContainer,
obscureHoverButton
} = SpoilerClasses;
const { obscured, hiddenMosaicItem, hiddenExplicit } = MosaicClasses;

return (
<div
aria-label={!visible && i18n.Messages.EXPLICIT_CONTENT_WARNING_TOOLTIP}
aria-expanded={visible}
className={classes(spoilerContainer, !visible && classes(hidden, spoilerContent))}
role={visible ? "presentation" : "button"}
tabIndex={visible ? -1 : 0}
>
{!visible &&
<div className={explicitContentWarning}>
<Icons.ImageWarningIcon size="lg" color="white"/>
<Text variant="text-sm/normal" color="always-white"
className={classes(explicitContentWarningText)}>
{i18n.Messages.EXPLICIT_CONTENT_WARNING}
</Text>
</div>
}
<div
aria-hidden={!visible}
className={classes(spoilerInnerContainer, !visible && classes(obscured, hiddenMosaicItem, hiddenExplicit))}
>
{props.children}
</div>
<div className={obscureButtonContainer}>
<Icons.Clickable onClick={() => setVisible(!visible)}
aria-label={i18n.Messages.EXPLICIT_CONTENT_BUTTON_TOOLTIP}
className={obscureHoverButton}>
{visible ? <Icons.EyeIcon size="md" color="currentColor"/> :
<Icons.EyeSlashIcon size="md" color="currentColor"/>}
</Icons.Clickable>
</div>
</div>
);
}

function ChannelMessageEmbedAccessory({ message, channel }: MessageEmbedProps): JSX.Element | null {
const compact = MessageDisplayCompact.useSetting();

Expand Down Expand Up @@ -314,6 +373,7 @@ function ChannelMessageEmbedAccessory({ message, channel }: MessageEmbedProps):
/>
</div>
)}
{...(settings.store.blurNsfw && channel.isNSFW() && { obscureReason: "explicit_content" })}
/>
);
}
Expand All @@ -326,7 +386,7 @@ function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null {

const [channelLabel, iconUrl] = getChannelLabelAndIconUrl(channel);

return <AutoModEmbed
const embed = <AutoModEmbed
channel={channel}
childrenAccessories={
<Text color="text-muted" variant="text-xs/medium" tag="span" className={`${EmbedClasses.embedAuthor} ${EmbedClasses.embedMargin}`}>
Expand Down Expand Up @@ -361,6 +421,12 @@ function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null {
message={message}
_messageEmbed="automod"
/>;

if (settings.store.blurNsfw && channel.isNSFW()) {
return <Spoiler>{embed}</Spoiler>;
}

return embed;
}

export default definePlugin({
Expand Down

0 comments on commit 116eac4

Please sign in to comment.