/* 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] */ import SnowflakeUtils from '../../utils/SnowflakeUtils.tsx'; /* Metro dependency 21 */ import ChannelStore from '../../stores/ChannelStore.tsx'; /* Metro dependency 1379 */ import UserStore from '../../stores/UserStore.tsx'; /* Metro dependency 1878 */ import MessageStore from '../../stores/MessageStore.tsx'; /* Metro dependency 4814 */ import ThreadMessageStore from '../threads/ThreadMessageStore.tsx'; /* Metro dependency 6898 */ import * as FileImportTrackerModule from '../../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */ import * as ReactModule from '../../by-id/module-00031-React.js'; /* Metro dependency 31 */ import * as ConstantsModule from '../../Constants.tsx'; /* Metro dependency 661 */ import * as ServerModule from '../../flow/Server.tsx'; /* Metro dependency 1909 */ import * as UserSettingsModule from '../user_settings/UserSettings.tsx'; /* Metro dependency 3829 */ import * as MediaFormatTestersModule from '../messages/MediaFormatTesters.tsx'; /* Metro dependency 4631 */ 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 isValidImageAttachment_750762 = isValidImageAttachment_75076; const isValidVideoAttachment_750772 = isValidVideoAttachment_75077; const isMediaAttachment2 = isMediaAttachment; const getForumPostMedia2 = getForumPostMedia; const useForumPostComponentsMedia2 = 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}); (FileImportTrackerModule).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 = isValidImageAttachment_750762; exports.isValidVideoAttachment = isValidVideoAttachment_750772; exports.isMediaAttachment = isMediaAttachment2; exports.ForumPostMediaTypes = {EMBED: 'embed', ATTACHMENT: 'attachment', COMPONENT: 'component'}; exports.getForumPostMedia = getForumPostMedia2; exports.useForumPostComponentsMedia = useForumPostComponentsMedia2; 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 = MediaFormatTestersModule; 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 _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 object; 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 = (MediaFormatTestersModule).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(); object = {}; object.type = env1_10.ATTACHMENT; object.src = r13; object.width = width; object.height = height; object.spoiler = spoiler != null && spoiler; object.flags = flags; object.contentScanVersion = content_scan_version; object.alt = description; object.isVideo = isVideoFile2; object.isThumbnail = r4; object.attachmentId = a0.id; object.mediaIndex = a1; moduleValue3 = require(1391) /* metro dependency 1391: FlagUtils */; hasFlag = moduleValue3.hasFlag; flags = a0.flags; object.srcIsAnimated = Reflect.apply(hasFlag, moduleValue3, [flags ?? 0, MessageAttachmentFlags.IS_ANIMATED]); } else { object = {}; object.type = env1_10.ATTACHMENT; object.src = r13; object.width = width; object.height = height; object.spoiler = spoiler != null && spoiler; object.flags = flags; object.contentScanVersion = content_scan_version; object.alt = description; object.isVideo = isVideoFile2; object.isThumbnail = r4; object.attachmentId = a0.id; object.mediaIndex = a1; moduleValue3 = require(1391) /* metro dependency 1391: FlagUtils */; hasFlag = moduleValue3.hasFlag; flags = a0.flags; object.srcIsAnimated = Reflect.apply(hasFlag, moduleValue3, [flags ?? 0, MessageAttachmentFlags.IS_ANIMATED]); } return object; } } 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 = (UserSettingsModule).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 = (UserSettingsModule).InlineEmbedMedia; const value3 = InlineEmbedMedia.useSetting(); const RenderEmbeds = (UserSettingsModule).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 _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 object; 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; } object = {}; value = environment.__proto__; object.type = env1_10.EMBED; object.src = proxyURL == null || proxyURL === '' ? url : proxyURL; object.height = height; object.width = width; object.spoiler = require; object.flags = a0.flags; object.contentScanVersion = a0.contentScanVersion; object.isVideo = r3; object.mediaIndex = a1; moduleValue = require(1391) /* metro dependency 1391: FlagUtils */; object.srcIsAnimated = moduleValue.hasFlag(flags ?? 0, MessageEmbedMediaFlags.IS_ANIMATED); return object; } } } } 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 = (UserSettingsModule).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 _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 = (ServerModule).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 _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); } } } 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 object; 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 { object = {}; object.type = env0_10.COMPONENT; object.src = a0.proxyUrl; height = a0.height; value5 = 0; r7 = value4 != height ? height : value5; object.height = r7; width = a0.width; r7 = value4 != width ? width : value5; object.width = r7; object.spoiler = a1; contentScanMetadata = a0.contentScanMetadata; object.contentScanVersion = value4 == contentScanMetadata ? value2 : contentScanMetadata.version; object.flags = value5; value = require(1391) /* metro dependency 1391: FlagUtils */; object.srcIsAnimated = value.hasFlag(a0.flags, (require(4630) /* metro dependency 4630: MediaTypes */).UnfurledMediaItemFlags.IS_ANIMATED); object.isVideo = unfurledMediaItemType === 'VIDEO'; object.mediaIndex = value5; object.srcUnfurledMediaItem = a0; r0 = object; } 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 ReactModule.useMemo(_fun75091, [a1, useForumPostMediaProperties(a0, value !== undefined ? value : false)]); 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 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 messageStoreBinding = MessageStore; const getMessage = messageStoreBinding.getMessage; const id = channel.id; const value3 = undefined; const defaultImport = SnowflakeUtils; const value4 = Reflect.apply(getMessage, messageStoreBinding, [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 _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 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 _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 object = {}; object.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; } object.containsGif = r1; return object; } } } global.__d(_fun75075, 9587, [31, 6898, 1379, 4814, 1878, 661, 4631, 3829, 1391, 1471, 1360, 4627, 1909, 4630, 21, 2]) /* metro module 9587, dependencies: [31, 6898, 1379, 4814, 1878, 661, 4631, 3829, 1391, 1471, 1360, 4627, 1909, 4630, 21, 2] */;