diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index e13da353..e3373930 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -18,6 +18,7 @@ import "./messageLogger.css"; +import { addContextMenuPatch, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu"; import { Settings } from "@api/settings"; import { disableStyle, enableStyle } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; @@ -25,7 +26,7 @@ import { Devs } from "@utils/constants"; import Logger from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy, findLazy } from "@webpack"; -import { moment, Parser, Timestamp, UserStore } from "@webpack/common"; +import { FluxDispatcher, Menu, moment, Parser, Timestamp, UserStore } from "@webpack/common"; import overlayStyle from "./deleteStyleOverlay.css?managed"; import textStyle from "./deleteStyleText.css?managed"; @@ -43,20 +44,48 @@ function addDeleteStyle() { } } +const MENU_ITEM_ID = "message-logger-remove-history"; +const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) => { + const { message } = props; + const { deleted, editHistory, id, channel_id } = message; + + if (!deleted && !editHistory?.length) return; + if (children.some(c => c?.props?.id === MENU_ITEM_ID)) return; + + children.push(( +