/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { Menu } from "@webpack/common"; import { addChannelToCategory, canMoveChannelInDirection, categories, isPinned, moveChannel, removeChannelFromCategory } from "../data"; import { forceUpdate, PinOrder, settings } from "../index"; import { openCategoryModal } from "./CreateCategoryModal"; function createPinMenuItem(channelId: string) { const pinned = isPinned(channelId); return ( {!pinned && ( <> openCategoryModal(null, channelId)} /> { categories.map(category => ( addChannelToCategory(channelId, category.id).then(forceUpdate)} /> )) } )} {pinned && ( <> removeChannelFromCategory(channelId).then(forceUpdate)} /> { settings.store.pinOrder === PinOrder.Custom && canMoveChannelInDirection(channelId, -1) && ( moveChannel(channelId, -1).then(forceUpdate)} /> ) } { settings.store.pinOrder === PinOrder.Custom && canMoveChannelInDirection(channelId, 1) && ( moveChannel(channelId, 1).then(forceUpdate)} /> ) } )} ); } const GroupDMContext: NavContextMenuPatchCallback = (children, props) => { const container = findGroupChildrenByChildId("leave-channel", children); container?.unshift(createPinMenuItem(props.channel.id)); }; const UserContext: NavContextMenuPatchCallback = (children, props) => { const container = findGroupChildrenByChildId("close-dm", children); if (container) { const idx = container.findIndex(c => c?.props?.id === "close-dm"); container.splice(idx, 0, createPinMenuItem(props.channel.id)); } }; export const contextMenus = { "gdm-context": GroupDMContext, "user-context": UserContext };