From 8156840270af6154de6af4dbc0c16d337d4c9cea Mon Sep 17 00:00:00 2001 From: Benjii <56143265+Accentaro@users.noreply.github.com> Date: Tue, 19 May 2026 13:44:29 +0100 Subject: [PATCH] hide dm addition (user request) (#1081) * address gemini * Update src/equicordplugins/hideMessages/index.tsx Happy Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * update patches --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: thororen <78185467+thororen1234@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/equicordplugins/hideMessages/index.tsx | 115 ++++++++++++++++++++- 1 file changed, 111 insertions(+), 4 deletions(-) diff --git a/src/equicordplugins/hideMessages/index.tsx b/src/equicordplugins/hideMessages/index.tsx index 425eaa4d9..c33cf2fdb 100644 --- a/src/equicordplugins/hideMessages/index.tsx +++ b/src/equicordplugins/hideMessages/index.tsx @@ -6,11 +6,28 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { definePluginSettings } from "@api/Settings"; +import ErrorBoundary from "@components/ErrorBoundary"; import { EyeIcon } from "@components/Icons"; import { EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { Message } from "@vencord/discord-types"; -import { ChannelStore, FluxDispatcher, Menu } from "@webpack/common"; +import { Channel, Message } from "@vencord/discord-types"; +import { ChannelStore, Clickable, FluxDispatcher, Menu, Tooltip } from "@webpack/common"; + +interface UserContextProps { + channel?: Channel; +} + +interface PrivateChannelsListInstance { + forceUpdate(callback?: () => void): void; +} + +const hiddenDmIds = new Set(); +let privateChannelsListInstance: PrivateChannelsListInstance | null = null; +let showHiddenDms = false; + +function notifyHiddenDmsUpdate() { + privateChannelsListInstance?.forceUpdate(); +} const hideMessage = (messageId: string, channelId: string) => { FluxDispatcher.dispatch({ @@ -21,6 +38,17 @@ const hideMessage = (messageId: string, channelId: string) => { }); }; +function toggleDm(channelId: string) { + if (hiddenDmIds.has(channelId)) { + hiddenDmIds.delete(channelId); + if (!hiddenDmIds.size) showHiddenDms = false; + } else { + hiddenDmIds.add(channelId); + } + + notifyHiddenDmsUpdate(); +} + const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }: { message: Message; }) => { const group = findGroupChildrenByChildId("copy-text", children); if (!group) return; @@ -35,6 +63,24 @@ const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }: { m )); }; +const userCtxPatch: NavContextMenuPatchCallback = (children, { channel }: UserContextProps) => { + if (!channel?.isDM()) return; + + const group = findGroupChildrenByChildId("close-dm", children); + if (!group) return; + + const hidden = hiddenDmIds.has(channel.id); + + group.splice(group.findIndex(c => c?.props?.id === "close-dm"), 0, ( + toggleDm(channel.id)} + /> + )); +}; + const settings = definePluginSettings({ hidePopoverButton: { type: OptionType.BOOLEAN, @@ -45,14 +91,75 @@ const settings = definePluginSettings({ export default definePlugin({ name: "HideMessages", - description: "A plugin to temporarily hide messages until you restart.", + description: "Temporarily hide messages and DMs until you restart.", dependencies: ["MessagePopoverAPI"], tags: ["Chat", "Utility"], authors: [EquicordDevs.yash], + patches: [ + { + find: '"dm-quick-launcher"===', + replacement: [ + { + match: /render\(\)\{/, + replace: "$&this.props.privateChannelIds=$self.filterPrivateChannelIds(this.props.privateChannelIds,this);" + }, + { + match: /renderRow=\i=>\{/, + replace: "$&this.props.privateChannelIds=$self.filterPrivateChannelIds(this.props.privateChannelIds,this);" + }, + { + match: /renderDM=\(\i,\i\)=>\{/, + replace: "$&this.props.privateChannelIds=$self.filterPrivateChannelIds(this.props.privateChannelIds,this);" + }, + { + match: /#{intl::DIRECT_MESSAGES}\)\}\),/, + replace: "$&$self.renderHiddenMessagesToggle()," + } + ] + } + ], contextMenus: { - "message": messageCtxPatch + "message": messageCtxPatch, + "user-context": userCtxPatch }, settings, + stop() { + hiddenDmIds.clear(); + showHiddenDms = false; + notifyHiddenDmsUpdate(); + privateChannelsListInstance = null; + }, + filterPrivateChannelIds(privateChannelIds: string[], instance?: PrivateChannelsListInstance) { + privateChannelsListInstance = instance ?? privateChannelsListInstance; + return showHiddenDms ? privateChannelIds : privateChannelIds.filter(id => !hiddenDmIds.has(id)); + }, + renderHiddenMessagesToggle: ErrorBoundary.wrap(() => { + const hasHiddenDms = hiddenDmIds.size > 0; + const label = !hasHiddenDms ? "No Hidden DMs" : showHiddenDms ? "Hide Hidden DMs" : "Show Hidden DMs"; + + return ( + + {tooltipProps => ( + { + event.preventDefault(); + event.stopPropagation(); + if (!hasHiddenDms) return; + showHiddenDms = !showHiddenDms; + notifyHiddenDmsUpdate(); + }} + > + + + )} + + ); + }, { noop: true }), messagePopoverButton: { icon: EyeIcon, render(message: Message) {