/* Metro module 9587; source: modules/forums/ForumPostMediaUtils.tsx; dependencies: [31, 6898, 1379, 4814, 1878, 661, 4631, 3829, 1391, 1471, 1360, 4627, 1909, 4630, 21, 2] */ function _fun75075(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#75075, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:6, offset: 0x01da1bc0, size: 463 bytes, params: 8, frame: 25 const env0_0 = require; const closure = isValidImageAttachment_75076; const closure2 = isValidVideoAttachment_75077; const closure3 = isMediaAttachment; const closure4 = getForumPostMedia; const closure5 = useForumPostComponentsMedia; const closure6 = function(a0, a1) { var r6; var value2 = useForumPostMedia(a0); var items = []; arraySpread(items, useForumPostComponentsMedia(a0), arraySpread(items, useForumPostEmbeds(a0, a1), arraySpread(items, value2, 0, r6), useForumPostEmbeds), useForumPostEmbeds); return items; }; const Object = global.Object; Object.defineProperty(exports, '__esModule', {value: true}); const env0_3 = importAll(31) /* metro dependency 31 */; const threadMessageStore = importDefault(6898) /* metro dependency 6898: ThreadMessageStore */; const channelStore = importDefault(1379) /* metro dependency 1379: ChannelStore */; const messageStore = importDefault(4814) /* metro dependency 4814: MessageStore */; const userStore = importDefault(1878) /* metro dependency 1878: UserStore */; const constantsModule = require(661) /* metro dependency 661: Constants */; const env0_8 = constantsModule.MessageAttachmentFlags; const env0_9 = constantsModule.MessageEmbedMediaFlags; (require(2) /* metro dependency 2 */).fileFinishedImporting('modules/forums/ForumPostMediaUtils.tsx'); exports.getEmbedColor = function(a0, a1) { var color; if (a0 != null) { if (a0.embeds[0] != null) { color = a0.embeds[0].color; return color == null ? a1 ? undefined : color : color.toLowerCase() === '#ffffff' || a1 ? undefined : color; } } }; exports.isValidImageAttachment = closure; exports.isValidVideoAttachment = closure2; exports.isMediaAttachment = closure3; exports.ForumPostMediaTypes = {EMBED: 'embed', ATTACHMENT: 'attachment', COMPONENT: 'component'}; exports.getForumPostMedia = closure4; exports.useForumPostComponentsMedia = closure5; exports.useForumPostMediaThumbnail = useForumPostMediaThumbnail; exports.useForumPostMediaProperties = closure6; exports.useFindFirstMediaProperties = useFindFirstMediaProperties; exports.useFirstMediaIsEmbed = useFirstMediaIsEmbed; exports.shouldShowAddMediaToOriginalPostModal = shouldShowAddMediaToOriginalPostModal; exports.messageContainsGifOrVideo = function(a0) { return a0.reduce(_fun75099, {'containsVideo': false, 'containsGif': false}); }; } function isValidImageAttachment_75076(a0) { // fn#75076, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:210, offset: 0x01da1d8f, size: 99 bytes, params: 2, frame: 15 if (a0 == null) { return false; } const filename = a0.filename; const height = a0.height; const width = a0.width; let value = require(4631) /* metro dependency 4631: MediaFormatTesters */; value = value.isImageFile(filename); let r0 = value && height != null && height > 0; r0 = r0 && width != null && width > 0; return r0; } function isValidVideoAttachment_75077(a0) { // fn#75077, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:361, offset: 0x01da1df2, size: 79 bytes, params: 2, frame: 15 var r1; var r0; let value = a0 != null; if (value) { value = a0 != null; if (value) { value = require(4631) /* metro dependency 4631: MediaFormatTesters */; value = value.isVideoFile(a0.filename); r1 = value; } else { r1 = value; } r1 = r1 && a0.proxy_url != null; r0 = r1; } else { r0 = value; } return r0; } function isMediaAttachment(a0) { // fn#75078, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:474, offset: 0x01da1e41, size: 31 bytes, params: 2, frame: 13 return isValidImageAttachment_75076(a0) || isValidVideoAttachment_75077(a0); } function getForumPostMedia(a0) { // fn#75079, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:662, offset: 0x01da1e60, size: 251 bytes, params: 2, frame: 15 var r3; const value = a1; const value2 = undefined; if (value !== value2 ? value : (require(3829) /* metro dependency 3829: UserSettings */).InlineAttachmentMedia.getSetting()) { r3 = (a0 == null || a0.messageSnapshots[0] == null ? value2 : a0.messageSnapshots[0].moderatorReport) != null ? a0 == null || a0.messageSnapshots[0] == null ? value2 : a0.messageSnapshots[0].message.attachments : a0 == null ? value2 : a0.attachments; return a0 == null || r3 == null ? [] : r3.filter(isMediaAttachment).map(_fun75080).filter((require(1360) /* metro dependency 1360: GlobalUtils */).isNotNullish); } return []; } function useForumPostMedia(a0) { // fn#75081, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:1632, offset: 0x01da20ef, size: 56 bytes, params: 2, frame: 13 const getForumPostMediaBinding = getForumPostMedia; const InlineAttachmentMedia = (require(3829) /* metro dependency 3829: UserSettings */).InlineAttachmentMedia; return getForumPostMediaBinding(a0, InlineAttachmentMedia.useSetting()); } function useForumPostEmbeds(a0, a1) { // fn#75082, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:1733, offset: 0x01da2127, size: 236 bytes, params: 3, frame: 19 var r0; var value5; const env0_0 = a1; const value2 = undefined; const InlineEmbedMedia = (require(3829) /* metro dependency 3829: UserSettings */).InlineEmbedMedia; const value3 = InlineEmbedMedia.useSetting(); const RenderEmbeds = (require(3829) /* metro dependency 3829: UserSettings */).RenderEmbeds; const value4 = RenderEmbeds.useSetting(); if (a0 == null) { return []; } const property = a0.messageSnapshots[0]; const r4 = (property == null ? value2 : property.moderatorReport) != null ? a0.messageSnapshots[0] == null ? value2 : a0.messageSnapshots[0].message.embeds : a0.embeds; if (value3) { if (value4) { if (r4 != null) { value5 = r4.map(_fun75083); r0 = value5.filter((require(1360) /* metro dependency 1360: GlobalUtils */).isNotNullish); } else { r0 = []; } } else { r0 = []; } } else { r0 = []; } return r0; } function useForumPostComponentsMedia(a0) { // fn#75084, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:2484, offset: 0x01da233f, size: 186 bytes, params: 2, frame: 17 var r0; var Array; var from; var value; const InlineEmbedMedia = (require(3829) /* metro dependency 3829: UserSettings */).InlineEmbedMedia; const value2 = InlineEmbedMedia.useSetting(); if (a0 == null) { return []; } const components = a0.components; if (value2) { if (components != null) { Array = global.Array; from = Array.from; value = require(4627) /* metro dependency 4627: InteractionComponentUtils */; value = value.flattenComponents(components); value = Reflect.apply(from, Array, [value.values()]); value = value.flatMap(_fun75085); value = value.filter((require(1360) /* metro dependency 1360: GlobalUtils */).isNotNullish); r0 = value; } else { r0 = []; } } else { r0 = []; } return r0; } function unfurledMediaToForumPostMediaAttachment(a0, a1) { // fn#75087, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:3029, offset: 0x01da24ba, size: 254 bytes, params: 3, frame: 21 var r7; var r0; var object2; var height; var value5; var width; var contentScanMetadata; var value; const value2 = undefined; const unfurledMediaItemType = (require(4630) /* metro dependency 4630: MediaTypes */).getUnfurledMediaItemType(a0); const value4 = null; if (unfurledMediaItemType === 'INVALID') { r0 = value4; } else { object2 = {}; object2.type = env0_10.COMPONENT; object2.src = a0.proxyUrl; height = a0.height; value5 = 0; r7 = value4 != height ? height : value5; object2.height = r7; width = a0.width; r7 = value4 != width ? width : value5; object2.width = r7; object2.spoiler = a1; contentScanMetadata = a0.contentScanMetadata; object2.contentScanVersion = value4 == contentScanMetadata ? value2 : contentScanMetadata.version; object2.flags = value5; value = require(1391) /* metro dependency 1391: FlagUtils */; object2.srcIsAnimated = value.hasFlag(a0.flags, (require(4630) /* metro dependency 4630: MediaTypes */).UnfurledMediaItemFlags.IS_ANIMATED); object2.isVideo = unfurledMediaItemType === 'VIDEO'; object2.mediaIndex = value5; object2.srcUnfurledMediaItem = a0; r0 = object2; } return r0; } function useForumPostMediaThumbnail(a0, a1) { // fn#75090, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:4122, offset: 0x01da264f, size: 80 bytes, params: 3, frame: 16 const value = a2; const env0_0 = a1; return env0_3.useMemo(_fun75091, [a1, useForumPostMediaProperties(a0, value !== undefined ? value : false)]); } function useFindFirstMediaProperties(a0, a1) { // fn#75093, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:4434, offset: 0x01da26ff, size: 77 bytes, params: 3, frame: 15 const value2 = useForumPostMedia(a0); const value3 = useForumPostEmbeds(a0, a1); const value = useForumPostComponentsMedia(a0); const property = value2[0]; const value4 = null; let r1 = value4 != property ? property : value3[0]; r1 = value4 == r1 ? value[0] : r1; return value4 != r1 ? r1 : value4; } function useFirstMediaIsEmbed(a0, a1) { // fn#75094, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:4655, offset: 0x01da274c, size: 75 bytes, params: 3, frame: 15 return useForumPostMedia(a0)[0] == null && useForumPostComponentsMedia(a0)[0] == null && useForumPostEmbeds(a0, a1)[0] != null; } function shouldShowAddMediaToOriginalPostModal(a0, a1) { // fn#75095, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:4859, offset: 0x01da2797, size: 280 bytes, params: 3, frame: 21 var r1; var r0; var ownerId; var currentUser; const channel = ChannelStore.getChannel(a1); if (channel == null) { return false; } const getMessage = MessageStore.getMessage; const id = channel.id; const value3 = undefined; const defaultImport = importDefault(21) /* metro dependency 21: SnowflakeUtils */; const value4 = Reflect.apply(getMessage, MessageStore, [id, defaultImport.castChannelIdAsMessageId(channel.id)]); const value5 = value4 != null; if (value5) { r1 = a0.length > 0 && a0.find(function(a0) { return a0.isImage || a0.isVideo; }) != null; r1 = r1 && channel.isForumPost(); if (r1) { ownerId = channel.ownerId; currentUser = UserStore.getCurrentUser(); r1 = ownerId === (currentUser == null ? value3 : currentUser.id); } r1 = r1 && ThreadMessageStore.getCount(channel.id) === 0; r1 = r1 && (value4.attachments.length === 0 || value4.attachments.find(_fun75097) == null); r0 = r1; } else { r0 = value5; } return r0; } function messageContainsGifOrVideo(a0) { // fn#75098, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:5327, offset: 0x01da28e2, size: 36 bytes, params: 2, frame: 13 return a0.reduce(_fun75099, {'containsVideo': false, 'containsGif': false}); } function _fun75080(a0, a1) { // fn#75080, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:999, offset: 0x01da1f5b, size: 404 bytes, params: 3, frame: 27 var r4; var moduleValue2; var hasFlag; var value3; var object2; var moduleValue3; const proxy_url = a0.proxy_url; const url = a0.url; const description = a0.description; const spoiler = a0.spoiler; let flags = a0.flags; const width = a0.width; const height = a0.height; const filename = a0.filename; const content_scan_version = a0.content_scan_version; if (width == null) { return null; } if (height == null) { return null; } const isVideoFile2 = (require(4631) /* metro dependency 4631: MediaFormatTesters */).isVideoFile(filename); const value2 = a0.flags != null; if (value2) { moduleValue2 = require(1391) /* metro dependency 1391: FlagUtils */; r4 = moduleValue2.hasFlag(a0.flags, MessageAttachmentFlags.IS_THUMBNAIL); } else { r4 = value2; } let r13 = proxy_url ?? url; if (isVideoFile2) { value3 = (importDefault(1471) /* metro dependency 1471: URLUtils */).toURLSafe(proxy_url); if (value3 == null) { return null; } value3.searchParams.append('format', 'webp'); r13 = value3.toString(); object2 = {}; object2.type = env1_10.ATTACHMENT; object2.src = r13; object2.width = width; object2.height = height; object2.spoiler = spoiler != null && spoiler; object2.flags = flags; object2.contentScanVersion = content_scan_version; object2.alt = description; object2.isVideo = isVideoFile2; object2.isThumbnail = r4; object2.attachmentId = a0.id; object2.mediaIndex = a1; moduleValue3 = require(1391) /* metro dependency 1391: FlagUtils */; hasFlag = moduleValue3.hasFlag; flags = a0.flags; object2.srcIsAnimated = Reflect.apply(hasFlag, moduleValue3, [flags ?? 0, MessageAttachmentFlags.IS_ANIMATED]); } else { object2 = {}; object2.type = env1_10.ATTACHMENT; object2.src = r13; object2.width = width; object2.height = height; object2.spoiler = spoiler != null && spoiler; object2.flags = flags; object2.contentScanVersion = content_scan_version; object2.alt = description; object2.isVideo = isVideoFile2; object2.isThumbnail = r4; object2.attachmentId = a0.id; object2.mediaIndex = a1; moduleValue3 = require(1391) /* metro dependency 1391: FlagUtils */; hasFlag = moduleValue3.hasFlag; flags = a0.flags; object2.srcIsAnimated = Reflect.apply(hasFlag, moduleValue3, [flags ?? 0, MessageAttachmentFlags.IS_ANIMATED]); } return object2; } function _fun75083(a0, a1) { // fn#75083, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:2034, offset: 0x01da2213, size: 300 bytes, params: 3, frame: 21 var r3; var height; var proxyURL; var width; var flags; var object2; var moduleValue; let r0 = a0.image ?? a0.thumbnail; let value = r0 == null; r0 = value && a0.images != null ? a0.images[0] : r0; if (r0 != null) { var url = r0.url; if (url != null) { height = r0.height; proxyURL = r0.proxyURL; url = r0.url; width = r0.width; flags = r0.flags; value = proxyURL != null; if (value) { value = environment.__proto__; value = require(4631) /* metro dependency 4631: MediaFormatTesters */; value = value.isVideoUrl(proxyURL); r3 = value; } else { r3 = value; } object2 = {}; value = environment.__proto__; object2.type = env1_10.EMBED; object2.src = proxyURL == null || proxyURL === '' ? url : proxyURL; object2.height = height; object2.width = width; object2.spoiler = require; object2.flags = a0.flags; object2.contentScanVersion = a0.contentScanVersion; object2.isVideo = r3; object2.mediaIndex = a1; moduleValue = require(1391) /* metro dependency 1391: FlagUtils */; object2.srcIsAnimated = moduleValue.hasFlag(flags ?? 0, MessageEmbedMediaFlags.IS_ANIMATED); return object2; } } } function _fun75085(a0) { // fn#75085, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:2685, offset: 0x01da23f9, size: 149 bytes, params: 2, frame: 16 var environment; var unfurledMediaToForumPostMediaAttachmentBinding; var media; var spoiler; const type = a0.type; const value = environment.__proto__; const ComponentType = (require(1909) /* metro dependency 1909: Server */).ComponentType; const THUMBNAIL = ComponentType.THUMBNAIL; if (THUMBNAIL === type) { unfurledMediaToForumPostMediaAttachmentBinding = unfurledMediaToForumPostMediaAttachment; media = a0.media; spoiler = a0.spoiler; return unfurledMediaToForumPostMediaAttachmentBinding(media, spoiler != null && spoiler); } const MEDIA_GALLERY = ComponentType.MEDIA_GALLERY; if (MEDIA_GALLERY === type) { return a0.items.map(_fun75086); } return null; } function _fun75091() { // fn#75091, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:4225, offset: 0x01da269f, size: 85 bytes, params: 1, frame: 13 var value2; if (require == null) { return []; } const isMediaChannel2 = require.isMediaChannel(); const binding = env0_1; if (isMediaChannel2) { value2 = binding.find(function(a0) { return a0.isThumbnail; }); return value2 != null ? [value2] : env0_1; } return binding; } function _fun75097(a0) { // fn#75097, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:5238, offset: 0x01da28c3, size: 31 bytes, params: 2, frame: 13 const value = environment.__proto__; return isValidImageAttachment_75076(a0) || isValidVideoAttachment_75077(a0); } function _fun75099({containsVideo, containsGif}, a1) { // fn#75099, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:5382, offset: 0x01da2906, size: 86 bytes, params: 3, frame: 14 var r1; var value; const object2 = {}; object2.containsVideo = containsVideo || a1.isVideo; if (containsGif) { r1 = containsGif; } else { value = environment.__proto__; value = require(4631) /* metro dependency 4631: MediaFormatTesters */; value = value.isAnimatedImageUrl(a1.src); r1 = value; } object2.containsGif = r1; return object2; } function _fun75086({media, spoiler}) { // fn#75086, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9773:2889, offset: 0x01da248e, size: 44 bytes, params: 2, frame: 14 const value = environment.__proto__.__proto__; return unfurledMediaToForumPostMediaAttachment(media, spoiler != null && spoiler); }