diff --git a/src/utils/discord.css b/src/utils/discord.css index a7f95fbe6..12d15694b 100644 --- a/src/utils/discord.css +++ b/src/utils/discord.css @@ -7,18 +7,18 @@ **/ .vc-image-modal { - background: transparent!important; - box-shadow: none!important; + background: transparent !important; + box-shadow: none !important; display: flex; justify-content: center; align-items: center; - border-radius: 0 + border-radius: 0; } @media(width <= 485px) { .vc-image-modal { - display:relative; + display: relative; overflow: visible; - overflow: initial + overflow: initial; } } diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index 08de22ccd..fed5a5d86 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -21,8 +21,9 @@ import "./discord.css"; import { MessageObject } from "@api/MessageEvents"; import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common"; import { Channel, Guild, Message, User } from "discord-types/general"; +import { Except } from "type-fest"; -import { ImageModal, ImageModalItem, openModal } from "./modal"; +import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal"; /** * Open the invite modal @@ -111,24 +112,20 @@ export function sendMessage( } /** - * You must specify either height or width + * You must specify either height or width in the item */ -export function openImageModal(props: Omit): string { - return openModal(modalProps => ( - - )); +export function openImageModal(item: Except, mediaModalProps?: Omit) { + return openMediaModal({ + className: "vc-image-modal", + fit: "vc-position-inherit", + shouldAnimateCarousel: true, + items: [{ + type: "IMAGE", + original: item.original ?? item.url, + ...item, + }], + ...mediaModalProps + }); } export async function openUserProfile(id: string) { diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index 7459379ea..a11cb3cc5 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; +import { findByPropsLazy, findModuleId, proxyLazyWebpack, wreq } from "@webpack"; import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react"; import { LazyComponent } from "./react"; @@ -101,24 +101,39 @@ export const Modals = findByPropsLazy("ModalRoot", "ModalCloseButton") as { }>; }; -export interface ImageModalItem { - type: "IMAGE" | "VIDEO"; +export type MediaModalItem = { url: string; + type: "IMAGE" | "VIDEO"; + original?: string; + alt?: string; width?: number; height?: number; - original?: string; -} + animated?: boolean; + maxWidth?: number; + maxHeight?: number; +} & Record; -export type ImageModal = ComponentType<{ +export type MediaModalProps = { + location?: string; + contextKey?: string; + onCloseCallback?: () => void; className?: string; + items: MediaModalItem[]; + startingIndex?: number; + onIndexChange?: (...args: any[]) => void; fit?: string; - onClose?(): void; + shouldRedactExplicitContent?: boolean; shouldHideMediaOptions?: boolean; - shouldAnimate?: boolean; - items: ImageModalItem[]; -}>; + shouldAnimateCarousel?: boolean; +}; -export const ImageModal = findComponentByCodeLazy(".MEDIA_MODAL_CLOSE") as ImageModal; +export const openMediaModal: (props: MediaModalProps) => void = proxyLazyWebpack(() => { + const mediaModalKeyModuleId = findModuleId('"Zoomed Media Modal"'); + if (mediaModalKeyModuleId == null) return; + + const openMediaModalModule = wreq(findModuleId(mediaModalKeyModuleId, "modalKey:") as any); + return Object.values(openMediaModalModule).find(v => String(v).includes("modalKey:")); +}); export const ModalRoot = LazyComponent(() => Modals.ModalRoot); export const ModalHeader = LazyComponent(() => Modals.ModalHeader);