1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-09 09:26:22 +00:00

FullSearchContext: Re-add Copy Author ID

This commit is contained in:
Nuckyz 2024-09-22 15:52:25 -03:00
parent 409f47bf24
commit 2ec5a92801
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 31 additions and 9 deletions

View file

@ -90,19 +90,20 @@ export function removeGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallba
* A helper function for finding the children array of a group nested inside a context menu based on the id(s) of its children
* @param id The id of the child. If an array is specified, all ids will be tried
* @param children The context menu children
* @param partialCheck Whether to check if the id is partially matched
*/
export function findGroupChildrenByChildId(id: string | string[], children: Array<ReactElement | null>): Array<ReactElement | null> | null {
export function findGroupChildrenByChildId(id: string | string[], children: Array<ReactElement | null>, partialCheck = false): Array<ReactElement | null> | null {
for (const child of children) {
if (child == null) continue;
if (Array.isArray(child)) {
const found = findGroupChildrenByChildId(id, child);
const found = findGroupChildrenByChildId(id, child, partialCheck);
if (found !== null) return found;
}
if (
(Array.isArray(id) && id.some(id => child.props?.id === id))
|| child.props?.id === id
(Array.isArray(id) && id.some(id => partialCheck ? child.props?.id?.includes(id) : child.props?.id === id))
|| partialCheck ? child.props?.id?.includes(id) : child.props?.id === id
) return children;
let nextChildren = child.props?.children;
@ -112,7 +113,7 @@ export function findGroupChildrenByChildId(id: string | string[], children: Arra
child.props.children = nextChildren;
}
const found = findGroupChildrenByChildId(id, nextChildren);
const found = findGroupChildrenByChildId(id, nextChildren, true);
if (found !== null) return found;
}
}

View file

@ -16,15 +16,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { migratePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { ChannelStore, Clipboard, ContextMenuApi, i18n, Menu, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
import type { MouseEvent } from "react";
const { useMessageMenu } = findByPropsLazy("useMessageMenu");
const IdIcon = findComponentByCodeLazy("M15.3 14.48c-.46.45-1.08.67-1.86.67h");
function MessageMenu({ message, channel, onHeightUpdate }) {
const canReport = message.author &&
@ -48,9 +49,25 @@ function MessageMenu({ message, channel, onHeightUpdate }) {
itemSrc: void 0,
itemSafeSrc: void 0,
itemTextContent: void 0,
isFullSearchContextMenu: true
});
}
const contextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
if (props?.isFullSearchContextMenu == null) return;
const group = findGroupChildrenByChildId("devmode-copy-id", children, true);
group?.push(
<Menu.MenuItem
id={`devmode-copy-id-${props.message.author.id}`}
label={i18n.Messages.COPY_ID_AUTHOR}
action={() => Clipboard.copy(props.message.author.id)}
icon={IdIcon}
/>
);
};
migratePluginSettings("FullSearchContext", "SearchReply");
export default definePlugin({
name: "FullSearchContext",
@ -65,7 +82,7 @@ export default definePlugin({
}
}],
handleContextMenu(event: MouseEvent, message: Message) {
handleContextMenu(event: React.MouseEvent, message: Message) {
const channel = ChannelStore.getChannel(message.channel_id);
if (!channel) return;
@ -78,5 +95,9 @@ export default definePlugin({
onHeightUpdate={contextMenuProps.onHeightUpdate}
/>
);
},
contextMenus: {
"message-actions": contextMenuPatch
}
});