36 lines
2.0 KiB
TypeScript
36 lines
2.0 KiB
TypeScript
// Metro module 15591 (f15592).
|
|
import { useMemo } from "react";
|
|
import { MediaKeyboardTarget } from "../MediaKeyboardConstants";
|
|
import { ChannelTypesSets, MAX_UPLOAD_COUNT } from "../../../../Constants";
|
|
import { useCanPostPollsInChannel } from "../../../polls/PollsUtils";
|
|
import useUploadDisabled from "../useUploadDisabled";
|
|
import { useCanStartThread } from "../../../threads/ThreadHooks";
|
|
import { useIsAppLauncherEnabled } from "../../../activities/ActivitiesInTextUtils";
|
|
import { getMediaKeyboardDraftType } from "../MediaKeyboardUtils";
|
|
import { ApplicationCommandOptionType } from "../../../../flow/Server";
|
|
export default function useMediaKeyboardConfig({ channel, context }) {
|
|
const r1 = context.target === MediaKeyboardTarget.COMMAND;
|
|
const canPostPolls = useCanPostPollsInChannel(channel) && !r1;
|
|
const uploadDisabled = useUploadDisabled(channel);
|
|
const canStartThreads = useCanStartThread(channel) && !ChannelTypesSets.GUILD_THREADS_ONLY.has(channel.type) && !channel.isThread() && !r1;
|
|
const isAppLauncherEnabled = useIsAppLauncherEnabled(channel.id) && !r1;
|
|
const mediaKeyboardDraftType = getMediaKeyboardDraftType(context.target);
|
|
return useMemo(() => {
|
|
const target = context.target;
|
|
if (target !== MediaKeyboardTarget.CHAT && target !== MediaKeyboardTarget.COMMAND) {
|
|
throw new Error(`MediaKeyboard does not support context target ${target}`);
|
|
}
|
|
return {
|
|
uploadLimit: target === MediaKeyboardTarget.CHAT ? MAX_UPLOAD_COUNT : 1,
|
|
disableWhenReachedLimit: target === MediaKeyboardTarget.CHAT,
|
|
includedUploadIds: target !== MediaKeyboardTarget.CHAT ? [context.option.name] : void 0,
|
|
fileTypes: target === MediaKeyboardTarget.COMMAND ? context.option.type === ApplicationCommandOptionType.ATTACHMENT ? context.option.fileTypes : void 0 : void 0,
|
|
canPostPolls,
|
|
canStartThreads,
|
|
isAppLauncherEnabled,
|
|
uploadDisabled,
|
|
draftType: mediaKeyboardDraftType
|
|
};
|
|
}, [context, canPostPolls, uploadDisabled, mediaKeyboardDraftType, canStartThreads, isAppLauncherEnabled]);
|
|
};
|