153 lines
6.2 KiB
TypeScript
153 lines
6.2 KiB
TypeScript
// Metro module 10921 (f10922).
|
|
import { useContext } from "react";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import { AppLauncherRouteName, useAppLauncherNavigation } from "../../app_launcher/native/AppLauncherNativeConstants";
|
|
import { SUB_COMMAND_KEY_SEPARATOR } from "../../application_commands/ApplicationCommandConstants";
|
|
import { COMMAND_SENTINEL } from "../../channel_autocomplete/ChannelAutocompleteConstants";
|
|
import { ApplicationCommandTriggerLocations } from "../../application_commands/ApplicationCommandTypes";
|
|
import { getRootNavigationRef } from "../../main_tabs_v2/RootNavigationRef.native";
|
|
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
|
|
import { KeyboardTypes } from "../../keyboard/native/KeyboardTypes";
|
|
import AlertActionCreators from "../../../actions/native/AlertActionCreators";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { ButtonColors } from "../../../design/void/native";
|
|
import { SlashBoxIcon } from "../../../design/components/Icon/native/redesign/generated/SlashBoxIcon";
|
|
import { presentCommandCopied, presentIdCopied } from "../../toast/native/ToastUtils";
|
|
import { copy } from "../../../utils/ClipboardUtils.native";
|
|
import { DeveloperMode } from "../../user_settings/UserSettings";
|
|
import { IdIcon } from "../../../design/components/Icon/native/redesign/generated/IdIcon";
|
|
import { showSimpleActionSheet } from "../../action_sheet/native/showSimpleActionSheet";
|
|
import { AppLauncherContext } from "../../app_launcher/native/AppLauncherContext";
|
|
import { Text } from "../../../design/components/Text/native/Text";
|
|
import { getBestActiveInput } from "../../../utils/native/ChatInputUtils";
|
|
import navigateToLastChannel from "../../main_tabs_v2/native/navigateToLastChannel";
|
|
import { smartOutput } from "../MarkupRulesUtils";
|
|
let handleLongPressCommandMention;
|
|
const handleTapCommandMention = function handleTapCommandMention({ appLauncherNavigator, channelId, currentText, onSetCommand: onSetCommand2, onOpenCustomKeyboard: onOpenCustomKeyboard2, commandId: commandId2, commandName }) {
|
|
let commandId;
|
|
commandId = void 0;
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
if (channel != null && channel.guild_id != null) {
|
|
commandId = commandName.includes(" ") ? commandId2 + SUB_COMMAND_KEY_SEPARATOR + commandName.split(" ").slice(1).join(SUB_COMMAND_KEY_SEPARATOR) : commandId2;
|
|
if (appLauncherNavigator != null && channel != null) {
|
|
appLauncherNavigator.navigate({
|
|
name: AppLauncherRouteName.COMMAND_VIEW,
|
|
params: {
|
|
analyticsLocation: ApplicationCommandTriggerLocations.MENTION,
|
|
preSelectedCommand: {
|
|
commandId
|
|
},
|
|
context: {
|
|
type: "channel",
|
|
channel
|
|
}
|
|
}
|
|
});
|
|
return void 0;
|
|
}
|
|
const rootNavigationRef = getRootNavigationRef();
|
|
if (rootNavigationRef != null) {
|
|
const state = rootNavigationRef.getState();
|
|
if ((state == null ? void 0 : state.routes?.length) > 1) {
|
|
const state2 = rootNavigationRef.getState();
|
|
let r97 = state2 == null ? void 0 : state2.routes?.length;
|
|
if (r97 == null) {
|
|
r97 = 0;
|
|
}
|
|
while (r97 > 1) {
|
|
rootNavigationRef.goBack();
|
|
r97 = r97 - 1;
|
|
}
|
|
}
|
|
}
|
|
ActionSheetActionCreators.hideActionSheet();
|
|
setTimeout(() => onOpenCustomKeyboard2({
|
|
type: KeyboardTypes.APP_LAUNCHER,
|
|
context: {
|
|
initialRouteName: AppLauncherRouteName.COMMAND_VIEW,
|
|
analyticsLocation: ApplicationCommandTriggerLocations.MENTION,
|
|
preSelectedCommand: {
|
|
commandId
|
|
}
|
|
}
|
|
}), 0);
|
|
} else if (currentText === "") {
|
|
onSetCommand2();
|
|
} else {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t.pe26Cj),
|
|
confirmText: intl.string(t.VkKicb),
|
|
onConfirm: () => onSetCommand2(),
|
|
cancelText: intl.string(t["ETE/oC"]),
|
|
confirmColor: ButtonColors.BRAND,
|
|
body: intl.string(t["+awCIy"])
|
|
});
|
|
}
|
|
};
|
|
handleLongPressCommandMention = function handleLongPressCommandMention(c18367_0, c18367_1) {
|
|
const options = [{
|
|
label: intl.string(t["42H+Nb"]),
|
|
IconComponent: SlashBoxIcon,
|
|
onPress: () => {
|
|
presentCommandCopied();
|
|
copy(`${COMMAND_SENTINEL}${c18367_0}`);
|
|
}
|
|
}];
|
|
if (DeveloperMode.getSetting()) {
|
|
options.push({
|
|
label: intl.string(t.oJ1Muw),
|
|
IconComponent: IdIcon,
|
|
onPress: () => {
|
|
presentIdCopied();
|
|
copy(c18367_1);
|
|
}
|
|
});
|
|
}
|
|
showSimpleActionSheet({
|
|
key: "LongPressCommandMention",
|
|
options,
|
|
hasIcons: true
|
|
});
|
|
};
|
|
export default function MarkupReactCommandRule(props) {
|
|
const { node, output, state, style } = props;
|
|
let c18368_1 = useContext(AppLauncherContext) != null;
|
|
const appLauncherNavigation = useAppLauncherNavigation();
|
|
return <Text style={style} variant="text-md/bold" onPress={() => {
|
|
const bestActiveInput = getBestActiveInput();
|
|
const appLauncherNavigator = c18368_1 ? appLauncherNavigation : void 0;
|
|
let currentText = bestActiveInput == null ? void 0 : bestActiveInput.getText();
|
|
if (currentText == null) {
|
|
currentText = "";
|
|
}
|
|
handleTapCommandMention({
|
|
appLauncherNavigator,
|
|
channelId: node.channelId,
|
|
commandId: node.commandId,
|
|
commandName: node.commandName,
|
|
currentText,
|
|
onOpenCustomKeyboard: (a0) => bestActiveInput == null ? void 0 : bestActiveInput.openCustomKeyboard(a0),
|
|
onSetCommand: () => {
|
|
navigateToLastChannel();
|
|
ActionSheetActionCreators.hideActionSheet();
|
|
if (bestActiveInput != null) {
|
|
bestActiveInput.openSystemKeyboard();
|
|
}
|
|
if (bestActiveInput != null) {
|
|
const applicationCommandManager = bestActiveInput.getApplicationCommandManager();
|
|
if (applicationCommandManager != null) {
|
|
applicationCommandManager.setPartialCommand(node.commandId, node.commandName, ApplicationCommandTriggerLocations.MENTION);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}} onLongPress={() => {
|
|
handleLongPressCommandMention(node.commandName, node.commandId);
|
|
}}>
|
|
/
|
|
{smartOutput(node, output, state)}
|
|
</Text>;
|
|
};
|
|
export { handleTapCommandMention };
|
|
export { handleLongPressCommandMention };
|