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

163 lines
6.6 KiB
TypeScript

// Metro module 9989 (f9990).
import ReferencedMessageStore from "../../../replies/ReferencedMessageStore";
import RelationshipStore from "../../../../stores/RelationshipStore";
import UserStore from "../../../../stores/UserStore";
import { MessageTypes } from "../../../../Constants";
import { markPortalAlive } from "../../../../components_native/common/NativePortalView";
import { isAlertOrActionSheetOpen } from "../../../../components_native/chat/isAlertOrActionSheetOpen";
import { MessageReferenceTypes } from "../../../../_bundle/Module694";
import { isThumbnailAttachment, extractMediaFromAttachment, extractMediaSourcesFromEmbed, setMediaSourcePortal, extractMediaSourcesFromComponent, extractMediaSourcesFromMessage, flattenSource } from "../../../media_viewer/native/MediaSourceUtil";
import Linking from "../../../../lib/native/Linking";
import { asComponentId } from "../../../interaction_components/InteractionComponentTypes";
import { openMediaModal } from "../../../media_viewer/native/components/openMediaModal";
import { computeChannelName } from "../../../channel/useChannelName";
import { getChannelIcon } from "../../../../utils/native/ChannelUtils";
export function handleMessagesTapImage(a0) {
let r99, r134, length;
let initialIndex;
const tapImageData = a0.tapImageData;
const { index, type, layout, portal, embedIndex, componentId, componentMediaIndex, embedId } = tapImageData;
const { allowWithinModal, message, messageChannel, selectedChannelId, showContextName } = a0;
initialIndex = void 0;
if (portal != null) {
markPortalAlive(portal);
}
L61: {
if (!(allowWithinModal !== true && isAlertOrActionSheetOpen(selectedChannelId))) {
if (type !== "attachment" && type !== "embed" && type !== "sticker" && type !== "component") {
throw new Error(`Unsupported thumbnail type: ${type}`);
}
const type2 = message.type;
const THREAD_STARTER_MESSAGE = MessageTypes.THREAD_STARTER_MESSAGE;
let r27 = message;
if (type2 === THREAD_STARTER_MESSAGE) {
const messageReference = message.messageReference;
r27 = message;
if (messageReference != null) {
const message2 = ReferencedMessageStore.getMessageByReference(message.messageReference).message;
r27 = message2 ?? message;
}
}
const type3 = r27.messageReference?.type;
const FORWARD = MessageReferenceTypes.FORWARD;
let r26 = r27;
if (type3 === FORWARD) {
r26 = r27.messageSnapshots[0]?.message;
if (r26 == null) {
break L61;
}
}
const r81 = r27.attachments.filter((attachment) => !isThumbnailAttachment(attachment));
if (type === "attachment" && index < r81.length) {
const r83 = r81[index];
if (extractMediaFromAttachment(r83, r27, index, messageChannel.guild_id) == null && r83.url != null && r83.url !== "") {
Linking.openURL(r83.url);
return void 0;
}
}
L53: {
initialIndex = -1;
if (type === "embed" && embedIndex != null) {
const r160 = r26.embeds[index];
initialIndex = embedIndex;
const r169 = extractMediaSourcesFromEmbed(r27, r26, r160, index, messageChannel.guild_id);
const length2 = r169.length;
r99 = r169;
if (!(initialIndex < length2)) {
break L53;
}
setMediaSourcePortal(r169[initialIndex], portal);
r99 = r169;
} else {
if (type === "component") {
if (componentId == null) {
return null;
}
L44: {
if (embedId != null && embedId !== "") {
const r132 = r26.embeds.find((embed) => embed.id === embedId);
const r133 = r132 == null;
r134 = void 0;
if (r133) {
break L44;
}
r134 = r132.components;
} else {
r134 = r26.components;
}
}
if (r134 != null && r134.length !== 0) {
const r148 = extractMediaSourcesFromComponent(r27, r134, messageChannel.guild_id, asComponentId(componentId), componentMediaIndex);
if (r148 == null) {
return void 0;
}
const sources = r148.sources;
initialIndex = r148.initialIndex;
setMediaSourcePortal(sources[initialIndex], portal);
r99 = sources;
break L53;
}
return void 0;
}
const r29 = extractMediaSourcesFromMessage(r27, r26, messageChannel.guild_id);
const r98 = 0 < r29.length;
let r0 = 0;
r99 = r29;
if (r98) {
do {
const r103 = flattenSource(r29[r0]);
const r1 = r0;
if (r103 != null && r103.accessoryType === type) {
let mediaViewIndex = r103.mediaViewIndex;
if (mediaViewIndex == null) {
mediaViewIndex = r103.mediaIndex;
}
if (mediaViewIndex === index) {
if (r103.noCarousel) {
const r120 = [r29[r1]];
initialIndex = 0;
setMediaSourcePortal(r120[0], portal);
r99 = r120;
break;
}
initialIndex = r1;
setMediaSourcePortal(r29[r1], portal);
r99 = r29.filter((item, index) => {
const r10 = flattenSource(item);
const r12 = r10 != null && !r10.noCarousel;
if (r12 ? !r12 : initialIndex >= index) {
initialIndex = initialIndex - 1;
}
return r12;
});
break;
}
}
r0 = r1 + 1;
length = r29.length;
r99 = r29;
} while (r0 < length);
}
}
}
const disableDownload = r99.some((item) => {
const r9 = flattenSource(item, true);
return r9 != null && r9.disableDownload;
});
const initialSources = r99;
if (initialIndex !== -1) {
openMediaModal({
disableDownload,
initialSources,
initialIndex,
originViewOrOriginLayout: layout,
analyticsSource: "Channel",
channelId: messageChannel.id,
contextName: showContextName ? computeChannelName(messageChannel, UserStore, RelationshipStore, false) : void 0,
contextIcon: showContextName ? getChannelIcon(messageChannel) : void 0
});
}
}
}
}