344 lines
13 KiB
TypeScript
344 lines
13 KiB
TypeScript
// Metro module 9907 (f9908).
|
|
import _slicedToArray from "../../_bundle/_slicedToArray";
|
|
import { InAppNavigationType } from "../autocompleter/record/InAppNavigationRecord";
|
|
import { ChannelRecordBase } from "../../records/ChannelRecord";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import LibraryApplicationStore from "../../stores/LibraryApplicationStore";
|
|
import SelectedChannelStore from "../../stores/SelectedChannelStore";
|
|
import SelectedGuildStore from "../../stores/SelectedGuildStore";
|
|
import QuickSwitcherStore from "./QuickSwitcherStore";
|
|
import { AnalyticEvents, AnalyticsLocations, AnalyticsPages, AppContext, ME, Layers } from "../../Constants";
|
|
import { isStaticChannelRoute } from "../channel/ChannelConstants";
|
|
import { CollectibleShopTab } from "../collectibles/CollectiblesShopConstants";
|
|
import { findNextSelectedResult, FindResultDirections, AutocompleterResultTypes, AutocompleterQuerySymbols } from "../autocompleter/index";
|
|
import { GameProfileInQuickswitcherExperiment } from "./GameProfileInQuickswitcherExperiment";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import ValidationUtils from "../../utils/ValidationUtils";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { transitionToGuild } from "../routing/transitionToGuild.native";
|
|
import { transitionToChannel } from "../routing/transitionToChannel";
|
|
import ChannelRTCActionCreators from "../../actions/ChannelRTCActionCreators";
|
|
import SelectedChannelActionCreators from "../../actions/SelectedChannelActionCreators";
|
|
import ChannelActionCreators from "../../actions/ChannelActionCreators";
|
|
import DimensionActionCreators from "../../actions/DimensionActionCreators";
|
|
import GameProfileActionCreators_native from "../game_profile/GameProfileActionCreators.native";
|
|
import { GameProfileSources } from "../game_profile/GameProfileAnalyticUtils";
|
|
import safeTransitionTo_native from "../links/safeTransitionTo.native";
|
|
import { getHasPlaygroundAccess } from "../design/PlaygroundAccessExperiment";
|
|
import { openCollectiblesShop } from "../collectibles/CollectiblesActionCreators";
|
|
import AnalyticsLocation from "../app_analytics/AnalyticsLocation";
|
|
import InstantInviteActionCreators from "../../actions/InstantInviteActionCreators";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
let c6576_19, c6576_20, c6576_21, c6576_22, show, _openInviteFromQuickSwitcher;
|
|
const trackClose = function trackClose(a0, a1) {
|
|
const props = QuickSwitcherStore.getProps();
|
|
const results = props.results;
|
|
let queryMode = props.queryMode;
|
|
const { query, maxQueryLength } = props;
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
const channelId = SelectedChannelStore.getChannelId(guildId);
|
|
const r9 = results[findNextSelectedResult(FindResultDirections.DOWN, -1, results)];
|
|
const isEmail = ValidationUtils.isEmail(query);
|
|
const isPhoneNumber = ValidationUtils.isPhoneNumber(query);
|
|
const isUserTagLike = ValidationUtils.isUserTagLike(query);
|
|
const r21 = channelId != null && isStaticChannelRoute(channelId);
|
|
const current_channel_id = r21 ? void 0 : channelId;
|
|
const current_channel_static_route = r21 ? channelId : void 0;
|
|
if (queryMode == null) {
|
|
queryMode = "GENERAL";
|
|
}
|
|
const r45 = {
|
|
current_channel_id,
|
|
current_channel_static_route,
|
|
current_guild_id: guildId,
|
|
query_mode: queryMode,
|
|
query_length: query.length,
|
|
max_query_length: maxQueryLength,
|
|
is_email_like: isEmail,
|
|
is_phone_like: isPhoneNumber,
|
|
is_username_like: isUserTagLike,
|
|
query: isEmail ? null : isPhoneNumber ? null : isUserTagLike ? null : query,
|
|
top_result_type: r9 == null ? null : r9.type === AutocompleterResultTypes.IN_APP_NAVIGATION ? r9.type + "_" + r9.record.type : r9.type,
|
|
top_result_score: r9 != null ? r9.score : null,
|
|
num_results_total: QuickSwitcherStore.getResultTotals(),
|
|
num_results_users: QuickSwitcherStore.getResultTotals(AutocompleterResultTypes.USER),
|
|
num_results_text_channels: QuickSwitcherStore.getResultTotals(AutocompleterResultTypes.TEXT_CHANNEL),
|
|
num_results_voice_channels: QuickSwitcherStore.getResultTotals(AutocompleterResultTypes.VOICE_CHANNEL),
|
|
num_results_guilds: QuickSwitcherStore.getResultTotals(AutocompleterResultTypes.GUILD),
|
|
num_results_group_dms: QuickSwitcherStore.getResultTotals(AutocompleterResultTypes.GROUP_DM)
|
|
};
|
|
if (channelId != null) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
r45.current_channel_type = channel != null ? channel.type : null;
|
|
}
|
|
L42: {
|
|
if (a1 != null) {
|
|
const { type, score, record } = a1;
|
|
r45.selected_type = a1 == null ? null : a1.type === AutocompleterResultTypes.IN_APP_NAVIGATION ? a1.type + "_" + a1.record.type : a1.type;
|
|
r45.selected_score = score;
|
|
r45.selected_index = results.indexOf(a1);
|
|
if (AutocompleterResultTypes.GUILD === type) {
|
|
r45.selected_guild_id = record.id;
|
|
} else {
|
|
if (AutocompleterResultTypes.TEXT_CHANNEL !== type && AutocompleterResultTypes.VOICE_CHANNEL !== type) {
|
|
if (AutocompleterResultTypes.GROUP_DM === type) {
|
|
r45.selected_channel_id = record.id;
|
|
break L42;
|
|
}
|
|
if (AutocompleterResultTypes.USER !== type) {
|
|
break L42;
|
|
}
|
|
r45.selected_user_id = record.id;
|
|
break L42;
|
|
}
|
|
if (record instanceof ChannelRecordBase) {
|
|
r45.selected_guild_id = record.guild_id != null ? record.guild_id : null;
|
|
}
|
|
r45.selected_channel_id = record.id;
|
|
}
|
|
}
|
|
}
|
|
AnalyticsUtils.track(a0, r45);
|
|
};
|
|
show = function show(source = "KEYBIND", r11 = "") {
|
|
if (!QuickSwitcherStore.isOpen()) {
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
const channelId = SelectedChannelStore.getChannelId(guildId);
|
|
const r2 = channelId != null;
|
|
let current_channel_type = void 0;
|
|
if (r2) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
current_channel_type = channel != null ? channel.type : null;
|
|
}
|
|
AnalyticsUtils.track(AnalyticEvents.QUICKSWITCHER_OPENED, {
|
|
source,
|
|
current_guild_id: guildId,
|
|
current_channel_id: channelId,
|
|
current_channel_type
|
|
});
|
|
}
|
|
const enabled = GameProfileInQuickswitcherExperiment.getConfig({
|
|
location: "QuickSwitcherActionCreators.getQueryMode"
|
|
}).enabled;
|
|
const r46 = enabled ? c6576_22 : c6576_21;
|
|
let r50 = (enabled ? c6576_20 : c6576_19)[r11.charAt(0)];
|
|
if (r50 == null) {
|
|
r50 = null;
|
|
}
|
|
const r52 = {
|
|
type: "QUICKSWITCHER_SHOW"
|
|
};
|
|
const r59 = _slicedToArray([r11.replace(r46, ""), r50], 2);
|
|
HermesBuiltin.copyDataProperties(r52, {
|
|
query: r59[0],
|
|
queryMode: r59[1]
|
|
});
|
|
Dispatcher.dispatch(r52);
|
|
};
|
|
_openInviteFromQuickSwitcher = function _openInviteFromQuickSwitcher() {
|
|
const r8 = async (c26561_0) => {
|
|
let c26561_2;
|
|
c26561_2 = void 0;
|
|
let c30157_0 = c26561_0;
|
|
let c30157_1 = (await InstantInviteActionCreators.resolveInvite(c26561_0, "Quick Switcher")).invite;
|
|
if (c30157_1 != null) {
|
|
Dispatcher.dispatch({
|
|
type: "INVITE_MODAL_OPEN",
|
|
invite: c30157_1,
|
|
code: c30157_0,
|
|
context: AppContext.APP
|
|
});
|
|
}
|
|
};
|
|
_openInviteFromQuickSwitcher = r8;
|
|
return r8.apply(this, arguments);
|
|
};
|
|
Layers;
|
|
const r63 = Object;
|
|
const r65 = {};
|
|
r65[AutocompleterQuerySymbols.USER] = AutocompleterResultTypes.USER;
|
|
r65[AutocompleterQuerySymbols.TEXT_CHANNEL] = AutocompleterResultTypes.TEXT_CHANNEL;
|
|
r65[AutocompleterQuerySymbols.VOICE_CHANNEL] = AutocompleterResultTypes.VOICE_CHANNEL;
|
|
r65[AutocompleterQuerySymbols.GUILD] = AutocompleterResultTypes.GUILD;
|
|
c6576_19 = r63.freeze(r65);
|
|
const r99 = Object;
|
|
const r101 = {
|
|
...c6576_19
|
|
};
|
|
r101[AutocompleterQuerySymbols.GAME_PROFILE] = AutocompleterResultTypes.GAME_PROFILE;
|
|
c6576_20 = r99.freeze(r101);
|
|
c6576_21 = new RegExp(`^${AutocompleterQuerySymbols.USER}|${AutocompleterQuerySymbols.TEXT_CHANNEL}|${AutocompleterQuerySymbols.VOICE_CHANNEL}|\\${AutocompleterQuerySymbols.GUILD}`);
|
|
c6576_22 = new RegExp(`^${AutocompleterQuerySymbols.USER}|${AutocompleterQuerySymbols.TEXT_CHANNEL}|${AutocompleterQuerySymbols.VOICE_CHANNEL}|\\${AutocompleterQuerySymbols.GUILD}|\\${AutocompleterQuerySymbols.GAME_PROFILE}`);
|
|
export function getQuickSwitcherOptions(a0) {
|
|
const enabled = GameProfileInQuickswitcherExperiment.getConfig({
|
|
location: "QuickSwitcherActionCreators.getQueryMode"
|
|
}).enabled;
|
|
const r8 = enabled ? c6576_22 : c6576_21;
|
|
let r18 = (enabled ? c6576_20 : c6576_19)[a0.charAt(0)];
|
|
if (r18 == null) {
|
|
r18 = null;
|
|
}
|
|
const r25 = _slicedToArray([a0.replace(r8, ""), r18], 2);
|
|
return {
|
|
query: r25[0],
|
|
queryMode: r25[1]
|
|
};
|
|
}
|
|
export function trackOpen(a0) {
|
|
if (!QuickSwitcherStore.isOpen()) {
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
const channelId = SelectedChannelStore.getChannelId(guildId);
|
|
const r1 = channelId != null;
|
|
let current_channel_type = void 0;
|
|
if (r1) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
current_channel_type = channel != null ? channel.type : null;
|
|
}
|
|
AnalyticsUtils.track(AnalyticEvents.QUICKSWITCHER_OPENED, {
|
|
source: a0,
|
|
current_guild_id: guildId,
|
|
current_channel_id: channelId,
|
|
current_channel_type
|
|
});
|
|
}
|
|
}
|
|
export { trackClose };
|
|
export { show };
|
|
export function hide() {
|
|
trackClose(AnalyticEvents.QUICKSWITCHER_CLOSED);
|
|
Dispatcher.dispatch({
|
|
type: "QUICKSWITCHER_HIDE"
|
|
});
|
|
}
|
|
export function toggle(r4 = "KEYBIND") {
|
|
if (QuickSwitcherStore.isOpen()) {
|
|
trackClose(AnalyticEvents.QUICKSWITCHER_CLOSED);
|
|
Dispatcher.dispatch({
|
|
type: "QUICKSWITCHER_HIDE"
|
|
});
|
|
} else {
|
|
show(r4);
|
|
}
|
|
}
|
|
export function search(a0) {
|
|
const enabled = GameProfileInQuickswitcherExperiment.getConfig({
|
|
location: "QuickSwitcherActionCreators.getQueryMode"
|
|
}).enabled;
|
|
const r11 = enabled ? c6576_22 : c6576_21;
|
|
let r25 = (enabled ? c6576_20 : c6576_19)[a0.charAt(0)];
|
|
if (r25 == null) {
|
|
r25 = null;
|
|
}
|
|
const r26 = {
|
|
type: "QUICKSWITCHER_SEARCH"
|
|
};
|
|
const r32 = _slicedToArray([a0.replace(r11, ""), r25], 2);
|
|
HermesBuiltin.copyDataProperties(r26, {
|
|
query: r32[0],
|
|
queryMode: r32[1]
|
|
});
|
|
Dispatcher.dispatch(r26);
|
|
}
|
|
export function selectResult(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "QUICKSWITCHER_SELECT",
|
|
selectedIndex: a0
|
|
});
|
|
}
|
|
export function switchToResult(a0, r9 = false) {
|
|
Dispatcher.dispatch({
|
|
type: "QUICKSWITCHER_HIDE"
|
|
});
|
|
trackClose(AnalyticEvents.QUICKSWITCHER_RESULT_SELECTED, a0);
|
|
const { type, record } = a0;
|
|
const analyticsSource = {
|
|
page: AnalyticsPages.QUICK_SWITCHER
|
|
};
|
|
if (AutocompleterResultTypes.GUILD === type) {
|
|
transitionToGuild(record.id, {
|
|
navigationReplace: true
|
|
});
|
|
} else if (AutocompleterResultTypes.TEXT_CHANNEL === type) {
|
|
const channel2 = ChannelStore.getChannel(record.id);
|
|
if (channel2 != null) {
|
|
transitionToChannel(channel2.id, {
|
|
state: {
|
|
analyticsSource
|
|
},
|
|
navigationReplace: true
|
|
});
|
|
}
|
|
} else if (AutocompleterResultTypes.VOICE_CHANNEL === type) {
|
|
const channel = ChannelStore.getChannel(record.id);
|
|
if (channel != null) {
|
|
if (r9) {
|
|
ChannelRTCActionCreators.updateChatOpen(record.id, true);
|
|
} else {
|
|
SelectedChannelActionCreators.selectVoiceChannel(record.id);
|
|
}
|
|
transitionToChannel(channel.id, {
|
|
state: {
|
|
analyticsSource
|
|
},
|
|
navigationReplace: true
|
|
});
|
|
}
|
|
} else if (AutocompleterResultTypes.USER === type) {
|
|
ChannelActionCreators.openPrivateChannel({
|
|
recipientIds: [record.id],
|
|
location: "Quickswitcher"
|
|
});
|
|
DimensionActionCreators.channelListScrollTo(ME, ChannelStore.getDMFromUserId(record.id));
|
|
} else if (AutocompleterResultTypes.GROUP_DM === type) {
|
|
transitionToChannel(record.id, {
|
|
navigationReplace: true
|
|
});
|
|
DimensionActionCreators.channelListScrollTo(ME, record.id);
|
|
} else if (AutocompleterResultTypes.APPLICATION === type) {
|
|
LibraryApplicationStore.getActiveLibraryApplication(record.id);
|
|
record.id;
|
|
AnalyticsLocations.QUICK_SWITCHER;
|
|
AnalyticsLocations.QUICK_SWITCHER;
|
|
Promise.resolve();
|
|
} else if (AutocompleterResultTypes.GAME_PROFILE === type) {
|
|
GameProfileActionCreators_native.openGameProfileModal({
|
|
gameId: record.id,
|
|
gameProfileModalChecks: {
|
|
shouldOpenGameProfile: true,
|
|
gameId: record.id
|
|
},
|
|
source: GameProfileSources.QuickSwitcher
|
|
});
|
|
} else if (AutocompleterResultTypes.LINK === type) {
|
|
if (record.inviteCode != null) {
|
|
(function openInviteFromQuickSwitcher() {
|
|
return _openInviteFromQuickSwitcher.apply(this, arguments);
|
|
})(record.inviteCode);
|
|
} else {
|
|
safeTransitionTo_native(record.path, {
|
|
navigationReplace: true
|
|
});
|
|
}
|
|
} else if (AutocompleterResultTypes.IN_APP_NAVIGATION === type && a0.record.type !== InAppNavigationType.SETTINGS) {
|
|
if (a0.record.type === InAppNavigationType.PLAYGROUND) {
|
|
if (!getHasPlaygroundAccess("quickswitcher_action")) {
|
|
return void 0;
|
|
}
|
|
} else if (a0.record.type === InAppNavigationType.SHOP_ORBS_TAB) {
|
|
openCollectiblesShop({
|
|
tab: CollectibleShopTab.ORBS,
|
|
analyticsLocations: [AnalyticsLocation.QUICK_SWITCHER],
|
|
analyticsSource: AnalyticsLocation.QUICK_SWITCHER
|
|
});
|
|
} else {
|
|
safeTransitionTo_native(record.path, {
|
|
navigationReplace: true
|
|
});
|
|
}
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "QUICKSWITCHER_SWITCH_TO",
|
|
result: a0
|
|
});
|
|
}
|