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

207 lines
7.4 KiB
TypeScript

// Metro module 11081 (f11082).
import { useRef, useState, useMemo, useCallback, useEffect } from "react";
import { ActivityIndicator, Image as Image2, View, findNodeHandle } from "react-native";
import ThemeStore from "../../user_settings/ThemeStore";
import UserStore from "../../../stores/UserStore";
import SafetyHubStore from "../SafetyHubStore";
import { DEFAULT_MEDIA_MAX_HEIGHT, DEFAULT_MEDIA_MAX_WIDTH, VIDEO_PLACEHOLDER_FILENAME, VIDEO_PLACEHOLDER_HEIGHT, VIDEO_PLACEHOLDER_WIDTH } from "../SafetyHubConstants";
import { MessageTypes } from "../../../Constants";
import RowGenerator from "../../messages/native/renderer/RowGenerator";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import { useStateFromStores } from "../../../_bundle/Module589";
import { isThemeLight } from "../../../design/shared";
import Module11082 from "../../../_bundle/Module11082";
import Module11083 from "../../../_bundle/Module11083";
import { getSpoilerFlagsForAttachment } from "../SafetyHubUtils";
import { isImageFile, isVideoFile } from "../../messages/MediaFormatTesters";
import { openMediaModal } from "../../media_viewer/native/components/openMediaModal";
import Video from "../../../_bundle/Video_8143";
import Chat_android from "../../chat/native/Chat.android";
import ChatItem from "../../../components_native/chat/ChatItem";
import { createMessageRecord } from "../../messages/MessageRecordUtils";
import SnowflakeUtils from "../../../utils/SnowflakeUtils";
const rowGenerator = new RowGenerator();
const useStyles = createStyles({
dummyVideoAttachments: {
width: 0,
height: 0
}
});
export default function ClassificationEvidence(props) {
let r99, props2;
let ref, c18524_5, c18524_6, state3, setState3, id, memo;
const flaggedContent = props.flaggedContent;
const styles = useStyles();
const stateFromStores2 = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
ref = useRef(null);
const [state, setState] = useState(null);
const [state2, setState2] = useState({});
const r53 = useStateFromStores([ThemeStore], () => isThemeLight(ThemeStore.theme)) ? Image2.resolveAssetSource(Module11082) : Image2.resolveAssetSource(Module11083);
L11: {
c18524_5 = r53;
const r57 = flaggedContent[0];
c18524_6 = r57;
[state3, setState3] = useState(r57.attachments.length);
const stateFromStores = useStateFromStores([SafetyHubStore], () => SafetyHubStore.getUsername());
id = r57.id;
memo = useMemo(() => c18524_6.attachments.map((attachment) => {
let r29;
let filename = attachment.filename;
if (filename == null) {
filename = "";
}
const r9 = {
...attachment,
filename,
flags: getSpoilerFlagsForAttachment(attachment),
size: 0,
proxy_url: attachment.url
};
if (isImageFile(attachment.filename)) {
let width = state2[attachment.id]?.width;
if (width == null) {
width = DEFAULT_MEDIA_MAX_WIDTH;
}
let height = state2[attachment.id]?.height;
if (height == null) {
height = DEFAULT_MEDIA_MAX_HEIGHT;
}
r29 = {
...r9,
width,
height
};
} else {
r29 = isVideoFile(attachment.filename) ? {
...r9,
width: VIDEO_PLACEHOLDER_WIDTH,
height: VIDEO_PLACEHOLDER_HEIGHT,
proxy_url: c18524_5.uri,
filename: VIDEO_PLACEHOLDER_FILENAME
} : r9;
}
return r29;
}), [r57.attachments, state2, r53]);
const callback = useCallback(({ nativeEvent }) => {
const { index, layout } = nativeEvent;
openMediaModal({
initialIndex: index,
initialSources: memo.map((item, index) => {
const videoURI = isVideoFile(c18524_6.attachments[index].filename) ? item.url : void 0;
const thumbnail = isVideoFile(c18524_6.attachments[index].filename) ? {
width: VIDEO_PLACEHOLDER_WIDTH,
height: VIDEO_PLACEHOLDER_HEIGHT,
uri: c18524_5.uri
} : void 0;
let width = state2[item.id]?.width;
if (width == null) {
width = DEFAULT_MEDIA_MAX_WIDTH;
}
let height = state2[item.id]?.height;
if (height == null) {
height = DEFAULT_MEDIA_MAX_HEIGHT;
}
return {
uri: item.url,
videoURI,
thumbnail,
mediaIndex: index,
channelId: "1",
messageId: id,
width,
height,
accessoryType: "attachment",
attachmentId: item.id
};
}),
disableDownload: true,
disableMediaOverlayButton: true,
shareable: false,
originViewOrOriginLayout: layout
});
}, [memo, r57.attachments, id, state2, r53]);
const callback2 = useCallback((a0) => {
a0.reactTag = state;
}, [state]);
useEffect(() => {
c18524_6.attachments.filter((attachment) => isImageFile(attachment.filename)).map((item) => {
return new Promise((c32025_0, reject) => Image2.getSize(item.url, (a0, a1) => c32025_0({
width: a0,
height: a1
}), reject)).then((c31606_0) => setState2((prevState2) => {
const r0 = {
...prevState2
};
r0[item.id] = c31606_0;
return r0;
})).finally(() => setState3((prevState3) => prevState3 - 1));
});
}, [r57.attachments]);
useEffect(() => {
if (state3 === 0) {
setState(findNodeHandle(ref.current));
}
}, [state3]);
if (r57.content === "") {
const length = r57.attachments.length;
r99 = null;
if (length === 0) {
break L11;
}
}
if (state3 > 0) {
props2 = {
children: [<ActivityIndicator />, <View style={styles.dummyVideoAttachments}>
{r57.attachments.filter((attachment) => isVideoFile(attachment.filename)).map((item, index) => {
return <Video key={index} source={{
uri: item.url
}} onLoad={(c30347_0) => {
setState2((prevState2) => {
const r0 = {
...prevState2
};
const id2 = item.id;
r0[id2] = {
width: c30347_0.naturalSize.width,
height: c30347_0.naturalSize.height
};
return r0;
});
setState3((prevState3) => prevState3 - 1);
}} onError={() => setState3((prevState3) => prevState3 - 1)} />;
})}
</View>]
};
} else {
const children = [<Chat_android ref={ref} onTapImage={callback} inverted={false} />, ,];
const r116 = {
id: r57.id,
timestamp: new Date(SnowflakeUtils.extractTimestamp(r57.id)).toUTCString(),
channel_id: "1",
type: MessageTypes.DEFAULT,
author: null,
content: null,
attachments: null
};
let author = stateFromStores2;
if (author == null) {
author = {
id: "0",
avatar: null,
discriminator: "0000",
username: stateFromStores
};
}
r116.author = author;
r116.content = r57.content;
r116.attachments = memo;
children[1] = <ChatItem rowGenerator={rowGenerator} message={createMessageRecord(r116)} modifyRow={callback2} />;
props2 = {
children
};
}
r99 = <View {...props2} />;
}
return r99;
};