diff --git a/src/api/ContextMenu.ts b/src/api/ContextMenu.ts index bed38d7a..fd8c7e10 100644 --- a/src/api/ContextMenu.ts +++ b/src/api/ContextMenu.ts @@ -92,7 +92,7 @@ export function removeGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallba * @param children The context menu children * @param matchSubstring Whether to check if the id is a substring of the child id */ -export function findGroupChildrenByChildId(id: string | string[], children: Array, matchSubstring = false): Array | null { +export function findGroupChildrenByChildId(id: string | string[], children: Array, matchSubstring = false): Array | null { for (const child of children) { if (child == null) continue; diff --git a/src/plugins/fullSearchContext/index.tsx b/src/plugins/fullSearchContext/index.tsx index 58a83ec0..193e69f1 100644 --- a/src/plugins/fullSearchContext/index.tsx +++ b/src/plugins/fullSearchContext/index.tsx @@ -19,13 +19,21 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { migratePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; +import { NoopComponent } from "@utils/react"; import definePlugin from "@utils/types"; -import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { ChannelStore, Clipboard, ContextMenuApi, i18n, Menu, UserStore } from "@webpack/common"; +import { filters, findByPropsLazy, waitFor } from "@webpack"; +import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common"; import { Message } from "discord-types/general"; const { useMessageMenu } = findByPropsLazy("useMessageMenu"); -const IdIcon = findComponentByCodeLazy("M15.3 14.48c-.46.45-1.08.67-1.86.67h"); + +interface CopyIdMenuItemProps { + id: string; + label: string; +} + +let CopyIdMenuItem: (props: CopyIdMenuItemProps) => React.ReactElement | null = NoopComponent; +waitFor(filters.componentByCode('"devmode-copy-id-".concat'), m => CopyIdMenuItem = m); function MessageMenu({ message, channel, onHeightUpdate }) { const canReport = message.author && @@ -54,17 +62,17 @@ function MessageMenu({ message, channel, onHeightUpdate }) { }); } -const contextMenuPatch: NavContextMenuPatchCallback = (children, props) => { +interface MessageActionsProps { + message: Message; + isFullSearchContextMenu?: boolean; +} + +const contextMenuPatch: NavContextMenuPatchCallback = (children, props: MessageActionsProps) => { if (props?.isFullSearchContextMenu == null) return; const group = findGroupChildrenByChildId("devmode-copy-id", children, true); group?.push( - Clipboard.copy(props.message.author.id)} - icon={IdIcon} - /> + CopyIdMenuItem({ id: props.message.author.id, label: i18n.Messages.COPY_ID_AUTHOR }) ); };