Files
discord-decomp/modules/media_keyboard/native/components/MediaKeyboard.tsx
T
2026-11-01 12:12:55 +02:00

369 lines
16 KiB
TypeScript

// Metro module 15589 (f15590).
import * as Module19 from "react";
import { useEffect, useRef, useMemo, useCallback } from "react";
import { DraftType } from "../../../../stores/DraftStore";
import UploadAttachmentStore from "../../../../stores/UploadAttachmentStore";
import { MediaKeyboardTarget, MediaPickerActionSheetEngagedActions } from "../MediaKeyboardConstants";
import { AnalyticEvents, ChatInputComponentViewedTypes } from "../../../../Constants";
import { AppLauncherRouteName } from "../../../app_launcher/native/AppLauncherNativeConstants";
import { KEYBOARD_ANIMATION_CONFIG } from "../../../keyboard/native/PortalKeyboardConstants";
import { jsx } from "react/jsx-runtime";
import AnalyticsUtils from "../../../../utils/AnalyticsUtils";
import { useSharedValue } from "../../../reanimated/ReanimatedRexport";
import { useKeyboardContextForType } from "../../../keyboard/native/useKeyboardType";
import { KeyboardTypes } from "../../../keyboard/native/KeyboardTypes";
import { useAppLauncherActionSheet } from "../../../app_launcher/native/AppLauncherActionSheet";
import { useMobileVisualRefreshConfig } from "../../../themes/experiments/MobileVisualRefreshExperiment";
import { useToken } from "../../../../design/tokens/native/useToken";
import Module712 from "../../../../_bundle/Module712";
import { getIsAppLauncherEnabled } from "../../../activities/ActivitiesInTextUtils";
import useMediaKeyboardConfig from "./useMediaKeyboardConfig";
import { useFileTypeFiltering } from "../../../interactions/FileTypeFiltering";
import { addImagesFromPicker, addAttachmentForCommand, handleSelectKeyboardItem, mediaNodeToUploadItem, handleAttachFile, handleCameraDialog, handleViewAllDialog, handleLimitedPickerDialog, handleSelectThread } from "../MediaKeyboardUtils";
import { getFileFromUploadItem } from "../../../../utils/native/UploadUtils";
import { dismissKeyboard } from "../../../../utils/native/ChatInputUtils";
import { UploadOrigin } from "../../../../lib/uploader/Upload";
import { isAndroid } from "../../../../utils/PlatformUtils";
import { CloudUpload } from "../../../../lib/uploader/CloudUpload";
import showUploadPreviewActionSheet from "../../../media_uploads/native/showUploadPreviewActionSheet";
import { openCreatePollModal } from "../../../polls/native/PollCreationModalActionCreators";
import { intl, t } from "../../../../intl/index.native";
import { AppsIcon } from "../../../../design/components/Icon/native/redesign/generated/AppsIcon";
import { ThreadIcon } from "../../../../design/components/Icon/native/redesign/generated/ThreadIcon";
import { PollsIcon } from "../../../../design/components/Icon/native/redesign/generated/PollsIcon";
import { AttachmentIcon } from "../../../../design/components/Icon/native/redesign/generated/AttachmentIcon";
import { ImageIcon } from "../../../../design/components/Icon/native/redesign/generated/ImageIcon";
import MediaKeyboardBottomSheetHeaderSimple from "./MediaKeyboardBottomSheetHeaderSimple";
import MediaKeyboardAccessoriesContainer from "./MediaKeyboardAccessoriesContainer";
import MediaKeyboardFloatingSend from "./MediaKeyboardFloatingSend";
import MediaKeyboardBottomSheetActions from "./MediaKeyboardBottomSheetActions";
import MediaKeyboardBottomSheet from "./MediaKeyboardBottomSheet";
import MediaKeyboardList from "./MediaKeyboardList";
import { HermesBuiltin } from "../../../../_hermes/prelude";
function $mk116983($env) {
return (a0) => (0, $env.$parent[1])(a0, $env[0]);
}
let $mk116982 = function() {
return () => dismissKeyboard();
};
let env11114 = {};
const r40 = Module19.memo(function MediaKeyboard(props) {
let env22219 = {
$parent: env11114
};
const channel = props.channel;
env22219[0] = channel;
const chatInputRef = props.chatInputRef;
env22219[1] = chatInputRef;
const { onClose, transitionState } = props;
env22219[2] = void 0;
env22219[3] = void 0;
env22219[4] = void 0;
env22219[5] = void 0;
env22219[6] = void 0;
env22219[7] = void 0;
env22219[8] = void 0;
env22219[9] = void 0;
env22219[10] = void 0;
env22219[11] = void 0;
env22219[12] = void 0;
env22219[13] = void 0;
env22219[14] = void 0;
env22219[15] = void 0;
useEffect(() => {
const CHAT_INPUT_COMPONENT_VIEWED = AnalyticEvents.CHAT_INPUT_COMPONENT_VIEWED;
const r14 = env22219[0];
AnalyticsUtils.track(CHAT_INPUT_COMPONENT_VIEWED, {
type: ChatInputComponentViewedTypes.MEDIA_PICKER,
channel_id: r14.id,
guild_id: r14.guild_id
});
}, [channel.id, channel.guild_id]);
const ref = useRef(null);
env22219[2] = ref;
const sharedValue2 = useSharedValue(-1);
env22219[3] = sharedValue2;
const sharedValue = useSharedValue(0);
env22219[4] = sharedValue;
const keyboardContextForType = useKeyboardContextForType(KeyboardTypes.MEDIA);
env22219[5] = keyboardContextForType;
const appLauncherActionSheet = useAppLauncherActionSheet({
chatInputRef,
channel
}).appLauncherActionSheet;
let chatInputFloating = useMobileVisualRefreshConfig({
location: "MediaKeyboard"
}).chatInputFloating;
const token = useToken(Module712.modules.mobile.MEDIA_KEYBOARD_SEND_VERTICAL_INSET);
env22219[6] = token;
const r23 = chatInputFloating ? getIsAppLauncherEnabled(channel) : chatInputFloating;
env22219[7] = r23;
const mediaKeyboardConfig = useMediaKeyboardConfig({
channel,
context: keyboardContextForType
});
env22219[8] = mediaKeyboardConfig;
const fileTypeFiltering = useFileTypeFiltering(mediaKeyboardConfig.fileTypes);
const allowedExtensions = fileTypeFiltering.allowedExtensions;
env22219[9] = allowedExtensions;
const validateFilenames = fileTypeFiltering.validateFilenames;
env22219[10] = validateFilenames;
const showInvalidFileTypeAlert = fileTypeFiltering.showInvalidFileTypeAlert;
env22219[11] = showInvalidFileTypeAlert;
const mediaFilesAllowed = fileTypeFiltering.mediaFilesAllowed;
const memo = useMemo(() => {
let env28092 = {
$parent: env22219
};
env28092[0] = function onRestoreKeyboard() {
const context = env22219[5];
if (context.target !== MediaKeyboardTarget.APP_LAUNCHER) {
env22219[1].current.openCustomKeyboard({
type: KeyboardTypes.MEDIA,
context
});
}
};
env28092[1] = function onSelectFiles(a0, a1) {
const r11 = env22219[5];
if (r11.target === MediaKeyboardTarget.CHAT) {
addImagesFromPicker(env22219[0].id, a0, a1);
} else if (r11.target === MediaKeyboardTarget.COMMAND) {
if (env22219[9].length > 0 && !(0, env22219[10])([getFileFromUploadItem(a0[0]).filename])) {
return (0, env22219[11])();
}
addAttachmentForCommand(env22219[0].id, env22219[1], a0[0], r11, a1);
}
};
env28092[2] = function onSelectItem({ channelId: channelId2, item: item2, isIncluded: isIncluded2 }) {
AnalyticsUtils.track(AnalyticEvents.MEDIA_PICKER_ACTION_SHEET_ENGAGED, {
action: MediaPickerActionSheetEngagedActions.MEDIA_SELECTED
});
const r27 = env22219[5];
if (r27.target === MediaKeyboardTarget.CHAT) {
handleSelectKeyboardItem(channelId2, item2, isIncluded2, false);
} else if (r27.target === MediaKeyboardTarget.COMMAND) {
const r36 = mediaNodeToUploadItem(item2);
if (env22219[9].length > 0 && !(0, env22219[10])([getFileFromUploadItem(r36).filename])) {
return (0, env22219[11])();
}
addAttachmentForCommand(channelId2, env22219[1], r36, r27, UploadOrigin.IMAGE_PICKER);
}
};
return {
onAttachPress: () => {
let env30898;
const r11 = {};
const FILE_ATTACHMENT = UploadOrigin.FILE_ATTACHMENT;
const r16 = env30898 = {
$parent: env28092
};
env30898[0] = FILE_ATTACHMENT;
HermesBuiltin.copyDataProperties(r11, {
channel: env22219[0],
uploadLimit: env22219[8].uploadLimit,
extensions: env22219[9],
onDismissKeyboard: $mk116982(),
onRestoreKeyboard: env28092[0],
onSelectFiles: $mk116983(r16)
});
handleAttachFile(r11);
},
onPressCamera: (a0) => {
let env30899;
const r11 = {};
const IMAGE_PICKER = UploadOrigin.IMAGE_PICKER;
const r16 = env30899 = {
$parent: env28092
};
env30899[0] = IMAGE_PICKER;
HermesBuiltin.copyDataProperties(r11, {
channel: env22219[0],
uploadLimit: env22219[8].uploadLimit,
extensions: env22219[9],
onDismissKeyboard: $mk116982(),
onRestoreKeyboard: env28092[0],
onSelectFiles: $mk116983(r16)
});
r11.previewType = a0;
handleCameraDialog(r11);
},
onPressHeader: () => {
if (env22219[3].get() === 0) {
const current2 = env22219[2].current;
if (current2 != null) {
current2.expand();
}
} else {
const current = env22219[2].current;
if (current != null) {
current.collapse();
}
}
},
onViewAll: () => {
let env30900;
const r5 = {};
const IMAGE_PICKER = UploadOrigin.IMAGE_PICKER;
const r10 = env30900 = {
$parent: env28092
};
env30900[0] = IMAGE_PICKER;
const r20 = env22219[8];
HermesBuiltin.copyDataProperties(r5, {
channel: env22219[0],
uploadLimit: r20.uploadLimit,
extensions: env22219[9],
onDismissKeyboard: $mk116982(),
onRestoreKeyboard: env28092[0],
onSelectFiles: $mk116983(r10)
});
r5.draftType = r20.draftType;
handleViewAllDialog(r5);
if (isAndroid()) {
const current = env22219[2].current;
if (current != null) {
current.collapse();
}
}
},
onManageLimited: () => {
handleLimitedPickerDialog({
onDismissKeyboard: dismissKeyboard,
onRestoreKeyboard: env28092[0]
});
},
onPressItem: (a0) => {
(0, env28092[2])({
channelId: a0.channelId,
item: a0.item,
isIncluded: a0.isIncluded
});
},
onLongPressItem: ({ channelId, item, isIncluded }) => {
let c30901_3;
c30901_3 = void 0;
const cloudUpload = new CloudUpload(mediaNodeToUploadItem(item), channelId);
const r26 = isIncluded ? UploadAttachmentStore.getUpload(channelId, cloudUpload.id, DraftType.ChannelMessage) : void 0;
const onRemove = r26 == null ? void 0 : () => handleSelectKeyboardItem(channelId, item, isIncluded, false);
c30901_3 = onRemove;
let upload = r26;
if (upload == null) {
upload = cloudUpload;
}
showUploadPreviewActionSheet({
channelId,
disableAddDescription: r26 == null,
disableSpoiler: r26 == null,
upload,
onAdd: r26 == null ? () => (0, env28092[2])({
channelId,
item,
isIncluded
}) : void 0,
onEdit: (a0) => {
if (c30901_3 != null) {
c30901_3();
}
(0, env28092[1])([a0], UploadOrigin.IMAGE_EDITOR);
},
onRemove
});
},
onPollsPress: () => {
const CHAT_INPUT_COMPONENT_VIEWED = AnalyticEvents.CHAT_INPUT_COMPONENT_VIEWED;
const channel = env22219[0];
AnalyticsUtils.track(CHAT_INPUT_COMPONENT_VIEWED, {
type: ChatInputComponentViewedTypes.POLLS,
channel_id: channel.id,
guild_id: channel.guild_id
});
env22219[1].current.closeCustomKeyboard();
openCreatePollModal({
channel,
onCancel: env28092[0]
});
},
onAppsPress: () => {
env22219[1].current.openCustomKeyboard({
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.HOME
}
});
},
onThreadPress: () => {
handleSelectThread(env22219[0], env22219[1]);
},
onSend: () => {
const current = env22219[2].current;
if (current != null) {
current.collapse();
}
env22219[1].current.handleSend();
}
};
}, [sharedValue2, channel, chatInputRef, keyboardContextForType, ref, mediaKeyboardConfig, allowedExtensions, validateFilenames, showInvalidFileTypeAlert]);
env22219[12] = memo;
if (chatInputFloating) {
chatInputFloating = mediaKeyboardConfig.canStartThreads;
}
env22219[13] = chatInputFloating;
const memo2 = useMemo(() => {
const r6 = env22219[7] ? [{
text: intl.string(t.PHjkRE),
IconComponent: AppsIcon,
onPress: env22219[12].onAppsPress,
disabled: false
}] : [];
const r35 = env22219[13] ? [{
text: intl.string(t["7Xm5QI"]),
IconComponent: ThreadIcon,
onPress: env22219[12].onThreadPress,
disabled: false
}] : [];
const r74 = {
text: intl.string(t.RgIi2B),
IconComponent: PollsIcon,
onPress: null,
disabled: null
};
const r80 = env22219[12];
r74.onPress = r80.onPollsPress;
const r82 = env22219[8];
r74.disabled = !r82.canPostPolls;
const r84 = [r74, ...r35, ...r6, {
text: intl.string(t["8Hvr3+"]),
IconComponent: AttachmentIcon,
onPress: r80.onAttachPress,
disabled: r82.uploadDisabled
}];
return [{
text: intl.string(t.Zmm6dN),
IconComponent: ImageIcon,
onPress: r80.onViewAll,
disabled: r82.uploadDisabled
}, ...r84];
}, [memo, mediaKeyboardConfig.uploadDisabled, mediaKeyboardConfig.canPostPolls, r23, chatInputFloating]);
env22219[14] = memo2;
env22219[15] = useRef(null);
const callback = useCallback((a0) => (0, jsx)(MediaKeyboardBottomSheetHeaderSimple, {
animatedIndex: a0.animatedIndex,
onPress: env22219[12].onPressHeader
}), [memo]);
return <MediaKeyboardBottomSheet animationConfigs={KEYBOARD_ANIMATION_CONFIG} animatedIndex={sharedValue2} animatedPosition={sharedValue} bottomSheetRef={ref} accessoriesComponent={useCallback(({ animateOnMount = false, initialPosition }) => {
const animatedIndex = env22219[3];
const r22 = env22219[8];
return <MediaKeyboardAccessoriesContainer animateOnMount={animateOnMount} animatedIndex={animatedIndex} animatedPosition={env22219[4]} initialPosition={initialPosition}>
<MediaKeyboardFloatingSend ref={env22219[15]} animatedIndex={animatedIndex} channelId={env22219[0].id} draftType={r22.draftType} onSend={env22219[12].onSend} />
<MediaKeyboardBottomSheetActions canPostPolls={r22.canPostPolls} onHeightChange={(event) => {
const current = env22219[15].current;
return current == null ? void 0 : current.setInsetFab(event + env22219[6]);
}} uploadDisabled={r22.uploadDisabled} overflowButtons={env22219[14]} />
</MediaKeyboardAccessoriesContainer>;
}, [sharedValue2, sharedValue, memo, channel.id, mediaKeyboardConfig, memo2, token])} handleComponent={callback} overlayComponent={appLauncherActionSheet} onClose={onClose} onAccessibilityFocusRestore={() => env22219[1].current.focusPhotosButton()} transitionState={transitionState}>
<MediaKeyboardList channel={channel} draftType={mediaKeyboardConfig.draftType} onPressCamera={memo.onPressCamera} onAttachPress={memo.onAttachPress} onPressItem={memo.onPressItem} onLongPressItem={memo.onLongPressItem} onViewAll={memo.onViewAll} onManageLimited={memo.onManageLimited} includedUploadIds={mediaKeyboardConfig.includedUploadIds} extensions={allowedExtensions} allowCamera={mediaFilesAllowed} uploadDisabled={mediaKeyboardConfig.uploadDisabled} uploadLimit={mediaKeyboardConfig.uploadLimit} disableWhenReachedLimit={mediaKeyboardConfig.disableWhenReachedLimit} />
</MediaKeyboardBottomSheet>;
});
export default r40;