// Metro module 11225 (f11226). import { useEffect } from "react"; import ChannelStore from "../../../stores/ChannelStore"; import UserStore from "../../../stores/UserStore"; import { APP_LAUNCHER_BUILT_IN_SECTION_ICON, AppLauncherRouteName } from "./AppLauncherNativeConstants"; import { AnalyticEvents } from "../../../Constants"; import { BuiltInSectionId } from "../../application_commands/ApplicationCommandConstants"; import { trackWithMetadata } from "../../app_analytics/AppAnalyticsUtils"; import { ApplicationCommandTriggerSections, CommandOrigin } from "../../application_commands/ApplicationCommandTypes"; import { SectionItemType } from "./screens/home/FrecencySection"; import { trackCommandSelected, getCommandTriggerSection } from "../../application_commands/ApplicationCommandUtils"; import { ApplicationCommandType, ApplicationCommandOptionType } from "../../../flow/Server"; import { setAppLauncherActiveCommand } from "../../application_commands/ApplicationCommandActionCreators"; import Module1855 from "../../../_bundle/Module1855"; import { isRealApplication } from "../utils/AppLauncherUtils"; import AvatarUtils from "../../../utils/AvatarUtils"; import { useAppLauncherContext } from "./AppLauncherContext"; import { useAnalyticsContext } from "../../../hooks/analytics"; import { useActivityAction, useOnActivityItemSelected } from "../../activities/utils/useActivityShelfItem"; import { useGetOrFetchApplication } from "../../applications/useGetOrFetchApplications"; import EmbeddedActivitiesNativeManager from "../../activities/native/EmbeddedActivitiesNativeManager"; import { triggerHapticFeedback, HapticFeedbackTypes } from "../../haptics/HapticUtils.native"; export function handleApplicationSelected({ location: location3, application, navigation, context, sectionName: sectionName2, installOnDemand, query, searchResultsPosition, navigates = true, entrypoint: entrypoint3 }) { const APPLICATION_COMMAND_SECTION_SELECTED = AnalyticEvents.APPLICATION_COMMAND_SECTION_SELECTED; const section = application.id === BuiltInSectionId.BUILT_IN ? ApplicationCommandTriggerSections.BUILT_IN : ApplicationCommandTriggerSections.APP; let id = application.id; if (id == null) { id = null; } trackWithMetadata(APPLICATION_COMMAND_SECTION_SELECTED, { location: location3, section, application_id: id, section_name: sectionName2, query, search_results_position: searchResultsPosition, source: entrypoint3 }); if (navigates) { navigation.navigate(AppLauncherRouteName.APPLICATION_VIEW, { application, context, installOnDemand, sectionName: sectionName2, entrypoint: entrypoint3 }); } } export function handleViewAllSelected({ location: location3, navigation, context, sectionName: sectionName2, sectionOverallPosition, applications, sectionItemType, commands, sectionDescriptors, title, promotedApplicationIds }) { trackWithMetadata(AnalyticEvents.APP_LAUNCHER_SECTION_VIEW_MORE, { section_name: sectionName2, num: sectionItemType === SectionItemType.APPS ? applications.length : commands.length }); navigation.navigate(AppLauncherRouteName.APP_LIST_VIEW, { analyticsLocation: location3, context, sectionName: sectionName2, sectionOverallPosition, applications, sectionItemType, commands, sectionDescriptors, title, promotedApplicationIds }); } export function handleApplicationCommandSelected({ location: location3, context, command, section, sectionDescriptors, query, navigation, installOnDemand, sectionName: sectionName2, searchResultsPosition, entrypoint: entrypoint3, onCommandExecuted }) { trackCommandSelected({ command, location: location3, triggerSection: getCommandTriggerSection(section), queryLength: query.length, sectionName: sectionName2, query, searchResultsPosition, source: entrypoint3 }); if (command.type === ApplicationCommandType.PRIMARY_ENTRY_POINT) { navigation.navigate(AppLauncherRouteName.APPLICATION_VIEW, { application: section.application, context, installOnDemand, sectionName: sectionName2, entrypoint: entrypoint3 }); } else { const id = section.id; const FRECENCY = BuiltInSectionId.FRECENCY; let section2 = section; if (id === FRECENCY) { const r40 = sectionDescriptors.find((sectionDescriptor) => sectionDescriptor.id === command.applicationId); section2 = r40 ?? section; } if (context.type !== "channel") { return void 0; } setAppLauncherActiveCommand(context.channel.id, command); navigation.navigate(AppLauncherRouteName.COMMAND_VIEW, { command, section: section2, context, installOnDemand, sectionName: sectionName2, analyticsLocation: location3, onCommandExecuted }); } } export function getInitialOptionValues({ option, prefilledValues, guildId, roles }) { let c18633_1; c18633_1 = void 0; const r13 = prefilledValues == null ? void 0 : prefilledValues.find((prefilledValue) => prefilledValue.name === option.name && prefilledValue.type === option.type); c18633_1 = r13; const type2 = option.type; if (ApplicationCommandOptionType.BOOLEAN === type2) { return r13 != null ? [{ type: "text", text: String(Boolean(r13.value)) }] : [{ type: "text", text: "false" }]; } if (ApplicationCommandOptionType.STRING !== type2 && ApplicationCommandOptionType.INTEGER !== type2 && ApplicationCommandOptionType.NUMBER !== type2) { if (ApplicationCommandOptionType.CHANNEL === type2) { return r13 != null && ChannelStore.getChannel(String(r13.value)) != null ? [{ type: "channelMention", channelId: String(r13.value) }] : [{ type: "text", text: "" }]; } if (ApplicationCommandOptionType.USER === type2) { return r13 != null && UserStore.getUser(String(r13.value)) != null ? [{ type: "userMention", userId: String(r13.value) }] : [{ type: "text", text: "" }]; } if (ApplicationCommandOptionType.ROLE === type2) { return r13 != null && (typeof r13.value === "string" && r13.value in roles) ? [{ type: "roleMention", roleId: r13.value }] : [{ type: "text", text: "" }]; } if (ApplicationCommandOptionType.MENTIONABLE === type2) { if (r13 != null) { if (r13.value === guildId) { return [{ type: "textMention", text: "@everyone" }]; } if (typeof r13.value === "string" && r13.value in roles) { return [{ type: "roleMention", roleId: r13.value }]; } if (UserStore.getUser(String(r13.value)) != null) { return [{ type: "userMention", userId: String(r13.value) }]; } } return [{ type: "text", text: "" }]; } return [{ type: "text", text: "" }]; } if (r13 != null) { if (option.choices == null) { return [{ type: "text", text: String(r13.value) }]; } if (option.choices.some((choice) => choice.value === c18633_1.value)) { return [{ type: "text", text: option.choices.find((choice) => choice.value === c18633_1.value).displayName }]; } } return [{ type: "text", text: "" }]; } export function getAppLauncherIconSource(a0) { return a0 == null ? Module1855 : isRealApplication(a0) ? AvatarUtils.getApplicationIconSource({ id: a0.id, icon: a0.icon, bot: a0.bot, botIconFirst: false }) : AvatarUtils.makeSource(APP_LAUNCHER_BUILT_IN_SECTION_ICON); } export function useLogAppLauncherEmptyStateView(a0, a1) { const type = a0; const entrypoint = useAppLauncherContext().entrypoint; useEffect(() => { if (type != null) { trackWithMetadata(AnalyticEvents.APP_LAUNCHER_EMPTY_STATE_ENCOUNTERED, { type, source: entrypoint }); } }, [a0, a1, entrypoint]); } export function useHandleActivityItemSelected({ applicationId, context, sectionName, onActivityItemSelected, location: location2, entrypoint: entrypoint2, launchingComponentId, fetchesApplication = true }) { const analyticsContext = useAnalyticsContext(); const activityAction = useActivityAction({ context, applicationId, fetchesApplication }); const getOrFetchApplication = useGetOrFetchApplication(applicationId, fetchesApplication); const entrypointParams = useAppLauncherContext().entrypointParams; const onActivityItemSelected2 = useOnActivityItemSelected({ application: getOrFetchApplication, context, embeddedActivitiesManager: EmbeddedActivitiesNativeManager, locationObject: analyticsContext.location, onActivityItemSelectedProp: ({ applicationId }) => { if (onActivityItemSelected != null) { onActivityItemSelected({ applicationId }); } trackWithMetadata(AnalyticEvents.APP_LAUNCHER_ACTIVITY_ITEM_SELECTED, { location: location2, application_id: applicationId, section_name: sectionName, action: activityAction, source: entrypoint2 }); }, launchingComponentId, commandOrigin: CommandOrigin.APPLICATION_LAUNCHER, sectionName, source: entrypoint2, fetchesApplication, customId: entrypointParams?.customId, referrerId: entrypointParams?.referrerId }); return { handleActivityItemSelected: function handleActivityItemSelected() { triggerHapticFeedback(HapticFeedbackTypes.IMPACT_MEDIUM); onActivityItemSelected2(); } }; }