Files
discord-decomp/modules/messages/native/handlers/handleMessagesTapLink.tsx
T
2026-11-01 12:12:55 +02:00

345 lines
14 KiB
TypeScript

// Metro module 9504 (f9505).
import { getSection } from "../../../application_commands/ApplicationCommandIndexStore";
import ApplicationStore from "../../../applications/ApplicationStore";
import GuildAutomodMessageStore from "../../../guild_automod/GuildAutomodMessageStore";
import SummaryStore from "../../../summaries/SummaryStore";
import UserRecord from "../../../../records/UserRecord";
import ChannelStore from "../../../../stores/ChannelStore";
import InviteStore from "../../../../stores/InviteStore";
import MessageStore from "../../../../stores/MessageStore";
import UserStore from "../../../../stores/UserStore";
import { AnalyticsLocations, LinkingTypes, Routes } from "../../../../Constants";
import { AppLauncherRouteName } from "../../../app_launcher/native/AppLauncherNativeConstants";
import { StaticChannelRoute } from "../../../channel/ChannelConstants";
import { NotificationTypes } from "../../../push_notifications/PushNotificationConstants";
import { OpenThreadAnalyticsLocations } from "../../../threads/ThreadConstants";
import * as _MarkupReactLinkUtils from "../../../markup/MarkupReactLinkUtils";
import parseURL from "../../../../utils/native/parseURL";
import { isGuildScheduledEventInviteEmbed } from "../../../instant_invite/InviteTypeUtils";
import handleAcceptEventInstantInvite from "../../../guild_scheduled_events/native/handleAcceptEventInstantInvite";
import { GameProfileSources } from "../../../game_profile/GameProfileAnalyticUtils";
import * as _GameProfileActionCreators_native from "../../../game_profile/GameProfileActionCreators.native";
import { handleClick } from "../../../../utils/MaskedLinkUtils";
import { isAlertOrActionSheetOpen } from "../../../../components_native/chat/isAlertOrActionSheetOpen";
import showUserProfileActionSheet from "../../../user_profile/native/showUserProfileActionSheet";
import ActionSheetActionCreators from "../../../action_sheet/native/ActionSheetActionCreators";
import SelectedChannelActionCreators from "../../../../actions/SelectedChannelActionCreators";
import { watchStreamAndTransitionToStream } from "../../../../actions/StreamActionCreators";
import openPinnedMessages from "../openPinnedMessages";
import showChatGDMCustomizeActionSheet from "../../../group_dm/native/showChatGDMCustomizeActionSheet";
import { removeAutomodMessageNotice } from "../../../guild_automod/GuildAutomodMessageActionCreators";
import MessageActionCreators from "../../../../actions/MessageActionCreators";
import AnalyticsLocation from "../../../app_analytics/AnalyticsLocation";
import { isPrimaryEntryPointCommandMessage } from "../../../applications/ApplicationInteractionInfoUtils";
import { KeyboardTypes } from "../../../keyboard/native/KeyboardTypes";
import showExecutedApplicationCommandPopout from "../../../application_commands/native/showExecutedApplicationCommandPopout";
import { getUserAuthor } from "../../useMessageAuthor";
import { transitionTo } from "../../../routing/router_utils";
import { trackRoleSubscriptionPurchaseMessageTierClick } from "../../../guild_role_subscriptions/GuildRoleSubscriptionSystemMessageUtils";
import { openGuildHighlightNotificationForPush } from "../../../notifications/native/GuildHighlightsNotificationsActionCreators";
const handleMessagesTapURLLink = function handleMessagesTapURLLink(data, a1) {
let r3 = data.url != null && data.url !== "";
if (r3) {
const { url, node } = data;
const r1 = node == null;
let r2 = false;
if (!r1) {
const isLinkTrusted = _MarkupReactLinkUtils.isLinkTrusted(node);
r2 = false;
if (isLinkTrusted) {
const payload = parseURL(url).payload;
const type = payload.type;
const INVITE = LinkingTypes.INVITE;
r2 = false;
if (type === INVITE) {
const r31 = payload.inviteCode == null;
r2 = false;
if (!r31) {
const invite = InviteStore.getInvite(payload.inviteCode);
let r36 = invite == null || !isGuildScheduledEventInviteEmbed(invite);
if (!r36) {
handleAcceptEventInstantInvite(invite);
r36 = 0;
}
r2 = !r36;
}
}
}
}
if (!r2) {
const payload2 = parseURL(data.url).payload;
const type2 = payload2.type;
const GAME_PROFILE = LinkingTypes.GAME_PROFILE;
let r4 = false;
if (type2 === GAME_PROFILE) {
const gameId = payload2.gameId;
const r57 = a1 != null;
let sourceUserId = void 0;
if (r57) {
const r60 = data.messageId != null;
sourceUserId = void 0;
if (r60) {
const message = MessageStore.getMessage(a1, data.messageId);
sourceUserId = message == null ? void 0 : message.author.id;
}
}
_GameProfileActionCreators_native.default.openGameProfileModal({
gameId,
source: GameProfileSources.Deeplink,
sourceUserId,
gameProfileModalChecks: {
shouldOpenGameProfile: true,
gameId
}
});
r4 = true;
}
r2 = r4;
}
r3 = true;
if (!r2) {
handleClick({
href: data.url,
trusted: data.node != null && _MarkupReactLinkUtils.isLinkTrusted(data.node),
messageId: data.messageId,
channelId: a1
});
r3 = true;
}
}
return r3;
};
export { handleMessagesTapURLLink };
export function handleMessagesTapLink(a0) {
L90: {
const { allowWithinModal, chatInputRef, handleTransitionToThread, message, messageChannel, selectedChannelId } = a0;
const data = a0.tapLinkData.data;
if (!(allowWithinModal !== true && isAlertOrActionSheetOpen(selectedChannelId)) && !handleMessagesTapURLLink(data, messageChannel?.id) && data.action != null) {
switch (data.action) {
case "bindUserMenu":
showUserProfileActionSheet({
userId: data.userId,
channelId: data.messageChannelId,
messageId: data.messageId
});
break L90;
case "bindGuildMenu":
if (data.messageReference == null) {
return void 0;
}
const guild_id2 = data.messageReference.guild_id;
if (guild_id2 == null) {
return void 0;
}
ActionSheetActionCreators.openLazy(import("../../../guild_profile/native/components/GuildProfileActionSheet"), `GuildProfileActionSheet:${guild_id2}`, {
guildId: guild_id2
});
break L90;
case "bindJoinStream":
const stream = data.stream;
if (stream == null) {
return void 0;
}
SelectedChannelActionCreators.selectVoiceChannel(stream.channelId);
watchStreamAndTransitionToStream(stream);
break L90;
case "bindOpenPins":
openPinnedMessages(data.messageChannelId, "pinned-message-system-message");
break L90;
case "bindOpenGdmCustomizeActionSheet":
showChatGDMCustomizeActionSheet({
channelId: data.messageChannelId
});
break L90;
case "bindDismissMessage":
if (GuildAutomodMessageStore.getMessage(data.message?.id)?.isBlockedEdit) {
removeAutomodMessageNotice(data.message?.id);
break L90;
}
MessageActionCreators.dismissAutomatedMessage(data.message);
break L90;
case "bindTapUsername":
showUserProfileActionSheet({
userId: data.userId,
channelId: data.messageChannelId,
messageId: data.messageId,
sourceAnalyticsLocations: [AnalyticsLocation.USERNAME]
});
break L90;
case "bindTapCommandName":
if (message?.interaction != null && messageChannel != null) {
const user = UserStore.getUser(data.userId);
if (user == null) {
return void 0;
}
if (isPrimaryEntryPointCommandMessage(message)) {
if (message.applicationId == null) {
return void 0;
}
const channel2 = ChannelStore.getChannel(data.messageChannelId);
if (channel2 == null) {
return void 0;
}
const section = getSection({
channel: channel2,
type: "channel"
}, message.applicationId);
if (section.descriptor?.application != null) {
if (chatInputRef == null) {
break L90;
}
const current4 = chatInputRef.current;
if (current4 == null) {
break L90;
}
const isGuildInstalled = section.isGuildInstalled;
current4.openCustomKeyboard({
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
initiallyExpanded: true,
application: section.descriptor.application,
installOnDemand: isGuildInstalled ? !isGuildInstalled : !section.isUserInstalled
}
});
break L90;
}
if (chatInputRef == null) {
break L90;
}
const current3 = chatInputRef.current;
if (current3 == null) {
break L90;
}
current3.openCustomKeyboard({
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
initiallyExpanded: true,
applicationId: message.applicationId,
installOnDemand: true
}
});
break L90;
}
if (message?.author == null) {
break L90;
}
const r189 = {
author: getUserAuthor(message.interaction.user, messageChannel),
channelId: data.messageChannelId,
chatInputRef,
messageId: data.messageId,
user,
applicationUser: new UserRecord(message?.author),
guildId: null,
messageType: null
};
let guildId = messageChannel.getGuildId();
if (guildId == null) {
guildId = void 0;
}
r189.guildId = guildId;
r189.messageType = data.messageType;
showExecutedApplicationCommandPopout(r189);
break L90;
}
return void 0;
case "bindTapActivityText":
const application = ApplicationStore.getApplication(data.applicationUserId);
if (chatInputRef == null) {
break L90;
}
const current2 = chatInputRef.current;
if (current2 == null) {
break L90;
}
current2.openCustomKeyboard(application == null ? {
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
applicationId: data.applicationUserId,
initiallyExpanded: true
}
} : {
type: KeyboardTypes.APP_LAUNCHER,
context: {
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
application,
initiallyExpanded: true
}
});
break L90;
case "bindOpenThreadChannel":
const channel = ChannelStore.getChannel(data.threadId);
if (channel == null) {
break L90;
}
handleTransitionToThread(channel?.guild_id, channel.id, OpenThreadAnalyticsLocations.EMBED);
break L90;
case "bindJumpToMessage":
MessageActionCreators.jumpToMessage({
channelId: data.targetChannelId,
messageId: data.targetMessageId,
flash: true,
returnMessageId: data.messageId
});
break L90;
case "bindOpenRoleSubscriptionOverview":
transitionTo(Routes.CHANNEL(data.guildId, StaticChannelRoute.ROLE_SUBSCRIPTIONS));
trackRoleSubscriptionPurchaseMessageTierClick(data.guildId, data.channelId, data.messageId, data.roleSubscriptionListingId);
break L90;
case "bindUserSurvey":
const guild_id = ChannelStore.getChannel(data.message.channel_id)?.guild_id;
if (guild_id == null) {
break L90;
}
const notificationType = data.notificationType;
if (NotificationTypes.TRENDING_CONTENT_PUSH === notificationType) {
const { message: message2, notificationType: notificationType3 } = data;
const MESSAGE_EMBED = AnalyticsLocations.MESSAGE_EMBED;
let summary_id = SummaryStore.selectedSummary(data.message.channel_id)?.id;
if (summary_id == null) {
summary_id = "unknown";
}
openGuildHighlightNotificationForPush(guild_id, message2, notificationType3, MESSAGE_EMBED, {
summary_id
});
break L90;
}
if (NotificationTypes.TOP_MESSAGE_PUSH === notificationType) {
openGuildHighlightNotificationForPush(guild_id, data.message, data.notificationType, AnalyticsLocations.MESSAGE_EMBED);
break L90;
}
const r13 = import("../../../notifications/native/NotificationSurveyActionSheet");
let notificationType2 = data.notificationType;
if (notificationType2 == null) {
notificationType2 = NotificationTypes.TOP_MESSAGE_PUSH;
}
ActionSheetActionCreators.openLazy(r13, "NotificationSurvey", {
location: AnalyticsLocations.MESSAGE_EMBED,
messageId: data.message.id,
notificationType: notificationType2
});
break L90;
case "bindInsertText":
if (chatInputRef == null) {
break L90;
}
const current = chatInputRef.current;
if (current == null) {
break L90;
}
const text = data.text;
let addSpace = data.addSpace;
if (addSpace == null) {
addSpace = true;
}
current.insertText(text, null, addSpace);
break L90;
default:
}
}
}
}