From 4414c2d29168a382deefbd3c4792e78c133958a0 Mon Sep 17 00:00:00 2001 From: kmmiio99o Date: Thu, 2 Jul 2026 12:28:24 +0200 Subject: [PATCH] feat(ChatboxAvatar): add Settings page with options --- plugins/ChatboxAvatar/src/index.tsx | 57 +++++++++++++++++++-- plugins/ChatboxAvatar/src/settings.tsx | 69 ++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 plugins/ChatboxAvatar/src/settings.tsx diff --git a/plugins/ChatboxAvatar/src/index.tsx b/plugins/ChatboxAvatar/src/index.tsx index 04aaacd..9bd654c 100644 --- a/plugins/ChatboxAvatar/src/index.tsx +++ b/plugins/ChatboxAvatar/src/index.tsx @@ -1,8 +1,11 @@ import { after } from "@vendetta/patcher"; import { find, findByName, findByProps, findByStoreName } from "@vendetta/metro"; import { ReactNative } from "@vendetta/metro/common"; +import { plugin } from "@vendetta"; import React from "react"; +import Settings from "./settings"; + const Flux = findByProps("useStateFromStores"); const { Pressable, View } = ReactNative; @@ -24,11 +27,15 @@ function openAccountSheet(userId: string, channelId: string) { try { fn(true, true); return; - } catch (_) {} + } catch { + // fall through to showUserProfileActionSheet + } } showUserProfileActionSheet?.({ userId, channelId }); } +const getSetting = (key: string, fallback: any) => plugin.storage[key] ?? fallback; + function AvatarAction() { const self = Flux?.useStateFromStores?.([UserStore], () => UserStore?.getCurrentUser?.()); const status = Flux?.useStateFromStores?.([SelfPresenceStore], () => SelfPresenceStore?.getStatus?.()); @@ -37,16 +44,44 @@ function AvatarAction() { if (!self || !Avatar) return null; + const pressAction = getSetting("pressAction", "profile"); + const longPressAction = getSetting("longPressAction", "server"); + const showStatusCutout = getSetting("showStatusCutout", true); + const profileType = getSetting("profileType", "server"); + const showInDms = getSetting("showInDms", true); + + const isDm = channel?.type === 1 || channel?.type === 3; + if (isDm && !showInDms) return null; + + const guildId = profileType === "server" ? channel?.guild_id : undefined; + const profileChannelId = profileType === "server" ? (channel?.id ?? channelId) : undefined; + + const handlePress = () => { + if (pressAction === "server") { + openAccountSheet(self.id, channel?.id ?? channelId); + } else { + showUserProfileActionSheet?.({ userId: self.id, channelId: profileChannelId }); + } + }; + + const handleLongPress = () => { + if (longPressAction === "server") { + openAccountSheet(self.id, channel?.id ?? channelId); + } else { + showUserProfileActionSheet?.({ userId: self.id, channelId: profileChannelId }); + } + }; + return ( showUserProfileActionSheet?.({ userId: self.id, channelId: channel?.id ?? channelId })} - onLongPress={() => openAccountSheet(self.id, channel?.id ?? channelId)} + onPress={handlePress} + onLongPress={handleLongPress} style={{ justifyContent: "center", alignItems: "center", marginHorizontal: 4 }} > @@ -58,6 +93,17 @@ const patches: (() => void)[] = []; export default { onLoad() { + const defaults: Record = { + pressAction: "profile", + longPressAction: "server", + showStatusCutout: true, + profileType: "server", + showInDms: true, + }; + for (const key in defaults) { + plugin.storage[key] = plugin.storage[key] ?? defaults[key]; + } + if (!ChatInputActions) return; if (ChatInputActions.type) { @@ -90,4 +136,5 @@ export default { } patches.length = 0; }, + settings: Settings, }; diff --git a/plugins/ChatboxAvatar/src/settings.tsx b/plugins/ChatboxAvatar/src/settings.tsx new file mode 100644 index 0000000..c53d716 --- /dev/null +++ b/plugins/ChatboxAvatar/src/settings.tsx @@ -0,0 +1,69 @@ +import { plugin } from "@vendetta"; +import { findByProps } from "@vendetta/metro"; +import { React } from "@vendetta/metro/common"; + +const { ScrollView } = findByProps("ScrollView"); +const { TableRowGroup, TableRadioGroup, TableRadioRow, TableSwitchRow, Stack } = findByProps( + "TableRadioGroup", + "TableRadioRow", + "TableSwitchRow", + "TableRowGroup", + "Stack", +); + +const get = (key: string, fallback: any) => plugin.storage[key] ?? fallback; +const set = (key: string, value: any) => { plugin.storage[key] = value; }; + +export default function ChatboxAvatarSettings() { + const [, forceUpdate] = React.useReducer((x: number) => ~x, 0); + + return ( + + + + { set("pressAction", v); forceUpdate(); }} + > + + + + + + { set("longPressAction", v); forceUpdate(); }} + > + + + + + + { set("profileType", v); forceUpdate(); }} + > + + + + + + { set("showStatusCutout", v === "true"); forceUpdate(); }} + > + + + + + + { set("showInDms", v); forceUpdate(); }} + /> + + + + ); +}