255 lines
8.9 KiB
TypeScript
255 lines
8.9 KiB
TypeScript
// Metro module 11133 (f11134).
|
|
import UserStore from "../../../../stores/UserStore";
|
|
import ApplicationAssetsStore, { FetchState } from "../../ApplicationAssetsStore";
|
|
import ApplicationStore from "../../ApplicationStore";
|
|
import { AppLauncherRouteName } from "../../../app_launcher/native/AppLauncherNativeConstants";
|
|
import { CodedLinkExtendedType } from "../../../messages/native/renderer/row_data/embeds/coded_links/CodedLinksConstants";
|
|
import { fetchApplication } from "../../ApplicationActionCreators";
|
|
import { getContentClassificationVisibility, ContentClassificationVisibility } from "../../../content_classification/ContentClassificationVisibility";
|
|
import getEmbedThemeColors from "../../../messages/native/renderer/row_data/embeds/getEmbedThemeColors";
|
|
import { intl, t } from "../../../../intl/index.native";
|
|
import { AppMessageEmbedDisplayType } from "../../../messages/native/renderer/row_data/embeds/coded_links/CodedLinksTypes";
|
|
import * as _AppLauncherUtils from "../../../app_launcher/utils/AppLauncherUtils";
|
|
import { fetchAssetIds, getAssetIds, getAssetImage } from "../../../../utils/ApplicationAssetUtils";
|
|
import { canLaunchFrame } from "../../../frames/utils/canLaunchFrame";
|
|
import { getPlayInContext } from "../utils/getPlayInContext";
|
|
import { getAppIconSrc, getAppGradientColors } from "./utils/nativeAppMessageEmbedUtil";
|
|
import { getUserBannerURL } from "../../../../utils/AvatarUtils";
|
|
import URLUtils from "../../../../utils/URLUtils";
|
|
import { joinOrStartActivityInChannel } from "./utils/joinOrStartActivityInChannel";
|
|
import AnalyticsLocation from "../../../app_analytics/AnalyticsLocation";
|
|
import { launchActivityInBotDM } from "../../../app_launcher/utils/AppLauncherPlayUtils";
|
|
import { CommandOrigin } from "../../../application_commands/ApplicationCommandTypes";
|
|
import FramesActionCreators_native from "../../../frames/FramesActionCreators.native";
|
|
import { getBestActiveInput } from "../../../../utils/native/ChatInputUtils";
|
|
import { KeyboardTypes } from "../../../keyboard/native/KeyboardTypes";
|
|
import { installApplication } from "../../../../utils/native/ApplicationUtils";
|
|
import { copy } from "../../../../utils/ClipboardUtils.native";
|
|
import { presentLinkCopied } from "../../../toast/native/ToastUtils";
|
|
import { assertNever } from "../../../../utils/GlobalUtils";
|
|
const _excluded = ["embedded_cover"];
|
|
let c7521_11 = 512;
|
|
export function getAppLinkGateResult({ appId, channel, message, theme }) {
|
|
let r30;
|
|
const application = ApplicationStore.getApplication(appId);
|
|
if (application == null) {
|
|
if (ApplicationStore.isFetchingApplication(appId) === false) {
|
|
fetchApplication(appId);
|
|
}
|
|
return {
|
|
state: "unavailable"
|
|
};
|
|
}
|
|
const contentClassificationVisibility = getContentClassificationVisibility(application.contentClassification, channel, UserStore.getCurrentUser()?.nsfwAllowed);
|
|
if (contentClassificationVisibility !== ContentClassificationVisibility.DISPLAY) {
|
|
const baseColors = getEmbedThemeColors(theme).baseColors;
|
|
const info = contentClassificationVisibility === ContentClassificationVisibility.BLOCK_UNDERAGE ? intl.string(t.LPOzxB) : intl.string(t.NIZyKq);
|
|
r30 = {
|
|
state: "blocked",
|
|
model: {
|
|
...baseColors,
|
|
displayType: AppMessageEmbedDisplayType.BLOCKED,
|
|
appId: "",
|
|
messageId: message.id,
|
|
title: null,
|
|
header: intl.string(t.bZBN64),
|
|
info,
|
|
tagline: null,
|
|
iconSrc: null,
|
|
staticBannerSrc: null,
|
|
bannerRatio: "bot",
|
|
actions: [],
|
|
embedUrl: null,
|
|
extendedType: CodedLinkExtendedType.APP_MESSAGE_EMBED,
|
|
gradientColors: [],
|
|
type: null,
|
|
headerText: null
|
|
}
|
|
};
|
|
} else {
|
|
r30 = {
|
|
state: "display",
|
|
app: application
|
|
};
|
|
}
|
|
return r30;
|
|
}
|
|
export function createAppMessageEmbed({ theme, embedUrl, message, app }) {
|
|
let r150, info;
|
|
const baseColors = getEmbedThemeColors(theme).baseColors;
|
|
const channel_id = message.channel_id;
|
|
const { id, name, bot, tags, maxParticipants, icon } = app;
|
|
const isEmbeddedApp = _AppLauncherUtils.isEmbeddedApp(app);
|
|
if (isEmbeddedApp) {
|
|
const applicationAssetFetchState = ApplicationAssetsStore.getApplicationAssetFetchState(id);
|
|
if (applicationAssetFetchState === FetchState.NOT_FETCHED) {
|
|
fetchAssetIds(id, _excluded);
|
|
return null;
|
|
}
|
|
if (applicationAssetFetchState === FetchState.FETCHING) {
|
|
return null;
|
|
}
|
|
}
|
|
const tagline = maxParticipants != null && maxParticipants > 0 ? intl.formatToPlainString(t.z8EAJW, {
|
|
count: maxParticipants
|
|
}) : intl.string(t.RjceQU);
|
|
const actions = [];
|
|
if (isEmbeddedApp) {
|
|
if (canLaunchFrame(app)) {
|
|
actions.push({
|
|
id: "play_frame",
|
|
label: intl.string(t.RscU7I)
|
|
});
|
|
} else {
|
|
const playInContext = getPlayInContext(id, channel_id);
|
|
const { instanceId, isCurrentlyInInstance } = playInContext;
|
|
if (playInContext.canLaunchInChannel) {
|
|
const r87 = intl.string(t.RscU7I);
|
|
actions.push({
|
|
id: "play_in_channel",
|
|
label: isCurrentlyInInstance ? intl.string(t.DPfdsq) : instanceId != null ? intl.string(t.VJlc0S) : r87,
|
|
disabled: isCurrentlyInInstance
|
|
});
|
|
} else {
|
|
actions.push({
|
|
id: "play_in_dm",
|
|
label: intl.string(t.JeK1Wg)
|
|
});
|
|
}
|
|
}
|
|
}
|
|
L28: {
|
|
info = tags.join(" ∙ ");
|
|
const { id: id2, bot: bot2 } = app;
|
|
if (_AppLauncherUtils.isEmbeddedApp(app)) {
|
|
let r133 = getAssetIds(id2, _excluded);
|
|
if (r133 == null) {
|
|
r133 = [];
|
|
}
|
|
const [r137] = r133;
|
|
const staticBannerSrc = r137 != null ? getAssetImage(id2, r137, c7521_11) : null;
|
|
if (staticBannerSrc != null) {
|
|
r150 = {
|
|
bannerRatio: "activity",
|
|
staticBannerSrc
|
|
};
|
|
break L28;
|
|
}
|
|
}
|
|
if (bot2 != null) {
|
|
const userBannerURL = getUserBannerURL({
|
|
id: bot2.id,
|
|
banner: bot2.banner,
|
|
size: 512,
|
|
canAnimate: false
|
|
});
|
|
r150 = userBannerURL != null ? {
|
|
bannerRatio: "bot",
|
|
staticBannerSrc: userBannerURL
|
|
} : {
|
|
bannerRatio: "bot",
|
|
staticBannerSrc: null
|
|
};
|
|
} else {
|
|
r150 = {
|
|
bannerRatio: "bot",
|
|
staticBannerSrc: null
|
|
};
|
|
}
|
|
}
|
|
const iconSrc = icon != null ? getAppIconSrc(id, icon, bot) : null;
|
|
let r158 = iconSrc;
|
|
if (r158 == null) {
|
|
r158 = r150.staticBannerSrc;
|
|
}
|
|
if (r158 == null) {
|
|
r158 = void 0;
|
|
}
|
|
return {
|
|
...baseColors,
|
|
...r150,
|
|
displayType: AppMessageEmbedDisplayType.DISPLAY,
|
|
appId: app.id,
|
|
messageId: message.id,
|
|
title: null,
|
|
header: name,
|
|
info,
|
|
tagline,
|
|
iconSrc,
|
|
actions,
|
|
embedUrl,
|
|
extendedType: CodedLinkExtendedType.APP_MESSAGE_EMBED,
|
|
gradientColors: getAppGradientColors(r158),
|
|
type: null,
|
|
headerText: null
|
|
};
|
|
}
|
|
export function handleTapAppMessageEmbed(a0) {
|
|
const application = ApplicationStore.getApplication(a0.appId);
|
|
const r19 = URLUtils.toURLSafe(a0.embedUrl);
|
|
let referrerId = r19 == null ? void 0 : r19.searchParams.get("referrer_id");
|
|
if (referrerId == null) {
|
|
referrerId = a0.message.author.id;
|
|
}
|
|
let customId = r19 == null ? void 0 : r19.searchParams.get("custom_id");
|
|
if (customId == null) {
|
|
customId = void 0;
|
|
}
|
|
const actionId = a0.actionId;
|
|
if (actionId === "play_in_channel") {
|
|
joinOrStartActivityInChannel({
|
|
appId: a0.appId,
|
|
channelId: a0.message.channel_id,
|
|
analyticsLocations: [AnalyticsLocation.APP_MESSAGE_EMBED],
|
|
referrerId,
|
|
customId
|
|
});
|
|
} else if (actionId === "play_in_dm") {
|
|
if (application?.bot == null) {
|
|
return void 0;
|
|
}
|
|
launchActivityInBotDM({
|
|
appId: a0.appId,
|
|
botId: application.bot.id,
|
|
analyticsLocations: [AnalyticsLocation.APP_MESSAGE_EMBED],
|
|
commandOrigin: CommandOrigin.APP_MESSAGE_EMBED,
|
|
referrerId,
|
|
customId
|
|
});
|
|
} else if (actionId === "play_frame") {
|
|
FramesActionCreators_native.launchFrame({
|
|
applicationId: a0.appId
|
|
});
|
|
} else if (actionId === "view_in_app_launcher") {
|
|
const bestActiveInput = getBestActiveInput();
|
|
if (bestActiveInput != null) {
|
|
bestActiveInput.openCustomKeyboard({
|
|
type: KeyboardTypes.APP_LAUNCHER,
|
|
context: {
|
|
initialRouteName: AppLauncherRouteName.APPLICATION_VIEW,
|
|
initiallyExpanded: true,
|
|
applicationId: a0.appId,
|
|
referrerId,
|
|
customId
|
|
}
|
|
});
|
|
}
|
|
} else if (actionId === "add_app") {
|
|
if (application == null) {
|
|
return void 0;
|
|
}
|
|
installApplication({
|
|
applicationId: application.id,
|
|
customInstallUrl: application.customInstallUrl,
|
|
installParams: application.installParams,
|
|
integrationTypesConfig: application.integrationTypesConfig,
|
|
source: "app_message_embed"
|
|
});
|
|
} else if (actionId === "link_copied") {
|
|
copy(a0.embedUrl);
|
|
presentLinkCopied();
|
|
} else {
|
|
assertNever(a0.actionId);
|
|
}
|
|
}
|