From c304668b9bb5d7d74e1865fbe3be29dcdd827f0d Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:34:10 +0800 Subject: [PATCH] feat(NoAutoReplyMention): exempt users --- plugins/NoAutoReplyMention/src/Settings.tsx | 99 +++++++++++++++++++++ plugins/NoAutoReplyMention/src/index.ts | 23 ++++- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 plugins/NoAutoReplyMention/src/Settings.tsx diff --git a/plugins/NoAutoReplyMention/src/Settings.tsx b/plugins/NoAutoReplyMention/src/Settings.tsx new file mode 100644 index 0000000..0136c34 --- /dev/null +++ b/plugins/NoAutoReplyMention/src/Settings.tsx @@ -0,0 +1,99 @@ +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 "."; + +const UserStore = findByStoreName("UserStore"); + +const { ScrollView, TouchableOpacity, Image, FlatList } = ReactNative; +const { FormInput, FormDivider, FormText, FormIcon, FormRow, FormSection } = Forms; + +const styles = stylesheet.createThemedStyleSheet({ + avatar: { + height: 36, + width: 36, + borderRadius: 18, + }, + button: { + marginRight: 12, + } +}); + +function AddButton({ callback }: { callback: () => void }) { + return + ADD + ; +} + +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]; + setValue(""); + } + onFinish(); + }; + + return <> + + } + label={ setValue(value.replace(/[^0-9]/g, "").trim())} + returnKeyType="done" + />} + trailing={( + + + + )} + /> + ; +} + +export default function Settings() { + const [shouldShowAdd, setShouldShowAdd] = React.useState(false); + const settings = useProxy(storage) as SettingsSchema; + const navigation = NavigationNative.useNavigation(); + + React.useEffect(() => { + navigation.setOptions({ + headerRight: () => setShouldShowAdd(true)} /> + }); + }, []); + + return ( + + + {settings.exempted?.length > 0 && item} + renderItem={({ item }) => { + const user = UserStore.getUser(item); + + return (} + trailing={ { + storage.exempted = storage.exempted.filter((id) => id !== item); + }}> + + } + />); + }} + ItemSeparatorComponent={FormDivider} + />} + {shouldShowAdd && setShouldShowAdd(false)} />} + + + ); +} diff --git a/plugins/NoAutoReplyMention/src/index.ts b/plugins/NoAutoReplyMention/src/index.ts index 4e4c031..f65f59d 100644 --- a/plugins/NoAutoReplyMention/src/index.ts +++ b/plugins/NoAutoReplyMention/src/index.ts @@ -1 +1,22 @@ -export const onUnload = globalThis.vendetta.patcher.before("createPendingReply", globalThis.vendetta.metro.findByProps("createPendingReply"), ([arg]) => arg.shouldMention &&= false); +// export const onUnload = globalThis.vendetta.patcher.before("createPendingReply", globalThis.vendetta.metro.findByProps("createPendingReply"), ([arg]) => arg.shouldMention &&= false); + +import { patcher } from "@vendetta"; +import { findByProps } from "@vendetta/metro"; +import { storage } from "@vendetta/plugin"; +import Settings from "./Settings"; + +export interface SettingsSchema { + exempted: string[]; +} + +const ReplyManager = findByProps("createPendingReply"); + +storage.exempted ??= []; + +export default new class NoAutoReplyMention { + settings = Settings; + + onUnload = patcher.before("createPendingReply", ReplyManager, ([arg]) => { + arg.shouldMention &&= storage.exempted.includes(arg.message?.author?.id); + }); +};