Files
discord-decomp/modules/share/native/ShareScreen.tsx
T
2026-11-01 12:12:55 +02:00

337 lines
11 KiB
TypeScript

// Metro module 13038 (f13039).
import _asyncToGenerator from "../../../_bundle/_asyncToGenerator";
import _slicedToArray from "../../../_bundle/_slicedToArray";
import { useState, useMemo, useCallback, useRef, lazy } from "react";
import { View } from "react-native";
import { ChannelRecordBase, isGuildChannelType } from "../../../records/ChannelRecord";
import "../../../stores/ChannelStore";
import PermissionStore from "../../../stores/PermissionStore";
import { Permissions, MAX_UPLOAD_COUNT } from "../../../Constants";
import { MAX_DESTINATION_COUNT } from "../../forwarding/ForwardConstants";
import { UserRowModes } from "../../main_tabs_v2/native/shared_components/user_list/UserRowConstants";
import { jsx } from "react/jsx-runtime";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { isIOS, isAndroid } from "../../../utils/PlatformUtils";
import { intl, t } from "../../../intl/index.native";
import { getOrResolveChannelIdFromDestinationId } from "../formatResults";
import { isNotNullish } from "../../../utils/GlobalUtils";
import { showInformationToast } from "./ShareUtils";
import allSettled from "../../../_bundle/allSettled";
import MessageManager from "../../messages/MessageManager";
import { transitionToChannel } from "../../routing/transitionToChannel";
import Module8197 from "../../../_bundle/Module8197";
import { openAlert } from "../../../design/components/AlertModal/native/useAlertStore.native";
import ShareAttachments from "./ShareAttachments";
import ShareEmbed from "./ShareEmbed";
import { GenericHeaderTitle } from "../../main_tabs_v2/native/shared_components/HeaderShared";
function $mk116471($env) {
return function() {
let env31677 = {
$parent: $env
};
env31677[0] = (0, _asyncToGenerator)(function*(c32038_0) {
let c32038_2;
L12: {
let env32140;
c32038_2 = env31677;
const r9 = env32140 = {};
env32140[0] = void 0;
const r25 = env31677.$parent.$parent.$parent;
const channel = r25[9].getChannel(c32038_0);
env32140[0] = channel;
if (channel == null) {
break L12;
}
yield (0, r25[0])(r25[2][18]).sendShareMessage({
attachments: env31677.$parent[1],
channel,
comment: env31677.$parent.$parent[8]
});
const r54 = c32038_2;
const r55 = r54.$parent.$parent.$parent;
const r60 = (0, r55[1])(r55[2][20]);
const SHARE_MESSAGE_SENT = r55[11].SHARE_MESSAGE_SENT;
const r71 = r54.$parent;
r60.track(SHARE_MESSAGE_SENT, {
guild_id: env32140[0].guild_id,
channel_id: env32140[0].id,
channel_type: env32140[0].type,
num_attachments: r71[1].length,
attachment_mimetypes: r71[2]
});
return void 0;
}
return false;
});
return function() {
return env31677[0].apply(this, arguments);
};
};
}
function $mk116473($env) {
return (a0, a1) => $env[3][a1].status === "rejected";
}
function $mk116474($env) {
return () => import("./DestinationFailedAlertModal");
}
let useStyles;
let env8997 = {};
const getAttachmentsRestriction = function getAttachmentsRestriction(a0) {
if (a0 instanceof ChannelRecordBase && (0, isGuildChannelType)(a0.type)) {
return PermissionStore.can(Permissions.ATTACH_FILES, a0) ? void 0 : {
label: intl.string(t.P7yvbm)
};
}
};
useStyles = createStyles({
container: {
flex: 1,
backgroundColor: Module712.colors.BACKGROUND_BASE_LOWER
},
headerContainer: {
paddingHorizontal: isIOS() ? Module712.space.PX_16 : 0,
paddingVertical: isIOS() ? Module712.space.PX_8 : 0
}
});
export default function ShareScreen(props) {
let r24, r53, sendLabel;
let env20351 = {
$parent: env8997
};
const { appEntryKey, sharedContent } = props;
env20351[0] = sharedContent;
const onClose = props.onClose;
env20351[1] = onClose;
env20351[2] = void 0;
env20351[3] = void 0;
env20351[4] = void 0;
env20351[5] = void 0;
env20351[6] = void 0;
env20351[7] = void 0;
env20351[8] = void 0;
env20351[9] = void 0;
env20351[10] = void 0;
const styles = useStyles();
const r39 = _slicedToArray(useState(useMemo(() => {
const r4 = env20351[0];
const r6 = [];
if (r4.targetUserId != null) {
r6.push({
type: "user",
id: r4.targetUserId
});
}
if (r4.targetChannelId != null) {
r6.push({
type: "channel",
id: r4.targetChannelId
});
}
return r6;
}, [sharedContent])), 2);
const initialSelectedDestinations = r39[0];
env20351[2] = initialSelectedDestinations;
env20351[3] = r39[1];
const length = initialSelectedDestinations.length;
env20351[4] = length;
const disabled = sharedContent.attachments.length > MAX_UPLOAD_COUNT;
env20351[5] = disabled;
const callback = useCallback((a0) => {
(0, env20351[3])(a0);
}, []);
const r48 = _slicedToArray(useState(false), 2);
const isSending = r48[0];
env20351[6] = r48[1];
env20351[7] = useRef(isSending);
if (length <= 1) {
sendLabel = intl.string(t.TXNS7S);
r53 = dependencyMap;
r24 = require;
} else {
r53 = dependencyMap;
sendLabel = require(r53[14]).intl.formatToPlainString(require(r53[14]).t.jWtYUm, {
count: length
});
r24 = require;
}
let text = sharedContent.text;
if (text == null) {
text = "";
}
const r74 = _slicedToArray(useState(text), 2);
const text2 = r74[0];
env20351[8] = text2;
const setText = r74[1];
const r78 = importDefault(r53[15])(text2);
const embed = r78.embed;
env20351[9] = embed;
const isLoading = r78.isLoading;
env20351[10] = isLoading;
const callback2 = useCallback(async () => {
let c27402_0, c27402_1, c27402_2;
let c27402_3 = 0;
const r12 = env20351;
L25: {
L24: {
L23: {
try {
let env30607;
c27402_1 = r12;
const r42 = env30607 = {
$parent: r12
};
c27402_0 = r42;
env30607[0] = void 0;
env30607[1] = void 0;
env30607[2] = void 0;
env30607[3] = void 0;
env30607[4] = void 0;
env30607[5] = void 0;
env30607[6] = void 0;
if (env20351[7].current) {
break L25;
}
env20351[7].current = true;
(0, env20351[6])(true);
c27402_3 = 1;
env30607[0] = (await Promise.all(env20351[2].map(getOrResolveChannelIdFromDestinationId))).filter(isNotNullish);
if (env30607[0].length === 0) {
showInformationToast(intl.string(t.wFcUiF));
c27402_3 = 0;
(0, env20351[6])(false);
env20351[7].current = false;
break L24;
}
const r114 = c27402_0;
env30607[1] = env20351[0].attachments;
env30607[2] = env30607[1].map(({ mimeType }) => {
if (mimeType == null) {
mimeType = "unknown";
}
return mimeType;
});
env30607[3] = await allSettled(env30607[0].map($mk116471(r114)()));
const r157 = env30607[3].every((item) => item.status === "fulfilled");
const r158 = c27402_0;
if (r157) {
env30607[4] = env30607[0][0];
await MessageManager.fetchMessages({
channelId: env30607[4]
});
transitionToChannel(env30607[4], {
navigationReplace: true,
openTextInVoiceIfVoiceChannel: true
});
if (isAndroid()) {
Module8197.launchApp();
}
(0, env20351[1])();
c27402_3 = 0;
(0, env20351[6])(false);
env20351[7].current = false;
break L23;
}
env30607[5] = env20351[2].filter($mk116473(r158));
env30607[6] = lazy($mk116474(env20351.$parent));
openAlert("share-failed-alert-modal", (0, jsx)(env30607[6], {
title: intl.string(t.dA1gbw),
content: intl.formatToPlainString(t.thm88D, {
count: env30607[5].length
}),
failedDestinations: env30607[5]
}));
c27402_3 = 0;
(0, env20351[6])(false);
env20351[7].current = false;
} catch ($e) {
const r40 = $e;
let r7 = r40;
c27402_2 = r40;
if (c27402_3 !== 0) {
while (true) {
try {
const r281 = c27402_2;
c27402_3 = 0;
(0, env20351[6])(false);
env20351[7].current = false;
throw r281;
} catch (r278) {
r7 = r278;
c27402_2 = r278;
if (c27402_3 === 0) {
break;
}
}
}
}
throw r7;
}
return void 0;
}
return void 0;
}
return void 0;
}
}, [onClose, initialSelectedDestinations, sharedContent.attachments, text2]);
const memo = useMemo(() => {
let r15;
L5: {
const r4 = env20351[9];
if (r4 == null) {
const length = env20351[0].attachments.length;
r15 = null;
if (length === 0) {
break L5;
}
}
r15 = <>
{[<ShareAttachments attachments={env20351[0].attachments} isRevamp />, <ShareEmbed embed={r4?.embed} isLoadingEmbed={env20351[10]} isRevamp />]}
</>;
}
return r15;
}, [embed, isLoading, sharedContent.attachments]);
return <View style={styles.container}>
<View style={styles.headerContainer}>
{jsx(r24(r53[29]).Header, {
title: r24(r53[14]).intl.string(r24(r53[14]).t["MR7/kg"]),
headerTitle: (a0) => (0, jsx)(GenericHeaderTitle, {
title: a0.children,
subtitle: env20351[5] ? intl.formatToPlainString(t["qqyp/e"], {
limit: MAX_UPLOAD_COUNT
}) : env20351[4] >= MAX_DESTINATION_COUNT ? intl.formatToPlainString(t["3Fbkir"], {
count: MAX_DESTINATION_COUNT
}) : void 0,
subtitleColor: "text-feedback-warning",
variant: "redesign/heading-18/bold"
}),
headerTitleAlign: "center",
headerLeft: r24(r53[31]).isMetaQuest() ? void 0 : r24(r53[32]).getHeaderCloseButton(onClose),
headerStatusBarHeight: r24(r53[13]).isIOS() ? 0 : void 0
})}
</View>
{jsx(importDefault(r53[33]), {
rowMode: UserRowModes.TOGGLE,
initialSelectedDestinations,
onSelectedDestinationChange: callback,
getRowIsUnavailable: sharedContent.attachments.length > 0 ? getAttachmentsRestriction : void 0,
insetEnd: 0,
disableGradient: true,
disableStickySections: true,
disableSelection: length >= MAX_DESTINATION_COUNT || disabled,
disableLongPress: r24(r53[13]).isAndroid()
})}
{jsx(importDefault(r53[34]), {
text: text2,
setText,
preview: memo,
sendLabel,
canSend: length > 0 && !disabled,
isSending,
onSend: callback2,
disabled,
appEntryKey
})}
</View>;
};