// Metro module 9672 (f9673). import _asyncToGenerator from "../../../_bundle/_asyncToGenerator"; import "../../user_settings/UnsyncedUserSettingsStore"; import ChannelStore from "../../../stores/ChannelStore"; import { DraftType } from "../../../stores/DraftStore"; import SelectedChannelStore from "../../../stores/SelectedChannelStore"; import UploadAttachmentStore from "../../../stores/UploadAttachmentStore"; import { MediaKeyboardTarget } from "./MediaKeyboardConstants"; import { AnalyticEvents, ChatInputComponentViewedTypes, ComponentActions, AnalyticsSections, AnalyticsObjects, AnalyticsObjectTypes, AnalyticsPages, MAX_UPLOAD_COUNT } from "../../../Constants"; import { NativePermissionTypes } from "../../native_permissions/NativePermissionConstants"; import { UploadOrigin, UploadPlatform } from "../../../lib/uploader/Upload"; import UploadAttachmentActionCreators from "../../../actions/UploadAttachmentActionCreators"; import { doesImageMatchUpload } from "../../../lib/uploader/UploadUtils"; import { getFileFromUploadItem } from "../../../utils/native/UploadUtils"; import NativePermissionUtils from "../../native_permissions/NativePermissionUtils"; import AnalyticsUtils from "../../../utils/AnalyticsUtils"; import { isIOS } from "../../../utils/PlatformUtils"; import { getSystemVersionMajor } from "../../../utils/native/DeviceUtils"; import { hideMediaKeyboardActionSheet, presentLimitedLibraryPicker, showMediaKeyboardActionSheet } from "./showMediaKeyboardActionSheet"; import { ComponentDispatch } from "../../../utils/ComponentDispatchUtils"; import { openGiftModal } from "../../premium/native/utils/openGiftModal"; import { setAccessibilityFocus } from "../../a11y/native/setAccessibilityFocus.android"; import { navigateToThreadCreation } from "../../threads/native/navigateToThreadCreation"; import { handleDocumentSelection } from "../../../utils/native/FilePickerUtils"; import Module12 from "../../../_bundle/Module12"; import { HermesBuiltin } from "../../../_hermes/prelude"; function $mk83052($env) { return (a0) => { const r4 = $env.$parent; let env26507 = { $parent: r4 }; env26507[0] = a0; const r7 = $env[0]; return r7 != null && a0.uri != null && a0.uri !== "" && r4[8].findUpload(r7, r4[6].ChannelMessage, (a0) => { const r1 = env26507.$parent; return (0, r1[0])(r1[2][11]).doesImageMatchUpload(env26507[0], a0); }) == null; }; } function $mk83053($env) { return (a0) => ({ ...a0, origin: $env[1] }); } function $mk83054($env) { return (a0) => { if (a0) { const r11 = $env; const r5 = $env.$parent; const r3 = r5[1]; const r6 = r5[2]; const r8 = r3(r6[14]); const CHAT_INPUT_COMPONENT_VIEWED = r5[11].CHAT_INPUT_COMPONENT_VIEWED; const r15 = r11[0]; r8.track(CHAT_INPUT_COMPONENT_VIEWED, { type: r5[16].CAMERA, channel_id: r15.id, guild_id: r15.guild_id }); (0, r11[2])(); r3(r6[15]).launchCamera({ mediaType: "mixed", includeBase64: false, quality: (0, r5[0])(r6[12]).getImageCompressionQuality(), videoQuality: "high", saveToPhotos: r5[4].saveCameraUploadsToDevice, skipProcessing: true }, $mk106644(r11)); } }; } function $mk83055($env) { return (a0) => { if (a0) { const r5 = $env; let env26508 = { $parent: $env }; const r6 = $env.$parent; const r4 = r6[1]; const r3 = r6[2]; const r11 = r4(r3[14]); const CHAT_INPUT_COMPONENT_VIEWED = r6[11].CHAT_INPUT_COMPONENT_VIEWED; const r17 = r5[0]; r11.track(CHAT_INPUT_COMPONENT_VIEWED, { type: r6[16].NATIVE_MEDIA_PICKER, channel_id: r17.id, guild_id: r17.guild_id }); (0, r5[4])(); const uploads = r6[8].getUploads(r17.id, r5[1]); env26508[0] = uploads; const r27 = r5[3]; let r28 = uploads; if (r27 != null) { const r31 = uploads.filter($mk106645(r5)); env26508[0] = r31; r28 = r31; } const r32 = r5[2]; const r44 = { mediaType: "any", includeBase64: false, selectionLimit: r32 > 1 ? r32 - ((0, r6[0])(r3[16]).isIOS() ? r28.filter($mk106646(r6)).length : r28.length) : 1, selections: r28.map((item) => item.id), includeExtra: !(0, r6[0])(r3[16]).isIOS(), skipProcessing: true }; r4(r3[15]).launchImageLibrary(r44, (a0) => { let r23; let env30131; L15: { const r1 = env26508.$parent; env30131 = { $parent: r1 }; env30131[0] = a0; (0, r1[5])(); if (!a0.didCancel && a0.errorCode == null) { const r6 = env26508[0]; if (r6.length === 0) { if (a0.assets == null) { break L15; } if (a0.assets.length === 0) { break L15; } } if (a0.replaceSelection) { r6.forEach((item) => { const r2 = env30131.$parent.$parent; let env31509 = { $parent: r2 }; env31509[0] = item; const origin = item.origin; const r8 = r2[0]; const r4 = r2[2]; let r13 = origin !== r8(r4[9]).UploadOrigin.IMAGE_PICKER; if (!r13) { const assets = env30131[0].assets; r13 = assets == null ? void 0 : assets.some((asset) => { const r1 = env31509.$parent; return (0, r1[0])(r1[2][11]).doesImageMatchUpload(asset, env31509[0]); }); } if (!r13) { (0, r2[1])(r4[10]).remove(env30131.$parent[0].id, item.id, r2[6].ChannelMessage); } }); } const r36 = []; let r39 = a0.assets[Symbol.iterator](); const next = r39.next; const r41 = env26508.$parent.$parent; while (true) { const r42 = r39 === void 0 ? void 0 : (r23 = next.call(r39)).done ? r39 = void 0 : r23.value; if (r39 === void 0) { if (!(r36.length > 0)) { break; } (0, r1[6])(r36); break; } try { if (r42.uri != null) { r36.push({ id: r42.id, uri: r42.uri, originalUri: r42.uri, mimeType: r42.mimeType, width: r42.width, height: r42.height, filename: r42.fileName, playableDuration: r42.duration, platform: (0, r41[0])(r41[2][9]).UploadPlatform.REACT_NATIVE }); } } catch (r61) { if (r39 !== void 0 && typeof r39.return === "function") { try { r39.return(); } catch {} } throw r61; } } } } }); } }; } function $mk106644($env) { return (a0) => { let fileName2; const r3 = $env; if (a0.didCancel) { (0, r3[3])(); } else if (a0.errorCode == null && a0.assets != null && a0.assets.length > 0) { const r17 = a0.assets[0]; if (r17 != null && r17.uri != null && r17.height != null && r17.width != null) { let type2 = r17.type; if (type2 == null) { const fileName = r17.fileName; const r11 = fileName == null ? void 0 : fileName.split(".").pop(); type2 = r11 != null ? r17.fileType != null ? `${r17.fileType}/${r11}`.toLowerCase() : "image/jpeg" : "image/jpeg"; } if (r17.fileName != null && r17.fileName !== "") { fileName2 = r17.fileName; } else { let r47 = type2.split("/")[1]; if (r47 == null) { r47 = "jpeg"; } fileName2 = `camera_upload.${r47}`; } const r54 = $env.$parent; const r55 = r54[0]; const r56 = r54[2]; (0, r3[4])([{ id: r17.id, uri: r17.uri, originalUri: r17.uri, width: r17.width, height: r17.height, filename: fileName2, playableDuration: r17.duration, platform: r55(r56[9]).UploadPlatform.REACT_NATIVE, createdUsingInAppCamera: true, mimeType: type2 }]); (0, r54[1])(r56[14]).track(r54[11].IN_APP_CAMERA_USED, { camera_view: r54[10].FULLY_EXPANDED, camera_preview_type: r3[1] }); (0, r3[3])(); } } }; } function $mk106645($env) { return (a0) => $env[3].includes(a0.id); } function $mk106646($env) { return (a0) => { const r1 = $env; return a0.origin !== (0, r1[0])(r1[2][9]).UploadOrigin.IMAGE_PICKER; }; } function $mk106653($env) { return (a0) => { let env30134; const r4 = $env.$parent.$parent; const id = $env.$parent[0].id; const r6 = $env[0]; const r2 = env30134 = { $parent: r4 }; env30134[0] = id; env30134[1] = r6; const r8 = r4[0]; const r12 = r4[2]; if (r6 !== r8(r12[9]).UploadOrigin.FILE_ATTACHMENT) { const files = a0.filter($mk83052(r2)).map($mk83053(r2)); (0, r4[1])(r12[10]).addFiles({ files, channelId: id, draftType: r4[6].ChannelMessage }); } else { (0, r4[1])(r12[10]).addFiles({ files: a0, channelId: id, draftType: r4[6].ChannelMessage }); } }; } function $mk115524($env) { return function() { let env31510 = { $parent: $env }; env31510[0] = (0, _asyncToGenerator)(function*(c31991_0) { let env32130; let c31991_5 = env31510; const r10 = env32130 = {}; env32130[0] = c31991_0; env32130[1] = void 0; env32130[2] = void 0; env32130[3] = void 0; env32130[4] = void 0; const uri = c31991_0.uri; env32130[1] = uri; const r28 = env31510.$parent.$parent; const r32 = (0, r28[0])(r28[2][12]); const name = c31991_0.name; if (name == null) { name = void 0; } const r41 = yield r32.getImageDimensionsIfMissing(uri, void 0, void 0, name); env32130[2] = r41; env32130[3] = env32130[2].width; env32130[4] = env32130[2].height; const r55 = c31991_5.$parent.$parent; const r64 = { id: (0, r55[1])(r55[2][24]).uniqueId(env32130[1]), uri: env32130[1], originalUri: env32130[1], filename: null, mimeType: null, channelId: null, platform: null, origin: null, width: null, height: null }; const name3 = env32130[0].name; let name2 = name3; if (name3 == null) { name2 = env32130[1].split("/").at(-1); } r64.filename = name2; const type = env32130[0].type; if (type == null) { type = void 0; } r64.mimeType = type; r64.channelId = c31991_5.$parent[0].id; const r88 = c31991_5.$parent.$parent; r64.platform = (0, r88[0])(r88[2][9]).UploadPlatform.REACT_NATIVE; r64.origin = (0, r88[0])(r88[2][9]).UploadOrigin.FILE_ATTACHMENT; r64.width = env32130[3]; r64.height = env32130[4]; return r64; }); return function() { return env31510[0].apply(this, arguments); }; }; } let handleAttachFile, handleSelectKeyboardItem, showSimpleMediaKeyboard; let $mk106651 = function() { return () => hideMediaKeyboardActionSheet(); }; let env6398 = {}; export async function handleLimitedPickerDialog(c26509_0) { let c30132_0 = c26509_0.onDismissKeyboard; let c30132_1 = c26509_0.onRestoreKeyboard; await void 0; (0, c30132_0)(); await presentLimitedLibraryPicker(); (0, c30132_1)(); } handleAttachFile = async function handleAttachFile(c26510_0) { let env30133; const r31 = env6398; let c26510_2 = r31; const r10 = env30133 = { $parent: r31 }; let c26510_1 = r10; env30133[0] = void 0; env30133[1] = void 0; env30133[2] = void 0; env30133[3] = void 0; env30133[4] = void 0; env30133[5] = void 0; env30133[0] = c26510_0.channel; env30133[1] = c26510_0.uploadLimit; env30133[2] = c26510_0.extensions; env30133[3] = c26510_0.onDismissKeyboard; env30133[4] = c26510_0.onRestoreKeyboard; env30133[5] = c26510_0.onSelectFiles; env30133[6] = void 0; env30133[7] = void 0; await void 0; (0, env30133[3])(); AnalyticsUtils.track(AnalyticEvents.CHAT_INPUT_COMPONENT_VIEWED, { type: ChatInputComponentViewedTypes.ATTACH_FILE, channel_id: env30133[0].id, guild_id: env30133[0].guild_id }); env30133[6] = await handleDocumentSelection({ pickMultiple: env30133[1] > 1, extensions: env30133[2] }); (0, env30133[4])(); if (env30133[6] != null && !(env30133[6].length < 1)) { env30133[7] = await Promise.all(Array.from(env30133[6]).map($mk115524(c26510_1)())); (0, env30133[5])(env30133[7]); } }; handleSelectKeyboardItem = function handleSelectKeyboardItem(a0, a1, a2, a3) { const image = a1.node.image; if (a2) { const r51 = UploadAttachmentStore.findUpload(a0, DraftType.ChannelMessage, (a0) => doesImageMatchUpload(image, a0)); if (r51 != null) { UploadAttachmentActionCreators.remove(a0, r51.id, DraftType.ChannelMessage); } } else { const image2 = a1.node.image; let id = a1.node.id; if (id == null) { id = image2.uri; } UploadAttachmentActionCreators.addFile({ channelId: a0, file: { id, origin: UploadOrigin.IMAGE_PICKER, uri: image2.uri, originalUri: image2.uri, mimeType: image2.mimeType, width: image2.width, height: image2.height, filename: image2.filename, playableDuration: image2.playableDuration, platform: UploadPlatform.REACT_NATIVE, ...a3 != null && { createdUsingInAppCamera: a3 } }, draftType: DraftType.ChannelMessage }); } }; export function animatedIndexThreshold(a0, a1) { return a0.get().length === 1 ? a1 - 1 : a1 * (a0.get().length - 1); } animatedIndexThreshold.__closure = {}; animatedIndexThreshold.__workletHash = 97398083076; animatedIndexThreshold.__initData = { code: "function animatedIndexThreshold_MediaKeyboardUtilsTsx1(animatedSnapPoints,thresholdPercent){return animatedSnapPoints.get().length===1?thresholdPercent-1:thresholdPercent*(animatedSnapPoints.get().length-1);}" }; export function addImagesFromPicker(a0, a1, a2) { let env17393; const r2 = env17393 = { $parent: env6398 }; env17393[0] = a0; env17393[1] = a2; if (a2 !== UploadOrigin.FILE_ATTACHMENT) { UploadAttachmentActionCreators.addFiles({ files: a1.filter($mk83052(r2)).map($mk83053(r2)), channelId: a0, draftType: DraftType.ChannelMessage }); } else { UploadAttachmentActionCreators.addFiles({ files: a1, channelId: a0, draftType: DraftType.ChannelMessage }); } } export function addAttachmentForCommand(a0, a1, a2, a3, a4) { const option = a3.option; const filename = getFileFromUploadItem(a2).filename; if (a3.target === MediaKeyboardTarget.COMMAND) { const applicationCommandManager = a1.current.getApplicationCommandManager(); if (applicationCommandManager != null) { applicationCommandManager.insertOrJumpCommandOption(option, void 0, false, { displayText: filename, preferred: true }); } } const target = a3.target; const draftType = MediaKeyboardTarget.CHAT === target ? DraftType.ChannelMessage : MediaKeyboardTarget.COMMAND === target ? DraftType.SlashCommand : MediaKeyboardTarget.APP_LAUNCHER === target ? DraftType.ApplicationLauncherCommand : MediaKeyboardTarget.INTERACTION_MODAL === target ? DraftType.InteractionModal : void 0; UploadAttachmentActionCreators.remove(a0, a3.option.name, draftType); UploadAttachmentActionCreators.addFile({ channelId: a0, file: { ...a2, origin: a4, id: option.name, filename }, draftType, allowOptimization: false }); } export function handleCameraDialog(a0) { let env17394; const r1 = env17394 = { $parent: env6398 }; env17394[0] = a0.channel; env17394[1] = a0.previewType; env17394[2] = a0.onDismissKeyboard; env17394[3] = a0.onRestoreKeyboard; env17394[4] = a0.onSelectFiles; NativePermissionUtils.requestPermission(NativePermissionTypes.CAMERA).then($mk83054(r1)); } export function handleViewAllDialog(a0) { let env17395; const r3 = env17395 = { $parent: env6398 }; env17395[0] = a0.channel; env17395[1] = a0.draftType; env17395[2] = a0.uploadLimit; env17395[3] = a0.includedUploadIds; env17395[4] = a0.onDismissKeyboard; env17395[5] = a0.onRestoreKeyboard; env17395[6] = a0.onSelectFiles; (isIOS() && getSystemVersionMajor() >= 14 ? Promise.resolve(true) : NativePermissionUtils.requestPermission(NativePermissionTypes.PHOTOS)).then($mk83055(r3)); } export function handleSelectGift(a0, a1, a2) { const ref = a2; const channelId = SelectedChannelStore.getChannelId(); a1.current.closeCustomKeyboard(); const channel = ChannelStore.getChannel(channelId); ComponentDispatch.dispatch(ComponentActions.MEDIA_KEYBOARD_GIFT_SELECTED); const analyticsLocation = { section: AnalyticsSections.CHANNEL_TEXT_AREA, object: AnalyticsObjects.BUTTON_ICON, objectType: AnalyticsObjectTypes.GIFT, page: channel?.guild_id != null ? AnalyticsPages.GUILD_CHANNEL : AnalyticsPages.DM_CHANNEL }; AnalyticsUtils.track(AnalyticEvents.CHAT_INPUT_COMPONENT_VIEWED, { type: ChatInputComponentViewedTypes.NITRO_GIFTING, channel_id: channel?.id, guild_id: channel?.guild_id }); openGiftModal({ recipientUserId: channel != null ? channel.isDM() ? channel.getRecipientId() : void 0 : void 0, analyticsLocation, analyticsLocations: a0, navigationParams: { presentation: "card" }, onDismiss: a2?.current != null ? () => setAccessibilityFocus({ ref }) : void 0 }); } export function handleSelectThread(a0, a1) { AnalyticsUtils.track(AnalyticEvents.CHAT_INPUT_COMPONENT_VIEWED, { type: ChatInputComponentViewedTypes.START_THREAD, channel_id: a0.id, guild_id: a0?.guild_id }); if (a0 != null) { a1.current.openSystemKeyboard(); if (isIOS()) { a1.current.blur(); } navigateToThreadCreation(a0, "Plus Button"); } } export { handleAttachFile }; export function mediaNodeToUploadItem(a0, a1) { const image2 = a0.node.image; let id = a0.node.id; if (id == null) { id = image2.uri; } return { id, origin: UploadOrigin.IMAGE_PICKER, uri: image2.uri, originalUri: image2.uri, mimeType: image2.mimeType, width: image2.width, height: image2.height, filename: image2.filename, playableDuration: image2.playableDuration, platform: UploadPlatform.REACT_NATIVE, ...a1 != null && { createdUsingInAppCamera: a1 } }; } export function cropResultToUploadItem(a0) { const r10 = a0.path.startsWith("file://"); const path = a0.path; const uri = r10 ? path : `file://${path}`; const filename = a0.path.split("/").pop(); return { id: Module12.uniqueId(a0.path), uri, originalUri: uri, mimeType: a0.mime, width: a0.width, height: a0.height, filename, platform: UploadPlatform.REACT_NATIVE }; } export { handleSelectKeyboardItem }; showSimpleMediaKeyboard = function showSimpleMediaKeyboard(a0) { let $mk106652 = function() { return () => { showSimpleMediaKeyboard(env17398[0]); }; }; let env17398 = { $parent: env6398 }; env17398[0] = a0; const CHAT = MediaKeyboardTarget.CHAT; const draftType = MediaKeyboardTarget.CHAT === CHAT ? DraftType.ChannelMessage : MediaKeyboardTarget.COMMAND === CHAT ? DraftType.SlashCommand : MediaKeyboardTarget.APP_LAUNCHER === CHAT ? DraftType.ApplicationLauncherCommand : MediaKeyboardTarget.INTERACTION_MODAL === CHAT ? DraftType.InteractionModal : void 0; env17398[1] = draftType; showMediaKeyboardActionSheet({ channel: a0, draftType, uploadLimit: MAX_UPLOAD_COUNT, disableWhenReachedLimit: true, onAttachPress: () => { let env26511; const r1 = {}; const FILE_ATTACHMENT = UploadOrigin.FILE_ATTACHMENT; const r14 = env26511 = { $parent: env17398 }; env26511[0] = FILE_ATTACHMENT; HermesBuiltin.copyDataProperties(r1, { channel: env17398[0], uploadLimit: MAX_UPLOAD_COUNT, onDismissKeyboard: $mk106651(), onRestoreKeyboard: $mk106652(), onSelectFiles: $mk106653(r14) }); handleAttachFile(r1); }, onPressCamera: (a0) => { let env26512; let env26513; const r2 = env6398; const r4 = {}; const IMAGE_PICKER = UploadOrigin.IMAGE_PICKER; const r13 = env26512 = { $parent: env17398 }; env26512[0] = IMAGE_PICKER; HermesBuiltin.copyDataProperties(r4, { channel: env17398[0], uploadLimit: MAX_UPLOAD_COUNT, onDismissKeyboard: $mk106651(), onRestoreKeyboard: $mk106652(), onSelectFiles: $mk106653(r13) }); r4.previewType = a0; const r21 = env26513 = { $parent: r2 }; env26513[0] = void 0; env26513[1] = void 0; env26513[2] = void 0; env26513[3] = void 0; env26513[4] = void 0; env26513[0] = r4.channel; env26513[1] = r4.previewType; env26513[2] = r4.onDismissKeyboard; env26513[3] = r4.onRestoreKeyboard; env26513[4] = r4.onSelectFiles; NativePermissionUtils.requestPermission(NativePermissionTypes.CAMERA).then($mk83054(r21)); }, onPressItem: ({ channelId, item, isIncluded }) => { hideMediaKeyboardActionSheet(); handleSelectKeyboardItem(channelId, item, isIncluded); }, onViewAll: () => { let env26514; let env26515; const r4 = env6398; const r6 = {}; const IMAGE_PICKER = UploadOrigin.IMAGE_PICKER; const r9 = env26514 = { $parent: env17398 }; env26514[0] = IMAGE_PICKER; HermesBuiltin.copyDataProperties(r6, { channel: env17398[0], uploadLimit: MAX_UPLOAD_COUNT, onDismissKeyboard: $mk106651(), onRestoreKeyboard: $mk106652(), onSelectFiles: $mk106653(r9) }); r6.draftType = env17398[1]; const r23 = env26515 = { $parent: r4 }; env26515[0] = void 0; env26515[1] = void 0; env26515[2] = void 0; env26515[3] = void 0; env26515[4] = void 0; env26515[5] = void 0; env26515[6] = void 0; env26515[0] = r6.channel; env26515[1] = r6.draftType; env26515[2] = r6.uploadLimit; env26515[3] = r6.includedUploadIds; env26515[4] = r6.onDismissKeyboard; env26515[5] = r6.onRestoreKeyboard; env26515[6] = r6.onSelectFiles; (isIOS() && getSystemVersionMajor() >= 14 ? Promise.resolve(true) : NativePermissionUtils.requestPermission(NativePermissionTypes.PHOTOS)).then($mk83055(r23)); }, onManageLimited: () => { handleLimitedPickerDialog({ onDismissKeyboard: hideMediaKeyboardActionSheet, onRestoreKeyboard: () => { showSimpleMediaKeyboard(env17398[0]); } }); }, onClose: hideMediaKeyboardActionSheet, onBack: hideMediaKeyboardActionSheet }); }; export { showSimpleMediaKeyboard }; export function getMediaKeyboardDraftType(a0) { if (MediaKeyboardTarget.CHAT === a0) { return DraftType.ChannelMessage; } if (MediaKeyboardTarget.COMMAND === a0) { return DraftType.SlashCommand; } if (MediaKeyboardTarget.APP_LAUNCHER === a0) { return DraftType.ApplicationLauncherCommand; } if (MediaKeyboardTarget.INTERACTION_MODAL === a0) { return DraftType.InteractionModal; } }