429 lines
15 KiB
TypeScript
429 lines
15 KiB
TypeScript
// Metro module 15480 (f15481).
|
|
import { useCallback, useContext } from "react";
|
|
import ChannelStore from "../../../../stores/ChannelStore";
|
|
import SearchQueryStore from "../stores/SearchQueryStore";
|
|
import { SearchHistoryItemTypes, SearchMediaTypes, SearchQueryTagTypes } from "../../SearchConstants";
|
|
import { SearchNavigatorScreens } from "../components/navigator/SearchNavigatorConstants";
|
|
import { SearchFilterAddLocations } from "../tracking/TrackingConstants";
|
|
import { SearchTypes, ME, Routes } from "../../../../Constants";
|
|
import { StaticChannelRoute } from "../../../channel/ChannelConstants";
|
|
import SearchPlatformUtils, { delayUntilNavigationComplete, performKeyboardAwareNavigation } from "../SearchPlatformUtils";
|
|
import SearchPlatformActionCreators from "../SearchPlatformActionCreators";
|
|
import URLUtils from "../../../../utils/URLUtils";
|
|
import { presentFailedToast } from "../../../toast/native/ToastUtils";
|
|
import { intl, t } from "../../../../intl/index.native";
|
|
import { handleClick } from "../../../../utils/MaskedLinkUtils";
|
|
import Linking from "../../../../lib/native/Linking";
|
|
import { useNavigation } from "../../../../design/components/Navigator/native/useNavigation.native";
|
|
import { SwipeForMemberListContext } from "../../../main_tabs_v2/native/channel/SwipeForMemberListWrapper";
|
|
import MessagePreviewActionCreators from "../../../../actions/native/MessagePreviewActionCreators";
|
|
import { openMediaModal } from "../../../media_viewer/native/components/openMediaModal";
|
|
import ChannelActionCreators from "../../../../actions/ChannelActionCreators";
|
|
import { transitionToChannel } from "../../../routing/transitionToChannel";
|
|
import "../../../../_bundle/asyncRequire";
|
|
import { maybeOpenAgeGateForVoiceChannel } from "../../../age_gate/AgeGateUtils";
|
|
import { maybeOpenSpoilerGateForVoiceChannel } from "../../../spoiler_channels/maybeOpenSpoilerGateForVoiceChannel.native";
|
|
import { getChannelRoleSubscriptionStatus } from "../../../guild_role_subscriptions/useChannelRoleSubscriptionStatus";
|
|
import { shouldShowMembershipVerificationGate } from "../../../guild_member_verification/hooks/useShowMemberVerificationGate";
|
|
import { transitionTo } from "../../../routing/router_utils";
|
|
import Tracking from "../tracking/Tracking";
|
|
function $mk96657($env) {
|
|
return () => {
|
|
const r1 = $env;
|
|
const r2 = $env.$parent;
|
|
return (0, r2[1])(r2[2][10]).addSearchHistoryItem(r1[0], r1[1]);
|
|
};
|
|
}
|
|
function $mk96658($env) {
|
|
return () => {
|
|
const r5 = $env;
|
|
const r1 = $env.$parent;
|
|
(0, r1[0])(r1[2][19]).ComponentDispatch.dispatch(r1[13].HIDE_CHANNEL_DETAILS, {
|
|
channelId: r5[0].id,
|
|
screenIndex: r5[1].screenIndex
|
|
});
|
|
};
|
|
}
|
|
function $mk118936($env) {
|
|
return () => (0, handleVoiceOrStageChannelConnectPress)($env[0]);
|
|
}
|
|
let env11014 = {};
|
|
export async function handleVoiceOrStageChannelConnectPress(c28040_0) {
|
|
let c30882_0 = c28040_0;
|
|
if (c28040_0.isGuildStageVoice()) {
|
|
(0, (await import("../../../stage_channels/StageChannelModalActionCreators")).connectAndOpen)(c30882_0);
|
|
} else {
|
|
(0, (await import("../../../../utils/native/PrivateChannelCallUtils")).openGuildVoiceModal)(c30882_0, "Channel List");
|
|
}
|
|
}
|
|
export function useOnPressSearchLink(a0) {
|
|
let c22057_0 = a0;
|
|
return useCallback((a0, c28041_0) => {
|
|
let c28041_1;
|
|
let env28042;
|
|
const r3 = env11014;
|
|
const tags = SearchQueryStore.getTags(c22057_0);
|
|
const r18 = {
|
|
type: SearchHistoryItemTypes.TEXT,
|
|
text: SearchQueryStore.getTextInputValue(c22057_0),
|
|
tags
|
|
};
|
|
const r19 = env28042 = {
|
|
$parent: r3
|
|
};
|
|
env28042[0] = c22057_0;
|
|
env28042[1] = r18;
|
|
const type = c22057_0.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r19));
|
|
}
|
|
const r38 = URLUtils.safeParseWithQuery(a0);
|
|
if (r38 != null && (r38.protocol != null && r38.hostname != null)) {
|
|
const href = URLUtils.format(r38);
|
|
c28041_1 = href;
|
|
handleClick({
|
|
href,
|
|
onConfirm: () => Linking.openURL(c28041_1),
|
|
trusted: () => c28041_0
|
|
});
|
|
} else {
|
|
presentFailedToast(intl.string(t.XiqzAp));
|
|
}
|
|
}, [a0]);
|
|
}
|
|
export function useOnPressMessageItem({ searchContext }) {
|
|
const navigation = useNavigation();
|
|
const context = useContext(SwipeForMemberListContext);
|
|
return useCallback((a0, a1) => {
|
|
const r3 = env11014;
|
|
const channel = ChannelStore.getChannel(a0);
|
|
if (channel != null) {
|
|
let env28044;
|
|
const tags = SearchQueryStore.getTags(searchContext);
|
|
const r16 = {
|
|
type: SearchHistoryItemTypes.TEXT,
|
|
text: SearchQueryStore.getTextInputValue(searchContext),
|
|
tags
|
|
};
|
|
const r17 = env28044 = {
|
|
$parent: r3
|
|
};
|
|
env28044[0] = searchContext;
|
|
env28044[1] = r16;
|
|
const type = searchContext.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r17));
|
|
}
|
|
MessagePreviewActionCreators.fetchMessages(a0, a1);
|
|
performKeyboardAwareNavigation(() => {
|
|
let env30883;
|
|
const r5 = env30883 = {
|
|
$parent: env11014
|
|
};
|
|
env30883[0] = channel;
|
|
env30883[1] = context;
|
|
let guildId = channel.getGuildId();
|
|
if (guildId == null) {
|
|
guildId = ME;
|
|
}
|
|
const r6 = {
|
|
channelId: channel.id,
|
|
guildId,
|
|
searchContext
|
|
};
|
|
if (context != null) {
|
|
navigation.navigate("sidebar", {
|
|
screen: SearchNavigatorScreens.SEARCH_CHAT_PREVIEW,
|
|
params: {
|
|
...r6,
|
|
onBeforeJumpToMessage: $mk96658(r5)
|
|
}
|
|
});
|
|
} else {
|
|
navigation.navigate(SearchNavigatorScreens.SEARCH_CHAT_PREVIEW, r6);
|
|
}
|
|
});
|
|
}
|
|
}, [navigation, searchContext, context]);
|
|
}
|
|
export function useOnPressMediaItem({ searchContext: searchContext2, allMediaResults, onEndReached, onEndReachedThreshold }) {
|
|
const navigation2 = useNavigation();
|
|
const context2 = useContext(SwipeForMemberListContext);
|
|
return useCallback((a0, a1) => {
|
|
let channel2, c28045_2, initialIndex, c28045_4;
|
|
let env28046;
|
|
const r4 = env11014;
|
|
const tags = SearchQueryStore.getTags(searchContext2);
|
|
const r14 = {
|
|
type: SearchHistoryItemTypes.TEXT,
|
|
text: SearchQueryStore.getTextInputValue(searchContext2),
|
|
tags
|
|
};
|
|
const r15 = env28046 = {
|
|
$parent: r4
|
|
};
|
|
env28046[0] = searchContext2;
|
|
env28046[1] = r14;
|
|
const type = searchContext2.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r15));
|
|
}
|
|
const type2 = a0.type;
|
|
if (SearchMediaTypes.AUDIO === type2) {
|
|
channel2 = ChannelStore.getChannel(a0.channelId);
|
|
if (channel2 == null) {
|
|
return void 0;
|
|
}
|
|
MessagePreviewActionCreators.fetchMessages(a0.channelId, a0.messageId);
|
|
performKeyboardAwareNavigation(() => {
|
|
let env30884;
|
|
const r5 = env30884 = {
|
|
$parent: env11014
|
|
};
|
|
env30884[0] = channel2;
|
|
env30884[1] = context2;
|
|
let guildId = channel2.getGuildId();
|
|
if (guildId == null) {
|
|
guildId = ME;
|
|
}
|
|
const r6 = {
|
|
channelId: channel2.id,
|
|
guildId,
|
|
searchContext: searchContext2
|
|
};
|
|
if (context2 != null) {
|
|
navigation2.navigate("sidebar", {
|
|
screen: SearchNavigatorScreens.SEARCH_CHAT_PREVIEW,
|
|
params: {
|
|
...r6,
|
|
onBeforeJumpToMessage: $mk96658(r5)
|
|
}
|
|
});
|
|
} else {
|
|
navigation2.navigate(SearchNavigatorScreens.SEARCH_CHAT_PREVIEW, r6);
|
|
}
|
|
});
|
|
return void 0;
|
|
}
|
|
if (!(SearchMediaTypes.ATTACHMENT !== type2 && (SearchMediaTypes.EMBED !== type2 && SearchMediaTypes.COMPONENT !== type2))) {
|
|
c28045_2 = 0;
|
|
initialIndex = 0;
|
|
const initialSources = [];
|
|
c28045_4 = initialSources;
|
|
allMediaResults.forEach((allMediaResult) => {
|
|
if (!(allMediaResult.type !== SearchMediaTypes.ATTACHMENT && allMediaResult.type !== SearchMediaTypes.EMBED && allMediaResult.type !== SearchMediaTypes.COMPONENT)) {
|
|
c28045_4.push(allMediaResult.sources);
|
|
const messageId = allMediaResult.messageId;
|
|
if (messageId === a0.messageId && allMediaResult.mediaIndex === a0.mediaIndex) {
|
|
initialIndex = c28045_2;
|
|
}
|
|
c28045_2 = c28045_2 + 1;
|
|
}
|
|
});
|
|
openMediaModal({
|
|
initialSources,
|
|
initialIndex,
|
|
onEndReached,
|
|
onEndReachedThreshold,
|
|
analyticsSource: "Search",
|
|
originViewOrOriginLayout: a1
|
|
});
|
|
}
|
|
}, [searchContext2, navigation2, context2, allMediaResults, onEndReached, onEndReachedThreshold]);
|
|
}
|
|
export function useOnPressGroupDMItem({ searchContext: searchContext3 }) {
|
|
const navigation3 = useNavigation();
|
|
return useCallback((a0) => {
|
|
let env28048;
|
|
const r3 = env11014;
|
|
const r6 = {
|
|
type: SearchHistoryItemTypes.GROUP_DM,
|
|
channelId: a0
|
|
};
|
|
const r10 = env28048 = {
|
|
$parent: r3
|
|
};
|
|
env28048[0] = searchContext3;
|
|
env28048[1] = r6;
|
|
const type = searchContext3.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r10));
|
|
}
|
|
const parent = navigation3.getParent();
|
|
if (parent != null) {
|
|
parent.goBack();
|
|
}
|
|
ChannelActionCreators.preload(ME, a0);
|
|
performKeyboardAwareNavigation(() => {
|
|
transitionToChannel(a0);
|
|
});
|
|
}, [navigation3, searchContext3]);
|
|
}
|
|
export function useOnPressDMItem({ searchContext: searchContext4 }) {
|
|
const navigation4 = useNavigation();
|
|
return useCallback((a0, a1) => {
|
|
let env28050;
|
|
const r4 = env11014;
|
|
const r7 = {
|
|
type: SearchHistoryItemTypes.DM,
|
|
userId: a0
|
|
};
|
|
const r11 = env28050 = {
|
|
$parent: r4
|
|
};
|
|
env28050[0] = searchContext4;
|
|
env28050[1] = r7;
|
|
const type = searchContext4.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r11));
|
|
}
|
|
const parent = navigation4.getParent();
|
|
if (parent != null) {
|
|
parent.goBack();
|
|
}
|
|
ChannelActionCreators.preload(ME, a1);
|
|
performKeyboardAwareNavigation(() => {
|
|
transitionToChannel(a1);
|
|
});
|
|
return a1;
|
|
}, [navigation4, searchContext4]);
|
|
}
|
|
export function useOnPressGuildTextChannel({ searchContext: searchContext5 }) {
|
|
return useCallback((a0) => {
|
|
const r4 = env11014;
|
|
const channel3 = ChannelStore.getChannel(a0);
|
|
if (channel3 == null) {
|
|
return null;
|
|
}
|
|
let env28052;
|
|
const r7 = {
|
|
type: SearchHistoryItemTypes.GUILD_TEXT_CHANNEL,
|
|
channelId: channel3.id
|
|
};
|
|
const r15 = env28052 = {
|
|
$parent: r4
|
|
};
|
|
env28052[0] = searchContext5;
|
|
env28052[1] = r7;
|
|
const type = searchContext5.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r15));
|
|
}
|
|
ChannelActionCreators.preload(channel3.guild_id, channel3.id);
|
|
performKeyboardAwareNavigation(() => transitionToChannel(channel3.id));
|
|
}, [searchContext5]);
|
|
}
|
|
export function useOnPressGuildVoiceChannel({ searchContext: searchContext6 }) {
|
|
let callback;
|
|
callback = void 0;
|
|
const navigation5 = useNavigation();
|
|
let c22064_0 = async (c31764_0) => {
|
|
let r12, r84, r87;
|
|
let c31764_1;
|
|
L22: {
|
|
L21: {
|
|
L16: {
|
|
let env32072;
|
|
const r14 = env32072 = {
|
|
$parent: env11014
|
|
};
|
|
c31764_1 = r14;
|
|
env32072[0] = c31764_0;
|
|
env32072[1] = void 0;
|
|
if (maybeOpenAgeGateForVoiceChannel(c31764_0.id)) {
|
|
break L22;
|
|
}
|
|
if (maybeOpenSpoilerGateForVoiceChannel(c31764_0.id)) {
|
|
break L22;
|
|
}
|
|
const needSubscriptionToAccess = getChannelRoleSubscriptionStatus(c31764_0.id).needSubscriptionToAccess;
|
|
const guildId = c31764_0.getGuildId();
|
|
env32072[1] = guildId;
|
|
if (guildId != null && shouldShowMembershipVerificationGate(guildId)) {
|
|
r12 = (0, (await import("../../../guild_member_verification/MemberVerificationModalActionCreators")).openMemberVerificationModal)(env32072[1], $mk118936(c31764_1));
|
|
break L16;
|
|
}
|
|
if (needSubscriptionToAccess) {
|
|
r84 = transitionTo(Routes.CHANNEL(c31764_0.guild_id, StaticChannelRoute.ROLE_SUBSCRIPTIONS));
|
|
} else {
|
|
handleVoiceOrStageChannelConnectPress(c31764_0);
|
|
r84 = void 0;
|
|
}
|
|
r87 = r84;
|
|
break L21;
|
|
}
|
|
return r12;
|
|
}
|
|
return r87;
|
|
}
|
|
};
|
|
callback = useCallback(function() {
|
|
return c22064_0.apply(this, arguments);
|
|
}, []);
|
|
return useCallback((a0) => {
|
|
const r3 = env11014;
|
|
const channel4 = ChannelStore.getChannel(a0);
|
|
if (channel4 == null) {
|
|
return null;
|
|
}
|
|
let env28054;
|
|
const r7 = {
|
|
type: SearchHistoryItemTypes.GUILD_VOICE_CHANNEL,
|
|
channelId: channel4.id
|
|
};
|
|
const r14 = env28054 = {
|
|
$parent: r3
|
|
};
|
|
env28054[0] = searchContext6;
|
|
env28054[1] = r7;
|
|
const type = searchContext6.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r14));
|
|
}
|
|
const parent = navigation5.getParent();
|
|
if (parent != null) {
|
|
parent.goBack();
|
|
}
|
|
performKeyboardAwareNavigation(() => callback(channel4));
|
|
}, [navigation5, callback, searchContext6]);
|
|
}
|
|
export function useOnPressSearchHistoryText({ searchContext: searchContext7 }) {
|
|
return useCallback((a0, a1) => {
|
|
let env28056;
|
|
let c28055_0 = a0;
|
|
const r3 = env11014;
|
|
const r8 = {
|
|
type: SearchHistoryItemTypes.TEXT,
|
|
text: a0,
|
|
tags: a1
|
|
};
|
|
const r12 = env28056 = {
|
|
$parent: r3
|
|
};
|
|
env28056[0] = searchContext7;
|
|
env28056[1] = r8;
|
|
const type = searchContext7.type;
|
|
if (!(SearchTypes.DMS !== type && SearchTypes.GUILD !== type)) {
|
|
delayUntilNavigationComplete($mk96657(r12));
|
|
}
|
|
SearchPlatformActionCreators.updateSearchQuery(searchContext7, (a0) => {
|
|
if (a1 != null) {
|
|
a0.setTags(a1);
|
|
}
|
|
a0.setTextInputValue(c28055_0);
|
|
});
|
|
SearchPlatformUtils.fetchInitialMessages(searchContext7);
|
|
if (a1 != null) {
|
|
a1.forEach((item) => {
|
|
if (item.type === SearchQueryTagTypes.COMPLETE) {
|
|
Tracking.trackSearchFilterAdd({
|
|
searchContext: searchContext7,
|
|
searchTokenType: item.searchTokenType,
|
|
location: SearchFilterAddLocations.SEARCH_HISTORY
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}, [searchContext7]);
|
|
}
|