316 lines
12 KiB
TypeScript
316 lines
12 KiB
TypeScript
// Metro module 7884 (f7885).
|
|
import { processColor } from "react-native";
|
|
import { MessageEmbedTypes } from "../../../../Constants";
|
|
import { sanitizeMediaDimension } from "./sanitizeMediaDimension";
|
|
import RowGeneratorUtils from "./RowGeneratorUtils";
|
|
import { isServerShopArticleEmbed, isSocialLayerStorefrontArticleEmbed, getEffectiveVideoProvider } from "../../../../utils/EmbedUtils";
|
|
import { isContentInventoryFallbackEmbed } from "../../../interaction_components/content_inventory_entry/utils";
|
|
import { getIsEligibleForSocialLayerStorefrontMobilePurchasing } from "../../../slayer_storefront/experiments/SocialLayerStorefrontMobilePurchasingExperiment";
|
|
import { isIOS } from "../../../../utils/PlatformUtils";
|
|
import * as _EmbedUtils2 from "./EmbedUtils";
|
|
import { isWebPlayerVideoUrl } from "../../MediaFormatTesters";
|
|
import { parseEmbedTitleMarkupWithoutLinks, parseEmbedTitleMarkup, parseEmbedDescriptionMarkup } from "./MarkupParsers";
|
|
import { calendarFormat } from "../../../../utils/DateUtils";
|
|
import { getMediaObscuredReasonFromBitmask, isMediaScanPending } from "../../../explicit_media_redaction/ObscuredMediaUtils";
|
|
import { ObscuredMediaTypes } from "../../../explicit_media_redaction/ExplicitMediaRedactionModels";
|
|
import { isVerifiedTeen } from "../../../age_assurance/AgeVerificationUtils";
|
|
import * as _index_native from "../../../../intl/index.native";
|
|
import { intl } from "../../../../intl/index.native";
|
|
export default function transformEmbeds({ embeds, channelId, gifAutoPlay, hasSpoilerEmbeds, ignoreEmbedDescriptionCache, shouldInlineEmbedMedia, colors, showListsAndHeaders, showMaskedLinks, themedBackgroundColor, enabledContentHarmTypeFlags, authorIsBot, showContentInventoryEntryFallbackEmbed, shouldAgeVerify, transformComponents }) {
|
|
const renderEmbedMedia2 = function renderEmbedMedia(a0) {
|
|
const url = a0.url;
|
|
let proxyURL = a0.proxyURL;
|
|
const { width, height } = a0;
|
|
const r3 = {
|
|
...a0,
|
|
width: sanitizeMediaDimension(width),
|
|
height: sanitizeMediaDimension(height),
|
|
proxyURL: proxyURL != null ? RowGeneratorUtils.getImageSrc(proxyURL, width, height, !gifAutoPlay) : proxyURL
|
|
};
|
|
if (proxyURL == null) {
|
|
proxyURL = url;
|
|
}
|
|
r3.url = RowGeneratorUtils.getImageSrc(proxyURL, width, height, !gifAutoPlay);
|
|
return r3;
|
|
};
|
|
return embeds.flatMap((embed) => {
|
|
let r128, footer, images;
|
|
if (embed.type !== MessageEmbedTypes.POST_PREVIEW && embed.type !== MessageEmbedTypes.GIFT && embed.type !== MessageEmbedTypes.SAFETY_POLICY_NOTICE && embed.type !== MessageEmbedTypes.SAFETY_SYSTEM_NOTIFICATION && embed.type !== MessageEmbedTypes.AGE_VERIFICATION_SYSTEM_NOTIFICATION) {
|
|
L8: {
|
|
if (embed.type === MessageEmbedTypes.COMPONENTS) {
|
|
if (embed.components != null && embed.components.length !== 0) {
|
|
break L8;
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
if (isServerShopArticleEmbed(embed)) {
|
|
return [];
|
|
}
|
|
if (embed.type === MessageEmbedTypes.VOICE_CHANNEL) {
|
|
return [];
|
|
}
|
|
if (isContentInventoryFallbackEmbed(embed) && !showContentInventoryEntryFallbackEmbed) {
|
|
return [];
|
|
}
|
|
if (isSocialLayerStorefrontArticleEmbed(embed) && getIsEligibleForSocialLayerStorefrontMobilePurchasing({
|
|
location: "transformEmbeds"
|
|
})) {
|
|
return [];
|
|
}
|
|
let r68 = null;
|
|
if (shouldInlineEmbedMedia) {
|
|
const r1 = embed.thumbnail != null;
|
|
r68 = null;
|
|
if (r1) {
|
|
const thumbnail = embed.thumbnail;
|
|
const url = thumbnail.url;
|
|
let proxyURL = thumbnail.proxyURL;
|
|
const { width, height } = thumbnail;
|
|
const r70 = {
|
|
...thumbnail,
|
|
width: sanitizeMediaDimension(width),
|
|
height: sanitizeMediaDimension(height),
|
|
proxyURL: proxyURL != null ? RowGeneratorUtils.getImageSrc(proxyURL, width, height, !gifAutoPlay) : proxyURL
|
|
};
|
|
if (proxyURL == null) {
|
|
proxyURL = url;
|
|
}
|
|
r70.url = RowGeneratorUtils.getImageSrc(proxyURL, width, height, !gifAutoPlay);
|
|
r68 = r70;
|
|
}
|
|
}
|
|
let image = shouldInlineEmbedMedia ? embed.image != null ? renderEmbedMedia2(embed.image) : null : null;
|
|
if (shouldInlineEmbedMedia && embed.images != null) {
|
|
images = embed.images.map(renderEmbedMedia2);
|
|
} else {
|
|
const r4 = image == null || !isIOS();
|
|
images = (r4 ? !r4 : embed.thumbnail == null) ? image != null ? [image] : null : null;
|
|
}
|
|
let thumbnail2 = r68;
|
|
if (thumbnail2 != null) {
|
|
const video = embed.video;
|
|
thumbnail2 = r68;
|
|
if (video != null) {
|
|
const r118 = embed.type === MessageEmbedTypes.VIDEO || embed.type === MessageEmbedTypes.RICH || embed.type === MessageEmbedTypes.ARTICLE;
|
|
L56: {
|
|
if (!(embed.type === MessageEmbedTypes.GIFV && gifAutoPlay) && !(r118 && embed.video.proxyURL != null)) {
|
|
r128 = r68;
|
|
if (!r118) {
|
|
break L56;
|
|
}
|
|
const proxyURL2 = embed.video.proxyURL;
|
|
r128 = r68;
|
|
if (proxyURL2 != null) {
|
|
break L56;
|
|
}
|
|
const shouldPlayVideoInline = _EmbedUtils2.shouldPlayVideoInline(getEffectiveVideoProvider(embed.provider?.name, embed.video.url));
|
|
r128 = r68;
|
|
if (!shouldPlayVideoInline) {
|
|
break L56;
|
|
}
|
|
r128 = {
|
|
...r68,
|
|
showPlayButton: true
|
|
};
|
|
} else {
|
|
const video2 = embed.video;
|
|
const { proxyURL: proxyURL3, url: url2 } = video2;
|
|
r128 = {
|
|
...r68,
|
|
gifv: embed.type === MessageEmbedTypes.GIFV,
|
|
videoUrl: proxyURL3 != null ? proxyURL3 !== "" ? proxyURL3 : url2 : url2
|
|
};
|
|
}
|
|
}
|
|
const r163 = embed.type !== MessageEmbedTypes.GIFV || gifAutoPlay;
|
|
let r164 = r128;
|
|
if (!r163) {
|
|
const video3 = embed.video;
|
|
const { proxyURL: proxyURL4, url: url3 } = video3;
|
|
r164 = {
|
|
...r128,
|
|
gifvUrlForPortal: proxyURL4 != null ? proxyURL4 !== "" ? proxyURL4 : url3 : url3
|
|
};
|
|
}
|
|
const video4 = embed.video;
|
|
const { proxyURL: proxyURL5, url: url4 } = video4;
|
|
thumbnail2 = isWebPlayerVideoUrl(proxyURL5 != null ? proxyURL5 !== "" ? proxyURL5 : url4 : url4) ? {
|
|
...r164,
|
|
inlinePlaybackDisabled: true
|
|
} : r164;
|
|
}
|
|
}
|
|
let embedBorderLeftColor = colors.embedBorderLeftColor;
|
|
if (embed.color != null && embed.color !== "") {
|
|
embedBorderLeftColor = processColor(embed.color);
|
|
}
|
|
const r201 = embed.url != null && embed.url !== "" ? parseEmbedTitleMarkupWithoutLinks : parseEmbedTitleMarkup;
|
|
let title = embed.type === MessageEmbedTypes.RICH && embed.rawTitle != null ? r201(embed.rawTitle, channelId) : embed.rawTitle;
|
|
const type = embed.type;
|
|
let description = MessageEmbedTypes.IMAGE !== type ? MessageEmbedTypes.VIDEO !== type ? MessageEmbedTypes.GIFV !== type ? MessageEmbedTypes.RICH === type ? embed.rawDescription != null ? parseEmbedDescriptionMarkup({
|
|
description: embed.rawDescription,
|
|
channelId,
|
|
isField: false,
|
|
ignoreCache: ignoreEmbedDescriptionCache,
|
|
showListsAndHeaders,
|
|
showMaskedLinks
|
|
}) : void 0 : embed.rawDescription : void 0 : void 0 : void 0;
|
|
let fields = embed.fields;
|
|
if (fields == null) {
|
|
fields = [];
|
|
}
|
|
let fields2 = fields.map((field) => ({
|
|
...field,
|
|
name: field.rawName == null ? null : parseEmbedTitleMarkup(field.rawName, channelId),
|
|
value: field.rawValue == null ? null : parseEmbedDescriptionMarkup({
|
|
description: field.rawValue,
|
|
channelId,
|
|
isField: true,
|
|
ignoreCache: ignoreEmbedDescriptionCache,
|
|
replaceMap: {
|
|
"\t": ""
|
|
},
|
|
showListsAndHeaders,
|
|
showMaskedLinks
|
|
})
|
|
}));
|
|
const content = embed.timestamp != null ? calendarFormat(embed.timestamp) : null;
|
|
if (embed.footer != null) {
|
|
const text = embed.footer.text;
|
|
const r246 = {
|
|
...embed.footer,
|
|
content: content != null ? `${text} | ${content}` : text
|
|
};
|
|
const r256 = embed.footer.iconProxyURL != null && embed.footer.iconProxyURL !== "" ? embed.footer.iconProxyURL : embed.footer.iconURL;
|
|
footer = r246;
|
|
if (r256 != null) {
|
|
r246.iconURL = RowGeneratorUtils.getImageSrc(r256, 16, 16, !gifAutoPlay);
|
|
footer = r246;
|
|
}
|
|
} else {
|
|
footer = content != null ? {
|
|
content,
|
|
text: ""
|
|
} : void 0;
|
|
}
|
|
const r271 = embed.author != null;
|
|
let author = void 0;
|
|
if (r271) {
|
|
const r279 = embed.author.iconProxyURL != null && embed.author.iconProxyURL !== "" ? embed.author.iconProxyURL : embed.author.iconURL;
|
|
author = r279 != null ? {
|
|
...embed.author,
|
|
iconURL: RowGeneratorUtils.getImageSrc(r279, 16, 16, !gifAutoPlay)
|
|
} : embed.author;
|
|
}
|
|
const type2 = embed.type;
|
|
const COMPONENTS = MessageEmbedTypes.COMPONENTS;
|
|
let components2 = void 0;
|
|
if (type2 === COMPONENTS) {
|
|
const components = embed.components;
|
|
components2 = transformComponents(hasSpoilerEmbeds ? components.map((component) => ({
|
|
...component,
|
|
spoiler: true
|
|
})) : components);
|
|
}
|
|
const mediaObscuredReasonFromBitmask = getMediaObscuredReasonFromBitmask({
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: embed
|
|
}, enabledContentHarmTypeFlags);
|
|
const r318 = authorIsBot ? !authorIsBot : isMediaScanPending({
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: embed
|
|
}, enabledContentHarmTypeFlags);
|
|
const obscureIsOpaque = mediaObscuredReasonFromBitmask.length > 0;
|
|
const obscureHideControls = obscureIsOpaque ? isVerifiedTeen() : obscureIsOpaque;
|
|
let id = embed.id;
|
|
if (id == null) {
|
|
id = "";
|
|
}
|
|
let type3 = embed.type;
|
|
if (type3 == null) {
|
|
type3 = void 0;
|
|
}
|
|
let obscureAwaitingScan = "";
|
|
const spoiler = hasSpoilerEmbeds ? intl.string(_index_native.t["F+x38C"]).toUpperCase() : "";
|
|
const obscure = obscureIsOpaque ? intl.string(_index_native.t.SpxcUR) : "";
|
|
if (r318) {
|
|
obscureAwaitingScan = intl.string(_index_native.t.MRdR7z);
|
|
}
|
|
const verifyAge = obscureIsOpaque && shouldAgeVerify;
|
|
let provider = embed.provider;
|
|
if (provider == null) {
|
|
provider = void 0;
|
|
}
|
|
if (title == null) {
|
|
title = void 0;
|
|
}
|
|
let url5 = embed.url;
|
|
if (url5 == null) {
|
|
url5 = void 0;
|
|
}
|
|
if (description == null) {
|
|
description = void 0;
|
|
}
|
|
if (thumbnail2 == null) {
|
|
thumbnail2 = void 0;
|
|
}
|
|
if (image == null) {
|
|
image = void 0;
|
|
}
|
|
if (images == null) {
|
|
images = void 0;
|
|
}
|
|
if (fields2 == null) {
|
|
fields2 = void 0;
|
|
}
|
|
if (components2 == null) {
|
|
components2 = void 0;
|
|
}
|
|
let video5 = embed.video;
|
|
if (video5 == null) {
|
|
video5 = void 0;
|
|
}
|
|
let referenceId = embed.referenceId;
|
|
if (referenceId == null) {
|
|
referenceId = void 0;
|
|
}
|
|
let backgroundColor = themedBackgroundColor;
|
|
if (themedBackgroundColor == null) {
|
|
backgroundColor = void 0;
|
|
}
|
|
return {
|
|
id,
|
|
type: type3,
|
|
spoiler,
|
|
obscure,
|
|
obscureAwaitingScan,
|
|
verifyAge,
|
|
obscureHideControls,
|
|
obscureIsOpaque,
|
|
provider,
|
|
author,
|
|
rawTitle: embed.rawTitle,
|
|
title,
|
|
url: url5,
|
|
rawDescription: embed.rawDescription,
|
|
description,
|
|
thumbnail: thumbnail2,
|
|
image,
|
|
images,
|
|
fields: fields2,
|
|
components: components2,
|
|
footer,
|
|
video: video5,
|
|
borderLeftColor: embedBorderLeftColor,
|
|
providerColor: colors.embedProviderColor,
|
|
headerTextColor: colors.embedHeaderTextColor,
|
|
bodyTextColor: colors.embedBodyTextColor,
|
|
referenceId,
|
|
backgroundColor
|
|
};
|
|
}
|
|
return [];
|
|
});
|
|
};
|