Plugin
FullSearchContext
Makes the message context menu in message search results have all options you'd expect
1
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";2
import { migratePluginSettings } from "@api/Settings";3
import { Devs } from "@utils/constants";4
import { getIntlMessage } from "@utils/discord";5
import { NoopComponent } from "@utils/react";6
import definePlugin from "@utils/types";7
import { Message } from "@vencord/discord-types";8
import { filters, findByCodeLazy, waitFor } from "@webpack";9
import { ChannelStore, ContextMenuApi, UserStore } from "@webpack/common";10
11
const useMessageMenu = findByCodeLazy(".MESSAGE,commandTargetId:");12
13
interface CopyIdMenuItemProps {14
id: string;15
label: string;16
}17
18
let CopyIdMenuItem: (props: CopyIdMenuItemProps) => React.ReactElement | null = NoopComponent;19
waitFor(filters.componentByCode(039;"cannot copy null text"039;), m => CopyIdMenuItem = m);20
21
function 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: true45
});46
}47
48
interface MessageActionsProps {49
message: Message;50
isFullSearchContextMenu?: boolean;51
}52
53
const 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
62
migratePluginSettings("FullSearchContext", "SearchReply");63
export default definePlugin({64
name: "FullSearchContext",65
description: "Makes the message context menu in message search results have all options you039;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
<MessageMenu85
message={message}86
channel={channel}87
onHeightUpdate={contextMenuProps.onHeightUpdate}88
/>89
);90
},91
92
contextMenus: {93
"message-actions": contextMenuPatch94
}95
});96