Files
discord-decomp/modules/media_channel/native/createMediaPostPreviewEmbedContent.tsx
T
2026-11-01 12:12:55 +02:00

119 lines
5.5 KiB
TypeScript

// Metro module 12387 (f12388).
import { Image as Image2, processColor } from "react-native";
import DevSettingsStore from "../../devtools/dev_settings/DevSettingsStore";
import ChannelStore from "../../../stores/ChannelStore";
import GuildStore from "../../../stores/GuildStore";
import SelectedGuildStore from "../../../stores/SelectedGuildStore";
import UserStore from "../../../stores/UserStore";
import MediaPostEmbedStore, { FetchState } from "../MediaPostEmbedStore";
import { getMediaPostEmbedChannelId, getMediaPostEmbedCommonData } from "../MediaPostEmbedUtils";
import { canViewChannel } from "../../links/LinkUtils";
import { intl, t } from "../../../intl/index.native";
import { getUserAuthorWithProcessedColor } from "../../messages/native/renderer/system_messages/useAuthorWithProcessedColor";
import formatUsernameOnClick from "../../messages/native/renderer/system_messages/formatUsernameOnClick";
import Module712 from "../../../_bundle/Module712";
import { isAnimatedImageUrl } from "../../messages/MediaFormatTesters";
import Module12388 from "../../../_bundle/Module12388";
import * as _ExplicitMediaRedactionUtils from "../../explicit_media_redaction/ExplicitMediaRedactionUtils";
import { shouldAgeVerifyForExplicitMedia } from "../../explicit_media_redaction/ExplicitMediaRedactionUtils";
import { isVerifiedTeen } from "../../age_assurance/AgeVerificationUtils";
import { getBackgroundImageUrl } from "../MediaPostThumbnailUtils";
export default function createMediaPostPreviewEmbedContent(a0, a1, a2, r10 = false) {
let r148;
const mediaPostEmbedChannelId = getMediaPostEmbedChannelId(a2);
if (mediaPostEmbedChannelId == null) {
return null;
}
if (MediaPostEmbedStore.getEmbedFetchState(mediaPostEmbedChannelId) !== FetchState.FETCHED) {
return null;
}
const media = MediaPostEmbedStore.getMediaPostEmbed(mediaPostEmbedChannelId)?.media;
if (media == null) {
return null;
}
const guild = GuildStore.getGuild(media.guild_id);
const user = UserStore.getUser(media.author_id);
const channel = ChannelStore.getChannel(media.parent_channel_id);
const mediaPostEmbedCommonData = getMediaPostEmbedCommonData({
mediaPostEmbedData: media,
guild,
parentChannel: channel,
postThread: ChannelStore.getChannel(media.channel_id),
user,
selectedGuildId: SelectedGuildStore.getGuildId(),
canAccess: channel != null && canViewChannel(channel)
});
if (mediaPostEmbedCommonData == null) {
return null;
}
const footer = mediaPostEmbedCommonData.authorName != null && (mediaPostEmbedCommonData.channelName != null && user != null) ? intl.formatToParts(t.mCytFr, {
username: mediaPostEmbedCommonData.authorName,
usernameOnClick: formatUsernameOnClick({
userId: user.id,
message: a0,
author: getUserAuthorWithProcessedColor(user, mediaPostEmbedCommonData.postThread),
roleStyle: a1,
messageChannelId: mediaPostEmbedCommonData.threadId
}),
channelName: mediaPostEmbedCommonData.channelName
}) : intl.formatToParts(t.p4VdWJ, {
guildName: mediaPostEmbedCommonData.guildName
});
const ctaButtonColor = mediaPostEmbedCommonData.canAccess === false ? processColor(Module712.unsafe_rawColors.TEAL_430) : processColor(Module712.unsafe_rawColors.BRAND_500);
const r109 = mediaPostEmbedCommonData.coverImage != null && isAnimatedImageUrl(mediaPostEmbedCommonData.coverImage);
if (mediaPostEmbedCommonData.coverImage != null && !mediaPostEmbedCommonData.shouldShowBlurredThumbnailImage && r109 && r10) {
mediaPostEmbedCommonData.coverImage = `${mediaPostEmbedCommonData.coverImage}?format=webp`;
}
if (mediaPostEmbedCommonData.shouldShowBlurredThumbnailImage) {
return {
...mediaPostEmbedCommonData,
blurredCoverImage: Image2.resolveAssetSource(Module12388).uri,
footer,
ctaButtonColor
};
}
const obscureIsOpaque = DevSettingsStore.get("obscure_blur_effect_explicit_content_enabled") || DevSettingsStore.get("obscure_blur_effect_gore_content_enabled") || DevSettingsStore.get("obscure_blur_effect_self_harm_content_enabled");
const isPendingScanVersion = _ExplicitMediaRedactionUtils.isPendingScanVersion(mediaPostEmbedCommonData.contentScanVersion);
const verifyAge = obscureIsOpaque ? shouldAgeVerifyForExplicitMedia() : obscureIsOpaque;
const obscureHideControls = obscureIsOpaque && isVerifiedTeen();
if (mediaPostEmbedCommonData.shouldContainMediaWithBackground && mediaPostEmbedCommonData.coverImage != null) {
const shouldSpoiler2 = mediaPostEmbedCommonData.shouldSpoiler;
let obscure2 = "";
const spoiler2 = shouldSpoiler2 === true ? intl.string(t["F+x38C"]).toUpperCase() : "";
if (obscureIsOpaque) {
obscure2 = intl.string(t.SpxcUR);
}
r148 = {
...mediaPostEmbedCommonData,
footer,
spoiler: spoiler2,
obscure: obscure2,
obscureAwaitingScan: isPendingScanVersion,
verifyAge,
obscureHideControls,
obscureIsOpaque,
ctaButtonColor,
backgroundImage: getBackgroundImageUrl(mediaPostEmbedCommonData.coverImage)
};
} else {
const shouldSpoiler = mediaPostEmbedCommonData.shouldSpoiler;
let obscure = "";
const spoiler = shouldSpoiler === true ? intl.string(t["F+x38C"]).toUpperCase() : "";
if (obscureIsOpaque) {
obscure = intl.string(t.SpxcUR);
}
r148 = {
...mediaPostEmbedCommonData,
footer,
spoiler,
obscure,
obscureAwaitingScan: isPendingScanVersion,
verifyAge,
obscureHideControls,
obscureIsOpaque,
ctaButtonColor
};
}
return r148;
};