ViewRaw: add message context menu option (#3990)

This commit is contained in:
BoatFloater 2026-04-18 07:39:47 +09:00 • committed by GitHub
parent 39044cd8e9
commit 51b4748ba7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings";
import { CodeBlock } from "@components/CodeBlock";
import { Divider } from "@components/Divider";
@ -124,31 +124,36 @@ const settings = definePluginSettings({
{ label: "Left Click to view the raw content.", value: "Left", default: true },
{ label: "Right click to view the raw content.", value: "Right" }
]
},
messageContextMenu: {
description: "Show in message context menu",
type: OptionType.BOOLEAN,
default: false
}
});
function MakeContextCallback(name: "Guild" | "Role" | "User" | "Channel"): NavContextMenuPatchCallback {
function MakeContextCallback(name: "Guild" | "Role" | "User" | "Channel" | "Message"): NavContextMenuPatchCallback {
return (children, props) => {
const value = props[name.toLowerCase()];
if (!value) return;
if (props.label === getIntlMessage("CHANNEL_ACTIONS_MENU_LABEL")) return; // random shit like notification settings
const isMessage = name === "Message";
if (isMessage && !settings.store.messageContextMenu) return;
const lastChild = children.at(-1);
if (lastChild?.key === "developer-actions") {
const p = lastChild.props;
if (!Array.isArray(p.children))
p.children = [p.children];
children = p.children;
}
// typescript parser goes crazy if this is inline
const id = `vc-view-${name.toLowerCase()}-raw`;
children.splice(-1, 0,
const action = isMessage
? () => openViewRawModalMessage(value)
: () => openViewRawModal(JSON.stringify(value, null, 4), name);
const devContainer = findGroupChildrenByChildId(`devmode-copy-id-${value.id}`, children);
(devContainer ?? children).splice(-1, 0,
<Menu.MenuItem
id={id}
label="View Raw"
action={() => openViewRawModal(JSON.stringify(value, null, 4), name)}
action={action}
icon={CopyIcon}
/>
);
@ -186,7 +191,8 @@ export default definePlugin({
"thread-context": MakeContextCallback("Channel"),
"gdm-context": MakeContextCallback("Channel"),
"user-context": MakeContextCallback("User"),
"dev-context": devContextCallback
"dev-context": devContextCallback,
"message": MakeContextCallback("Message"),
},
messagePopoverButton: {