fix(ChatboxAvatar): deduplicate patches, add live position switching

- Guard against double-patching when ChatInputActions and
  ChatInputSendButton resolve to the same component
- Always patch both targets but conditionally render avatar
  based on position setting, so changes apply without restart
This commit is contained in:
kmmiio99o 2026-07-02 12:54:32 +02:00
parent 7b0e6d68f6
commit b2233e9bcf
No known key found for this signature in database
GPG key ID: AC9D7747D423B9BF

View file

@ -106,10 +106,12 @@ export default {
plugin.storage[key] = plugin.storage[key] ?? defaults[key];
}
if (ChatInputActions) {
const target = ChatInputActions.type || ChatInputActions;
const actionsTarget = ChatInputActions?.type || ChatInputActions;
const sendTarget = ChatInputSendButton?.type || ChatInputSendButton;
if (actionsTarget && actionsTarget !== sendTarget) {
patches.push(
after("render", target, (args, ret) => {
after("render", actionsTarget, (args, ret) => {
const position = getSetting("position", "after_actions");
if (position === "near_send") return ret;
return (
@ -123,10 +125,9 @@ export default {
);
}
if (ChatInputSendButton) {
const target = ChatInputSendButton.type || ChatInputSendButton;
if (sendTarget && sendTarget !== actionsTarget) {
patches.push(
after("render", target, (args, ret) => {
after("render", sendTarget, (args, ret) => {
const position = getSetting("position", "after_actions");
if (position !== "near_send") return ret;
return (
@ -138,6 +139,21 @@ export default {
})
);
}
if (actionsTarget && actionsTarget === sendTarget) {
patches.push(
after("render", actionsTarget, (args, ret) => {
const position = getSetting("position", "after_actions");
return (
<View style={{ flexDirection: "row", alignItems: "center" }}>
{position === "before_actions" && <AvatarAction />}
{ret}
{(position === "after_actions" || position === "near_send") && <AvatarAction />}
</View>
);
})
);
}
},
onUnload() {
for (const unpatch of patches) {