aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-07-08 03:30:16 +0200
committerV <vendicated@riseup.net>2023-07-08 03:30:16 +0200
commit7cd1d4c60f417f47a7badbae698f9f3ed4cfbf41 (patch)
treee1566c5aa17ac4ff5c7c23f7080b1cc67e3361a4 /src/plugins
parent2a318e390e77f8269fcba45ab9a0fd7008ca8d0a (diff)
downloadVencord-7cd1d4c60f417f47a7badbae698f9f3ed4cfbf41.tar.gz
Vencord-7cd1d4c60f417f47a7badbae698f9f3ed4cfbf41.tar.bz2
Vencord-7cd1d4c60f417f47a7badbae698f9f3ed4cfbf41.zip
translate: Add context menu item; fix MLE compatibility
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/translate/TranslationAccessory.tsx3
-rw-r--r--src/plugins/translate/index.tsx25
2 files changed, 27 insertions, 1 deletions
diff --git a/src/plugins/translate/TranslationAccessory.tsx b/src/plugins/translate/TranslationAccessory.tsx
index 4f46e4b..72b3594 100644
--- a/src/plugins/translate/TranslationAccessory.tsx
+++ b/src/plugins/translate/TranslationAccessory.tsx
@@ -44,6 +44,9 @@ export function TranslationAccessory({ message }: { message: Message; }) {
const [translation, setTranslation] = useState<TranslationValue>();
useEffect(() => {
+ // Ignore MessageLinkEmbeds messages
+ if ((message as any).vencordEmbeddedBy) return;
+
TranslationSetters.set(message.id, setTranslation);
return () => void TranslationSetters.delete(message.id);
diff --git a/src/plugins/translate/index.tsx b/src/plugins/translate/index.tsx
index d71b2da..3007032 100644
--- a/src/plugins/translate/index.tsx
+++ b/src/plugins/translate/index.tsx
@@ -18,19 +18,39 @@
import "./styles.css";
+import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
import { addAccessory, removeAccessory } from "@api/MessageAccessories";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { addButton, removeButton } from "@api/MessagePopover";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
-import { ChannelStore } from "@webpack/common";
+import { ChannelStore, Menu } from "@webpack/common";
import { settings } from "./settings";
import { TranslateChatBarIcon, TranslateIcon } from "./TranslateIcon";
import { handleTranslate, TranslationAccessory } from "./TranslationAccessory";
import { translate } from "./utils";
+const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }) => () => {
+ if (!message.content) return;
+
+ const group = findGroupChildrenByChildId("copy-text", children);
+ if (!group) return;
+
+ group.splice(group.findIndex(c => c?.props?.id === "copy-text") + 1, 0, (
+ <Menu.MenuItem
+ id="vc-trans"
+ label="Translate"
+ icon={TranslateIcon}
+ action={async () => {
+ const trans = await translate("received", message.content);
+ handleTranslate(message.id, trans);
+ }}
+ />
+ ));
+};
+
export default definePlugin({
name: "Translate",
description: "Translate messages with Google Translate",
@@ -53,6 +73,8 @@ export default definePlugin({
start() {
addAccessory("vc-translation", props => <TranslationAccessory message={props.message} />);
+ addContextMenuPatch("message", messageCtxPatch);
+
addButton("vc-translate", message => {
if (!message.content) return null;
@@ -78,6 +100,7 @@ export default definePlugin({
stop() {
removePreSendListener(this.preSend);
+ removeContextMenuPatch("message", messageCtxPatch);
removeButton("vc-translate");
removeAccessory("vc-translation");
},