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

Merge branch 'dev' into immediate-finds

This commit is contained in:
Nuckyz 2024-09-22 15:54:21 -03:00
commit 87e66354df
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 30 additions and 7 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,14 +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 { findProp } from "@webpack";
import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common";
import { findComponentByCode, findProp } from "@webpack";
import { ChannelStore, Clipboard, ContextMenuApi, i18n, Menu, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
const useMessageMenu = findProp("useMessageMenu");
const IdIcon = findComponentByCode("M15.3 14.48c-.46.45-1.08.67-1.86.67h");
function MessageMenu({ message, channel, onHeightUpdate }) {
const canReport = message.author &&
@ -47,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",
@ -77,5 +95,9 @@ export default definePlugin({
onHeightUpdate={contextMenuProps.onHeightUpdate}
/>
);
},
contextMenus: {
"message-actions": contextMenuPatch
}
});