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

121 lines
4.4 KiB
TypeScript

// Metro module 4375 (f4376).
import GuildStore from "../../stores/GuildStore";
import RelationshipStore from "../../stores/RelationshipStore";
import UserStore from "../../stores/UserStore";
import { GuildFeatures, MessageAttachmentFlags } from "../../Constants";
import { getThumbnailImage } from "./MediaPostThumbnailUtils";
import { intl, t } from "../../intl/index.native";
import NicknameUtils from "../../utils/NicknameUtils";
import AvatarUtils from "../../utils/AvatarUtils";
import * as _Module1384 from "../../_bundle/Module1384";
import { computeChannelName } from "../channel/useChannelName";
import { parseURLSafely, remainingPathFromDiscordHostMatch } from "../coded_links/findCodedLinks";
import { tryParseChannelPath } from "../links/LinkUtils";
export function getMediaPostEmbedCommonData({ mediaPostEmbedData, guild, parentChannel, postThread, user, selectedGuildId, canAccess = false }) {
if (mediaPostEmbedData == null) {
return null;
}
const thumbnailImage = getThumbnailImage(mediaPostEmbedData.thumbnail);
const shouldShowBlurredThumbnailImage = canAccess ? !canAccess : mediaPostEmbedData.has_media_attachment;
const ctaText = canAccess ? intl.string(t.UsZEBI) : intl.string(t.ReFzYZ);
const authorName = user != null ? NicknameUtils.getName(mediaPostEmbedData.guild_id, mediaPostEmbedData.channel_id, user) : void 0;
let avatarUrl = user == null ? void 0 : user.getAvatarURL(guild?.id, 40);
if (!(avatarUrl != null && selectedGuildId === mediaPostEmbedData.guild_id)) {
avatarUrl = AvatarUtils.getGuildIconURL({
id: mediaPostEmbedData.guild_id,
icon: mediaPostEmbedData.guild_icon,
size: 40,
canAnimate: false
});
}
const thumbnail = mediaPostEmbedData.thumbnail;
const r2 = thumbnail == null;
let shouldContainMediaWithBackground = false;
if (!r2) {
const { height, width } = thumbnail;
shouldContainMediaWithBackground = height != null && width != null && height >= width;
}
if (shouldContainMediaWithBackground) {
shouldContainMediaWithBackground = !shouldShowBlurredThumbnailImage;
}
let r64 = mediaPostEmbedData.thumbnail?.flags;
if (r64 == null) {
r64 = 0;
}
const hasFlag = _Module1384.hasFlag(r64, MessageAttachmentFlags.IS_SPOILER);
let title = mediaPostEmbedData.title;
if (title == null) {
title = "";
}
const coverImageOverlayText = shouldShowBlurredThumbnailImage ? intl.string(t.Yonlia) : void 0;
let guildName = guild?.name;
if (guildName == null) {
guildName = mediaPostEmbedData.guild_name;
}
return {
title,
subtitle: mediaPostEmbedData.description,
ctaText,
coverImage: thumbnailImage,
coverImageOverlayText,
parentChannelId: mediaPostEmbedData.parent_channel_id,
threadId: mediaPostEmbedData.channel_id,
postThread,
messageId: mediaPostEmbedData.message_id,
canAccess,
guildId: mediaPostEmbedData.guild_id,
guildName,
authorId: mediaPostEmbedData?.author_id,
authorName,
channelName: parentChannel != null ? computeChannelName(parentChannel, UserStore, RelationshipStore) : void 0,
avatarUrl,
shouldShowBlurredThumbnailImage,
shouldContainMediaWithBackground,
shouldSpoiler: hasFlag,
obscureAwaitingScan: false,
flags: mediaPostEmbedData.flags,
contentScanVersion: mediaPostEmbedData.content_scan_version
};
}
export function getMediaPostEmbedChannelId(a0) {
const r2 = a0 != null;
let r4 = void 0;
if (r2) {
const r11 = parseURLSafely(a0);
const r12 = r11 != null;
r4 = void 0;
if (r12) {
const r16 = remainingPathFromDiscordHostMatch(r11);
r4 = r16 != null ? tryParseChannelPath(r16) : void 0;
}
}
if (r4 != null) {
let threadId = r4.threadId;
if (threadId == null) {
threadId = r4.channelId;
}
if (threadId === r4.messageId) {
return threadId;
}
}
}
export function getMediaPostEmbedChannelPath(a0) {
if (a0 != null) {
const r9 = parseURLSafely(a0);
if (r9 != null) {
const r13 = remainingPathFromDiscordHostMatch(r9);
if (r13 != null) {
return tryParseChannelPath(r13);
}
}
}
}
export function canUseMediaPostEmbed(a0, a1) {
const guild = GuildStore.getGuild(a0);
if (guild != null && a1 != null) {
const r11 = guild.features.has(GuildFeatures.CREATOR_MONETIZABLE) || guild.features.has(GuildFeatures.CREATOR_MONETIZABLE_PROVISIONAL);
return a1.isMediaChannel() === true && r11;
}
return false;
}