Plugin

FullSearchContext

Makes the message context menu in message search results have all options you'd expect

Utility
index.tsx
Download

Source

src/plugins/fullSearchContext/index.tsx
1import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
2import { migratePluginSettings } from "@api/Settings";
3import { Devs } from "@utils/constants";
4import { getIntlMessage } from "@utils/discord";
5import { NoopComponent } from "@utils/react";
6import definePlugin from "@utils/types";
7import { Message } from "@vencord/discord-types";
8import { filters, findByCodeLazy, waitFor } from "@webpack";
9import { ChannelStore, ContextMenuApi, UserStore } from "@webpack/common";
10
11const useMessageMenu = findByCodeLazy(".MESSAGE,commandTargetId:");
12
13interface CopyIdMenuItemProps {
14 id: string;
15 label: string;
16}
17
18let CopyIdMenuItem: (props: CopyIdMenuItemProps) => React.ReactElement | null = NoopComponent;
19waitFor(filters.componentByCode('"cannot copy null text"'), m => CopyIdMenuItem = m);
20
21function MessageMenu({ message, channel, onHeightUpdate }) {
22 const canReport = message.author &&
23 !(message.author.id === UserStore.getCurrentUser().id || message.author.system);
24
25 return useMessageMenu({
26 navId: "message-actions",
27 ariaLabel: getIntlMessage("MESSAGE_UTILITIES_A11Y_LABEL"),
28
29 message,
30 channel,
31 canReport,
32 onHeightUpdate,
33 onClose: () => ContextMenuApi.closeContextMenu(),
34
35 textSelection: "",
36 favoriteableType: null,
37 favoriteableId: null,
38 favoriteableName: null,
39 itemHref: void 0,
40 itemSrc: void 0,
41 itemSafeSrc: void 0,
42 itemTextContent: void 0,
43
44 isFullSearchContextMenu: true
45 });
46}
47
48interface MessageActionsProps {
49 message: Message;
50 isFullSearchContextMenu?: boolean;
51}
52
53const contextMenuPatch: NavContextMenuPatchCallback = (children, props: MessageActionsProps) => {
54 if (props?.isFullSearchContextMenu == null) return;
55
56 const group = findGroupChildrenByChildId("devmode-copy-id", children, true);
57 group?.push(
58 CopyIdMenuItem({ id: props.message.author.id, label: getIntlMessage("COPY_ID_AUTHOR") })
59 );
60};
61
62migratePluginSettings("FullSearchContext", "SearchReply");
63export default definePlugin({
64 name: "FullSearchContext",
65 description: "Makes the message context menu in message search results have all options you'd expect",
66 tags: ["Utility"],
67 authors: [Devs.Ven, Devs.Aria],
68
69 patches: [{
70 find: "Listbox navigator was given an unhandled action",
71 replacement: {
72 match: /this(?=\.handleContextMenu\(\i,\i\))/,
73 replace: "$self"
74 }
75 }],
76
77 handleContextMenu(event: React.MouseEvent, message: Message) {
78 const channel = ChannelStore.getChannel(message.channel_id);
79 if (!channel) return;
80
81 event.stopPropagation();
82
83 ContextMenuApi.openContextMenu(event, contextMenuProps =>
84 <MessageMenu
85 message={message}
86 channel={channel}
87 onHeightUpdate={contextMenuProps.onHeightUpdate}
88 />
89 );
90 },
91
92 contextMenus: {
93 "message-actions": contextMenuPatch
94 }
95});
96