From 081df6beb79a48ed970aaca7a5dde852651a6d61 Mon Sep 17 00:00:00 2001
From: Vendicated <vendicated@riseup.net>
Date: Tue, 28 Mar 2023 18:56:12 +0200
Subject: Fix SilentMessage/SilentTyping toggles showing in wrong sections

Closes #656
---
 src/plugins/silentMessageToggle.tsx | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'src/plugins/silentMessageToggle.tsx')

diff --git a/src/plugins/silentMessageToggle.tsx b/src/plugins/silentMessageToggle.tsx
index 8d33f81..3151e5c 100644
--- a/src/plugins/silentMessageToggle.tsx
+++ b/src/plugins/silentMessageToggle.tsx
@@ -22,7 +22,11 @@ import { Devs } from "@utils/constants";
 import definePlugin from "@utils/types";
 import { Button, ButtonLooks, ButtonWrapperClasses, React, Tooltip } from "@webpack/common";
 
-function SilentMessageToggle() {
+function SilentMessageToggle(chatBoxProps: {
+    type: {
+        analyticsName: string;
+    };
+}) {
     const [enabled, setEnabled] = React.useState(false);
 
     React.useEffect(() => {
@@ -37,6 +41,8 @@ function SilentMessageToggle() {
         return () => void removePreSendListener(listener);
     }, [enabled]);
 
+    if (chatBoxProps.type.analyticsName !== "normal") return null;
+
     return (
         <Tooltip text="Toggle Silent Message">
             {tooltipProps => (
@@ -78,7 +84,7 @@ export default definePlugin({
             find: ".activeCommandOption",
             replacement: {
                 match: /"gift"\)\);(?<=(\i)\.push.+?disabled:(\i),.+?)/,
-                replace: (m, array, disabled) => `${m}${disabled}||${array}.push($self.SilentMessageToggle());`
+                replace: (m, array, disabled) => `${m};try{${disabled}||${array}.push($self.SilentMessageToggle(arguments[0]));}catch{}`
             }
         }
     ],
-- 
cgit 

