diff --git a/plugins/NoAutoReplyMention/src/Settings.tsx b/plugins/NoAutoReplyMention/src/Settings.tsx index 0136c34..cc5f444 100644 --- a/plugins/NoAutoReplyMention/src/Settings.tsx +++ b/plugins/NoAutoReplyMention/src/Settings.tsx @@ -1,15 +1,14 @@ import { findByStoreName } from "@vendetta/metro"; import { NavigationNative, React, ReactNative, stylesheet } from "@vendetta/metro/common"; -import { storage } from "@vendetta/plugin"; import { useProxy } from "@vendetta/storage"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { Forms } from "@vendetta/ui/components"; -import { SettingsSchema } from "."; +import { settings, SettingsSchema } from "."; const UserStore = findByStoreName("UserStore"); const { ScrollView, TouchableOpacity, Image, FlatList } = ReactNative; -const { FormInput, FormDivider, FormText, FormIcon, FormRow, FormSection } = Forms; +const { FormInput, FormDivider, FormText, FormIcon, FormRow, FormSection, FormSwitchRow } = Forms; const styles = stylesheet.createThemedStyleSheet({ avatar: { @@ -32,15 +31,14 @@ function AddRow({ onFinish }: { onFinish: () => void }) { const [value, setValue] = React.useState(""); const onPressCallback = () => { - if (value && +value && UserStore.getUser(value) && !storage.exempted.includes(value)) { - storage.exempted = [...storage.exempted, value]; + if (!isNaN(parseInt(value)) && UserStore.getUser(value) && !settings.exempted.includes(value)) { + settings.exempted = [...settings.exempted, value]; setValue(""); } onFinish(); }; - return <> - + return ( } label={ void }) { )} /> - ; + ); } export default function Settings() { + useProxy(settings) as SettingsSchema; + const [shouldShowAdd, setShouldShowAdd] = React.useState(false); - const settings = useProxy(storage) as SettingsSchema; const navigation = NavigationNative.useNavigation(); React.useEffect(() => { @@ -73,18 +72,26 @@ export default function Settings() { return ( - + } + value={settings.isBlacklistMode} + onValueChange={(value: boolean) => settings.isBlacklistMode = value} + /> + {settings.exempted?.length > 0 && item} renderItem={({ item }) => { const user = UserStore.getUser(item); + if (!user) throw new Error("User not found/is not cached"); return (} trailing={ { - storage.exempted = storage.exempted.filter((id) => id !== item); + settings.exempted = settings.exempted.filter((id) => id !== item); }}> } @@ -92,7 +99,10 @@ export default function Settings() { }} ItemSeparatorComponent={FormDivider} />} - {shouldShowAdd && setShouldShowAdd(false)} />} + {shouldShowAdd && <> + + setShouldShowAdd(false)} /> + } ); diff --git a/plugins/NoAutoReplyMention/src/index.ts b/plugins/NoAutoReplyMention/src/index.ts index f65f59d..25cf330 100644 --- a/plugins/NoAutoReplyMention/src/index.ts +++ b/plugins/NoAutoReplyMention/src/index.ts @@ -6,17 +6,22 @@ import { storage } from "@vendetta/plugin"; import Settings from "./Settings"; export interface SettingsSchema { + isBlacklistMode: boolean; exempted: string[]; } +export const settings = storage as SettingsSchema; + const ReplyManager = findByProps("createPendingReply"); -storage.exempted ??= []; +settings.isBlacklistMode ??= false; +settings.exempted ??= []; export default new class NoAutoReplyMention { settings = Settings; onUnload = patcher.before("createPendingReply", ReplyManager, ([arg]) => { - arg.shouldMention &&= storage.exempted.includes(arg.message?.author?.id); + const isListed = settings.exempted.includes(arg.message?.author?.id); + arg.shouldMention &&= settings.isBlacklistMode ? !isListed : isListed; }); };