From b03e6dbb40f2899b5dfb4ef048b5eafd653b36c2 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Fri, 4 Apr 2025 01:57:33 -0400 Subject: [PATCH] Update BetterBlockedUsers --- .../betterBlockedUsers/index.tsx | 131 ++++++++++++------ 1 file changed, 91 insertions(+), 40 deletions(-) diff --git a/src/equicordplugins/betterBlockedUsers/index.tsx b/src/equicordplugins/betterBlockedUsers/index.tsx index bd8cde39..4ea600b5 100644 --- a/src/equicordplugins/betterBlockedUsers/index.tsx +++ b/src/equicordplugins/betterBlockedUsers/index.tsx @@ -22,27 +22,33 @@ const ButtonComponent = findComponentByCodeLazy('submittingStartedLabel","submit const ConfirmationModal = findByCodeLazy('"ConfirmModal")', "useLayoutEffect"); const settings = definePluginSettings({ - hideBlockedWarning: { - default: true, - type: OptionType.BOOLEAN, - description: "Skip the warning about blocked/ignored users when opening the profile through the blocklist.", - restartNeeded: true, - }, addDmsButton: { default: true, type: OptionType.BOOLEAN, - description: "Adds a 'View DMs' button to the users in the blocked list.", + description: "Adds a 'View DMs' button to the users in the blocked/ignored list.", }, - unblockButtonDanger: { + hideBlockedWarning: { default: false, type: OptionType.BOOLEAN, - description: "Changes the 'Unblock' button to a red color to make it's 'danger' more obvious.", + description: "Skip the warning about blocked/ignored users when opening any profile anywhere on discord outside of the blocklist.", + restartNeeded: true, }, showUnblockConfirmation: { default: true, type: OptionType.BOOLEAN, - description: "Show a confirmation dialog when clicking the 'Unblock' button.", - } + description: "Show a warning before unblocking a user from the blocklist.", + }, + showUnblockConfirmationEverywhere: { + default: false, + type: OptionType.BOOLEAN, + description: "Show a warning before unblocking a user anywhere on discord.", + restartNeeded: true, + }, + unblockButtonDanger: { + default: false, + type: OptionType.BOOLEAN, + description: "Color the unblock button in the blocklist red instead of gray.", + }, }); export default definePlugin({ @@ -63,7 +69,7 @@ export default definePlugin({ replace: "style:{cursor:'pointer'},onClick:()=>$self.openUserProfile($1)," }, { - match: /(?<=children:null!=(\i).globalName\?\i.username:null.*?}\),).*?(\{color:.{0,50}?children:\i.\i.string\((\i)\?.*?"8wXU9P"]\)})\)/, + match: /(?<=children:null!=(\i).globalName\?.+?}\),).*?(\{color:.{0,65}?string\((\i).+?"8wXU9P"]\)})\)/, replace: "$self.generateButtons({user:$1, originalProps:$2, isBlocked:$3})", }, { @@ -95,8 +101,45 @@ export default definePlugin({ match: /(?<=isIgnored:.*?,\[\i,\i]=\i.useState\()\i\|\|\i\|\|\i.*?]\);/, replace: "false);" }, - predicate: () => settings.store.hideBlockedWarning, }, + + // If the users wishes to, they can disable the warning in all other places as well. + ...[ + "UserProfilePanelWrapper: currentUser cannot be undefined", + "UserProfilePopoutWrapper: currentUser cannot be undefined", + ].map(x => ({ + find: x, + replacement: { + match: /(?<=isIgnored:.*?,\[\i,\i]=\i.useState\()\i\|\|\i\|\|\i\)(?:;\i.useEffect.*?]\))?/, + replace: "false)", + }, + predicate: () => settings.store.hideBlockedWarning, + })), + + { + find: ".BLOCKED:return", + replacement: { + match: /(?<=\i.BLOCKED:return.{0,65}onClick:)\(\)=>\{(\i.\i.unblockUser\((\i).+?}\))/, + replace: "(event) => {$self.openConfirmationModal(event,()=>{$1}, $2)", + }, + predicate: () => settings.store.showUnblockConfirmationEverywhere, + }, + { + find: "#{intl::UNBLOCK}),", + replacement: { + match: /(?<=#{intl::UNBLOCK}.+?Click=)\(\)=>(\{.+?(\i.getRecipientId\(\))\)})/, + replace: "event => $self.openConfirmationModal(event, ()=>$1, $2)", + }, + predicate: () => settings.store.showUnblockConfirmationEverywhere, + }, + { + find: "#{intl::BLOCK}),action", + replacement: { + match: /(?<=id:"block".{0,100}action:\i\?)\(\)=>(\{.{0,25}unblockUser\((\i).{0,60}:void 0\)})/, + replace: "event => {$self.openConfirmationModal(event, ()=>$1,$2)}", + }, + predicate: () => settings.store.showUnblockConfirmationEverywhere, + } ], renderSearchInput() { const [value, setValue] = React.useState(lastSearch); @@ -144,44 +187,23 @@ export default definePlugin({ // TODO add extra unblock confirmation after the click + setting. - if (settings.store.showUnblockConfirmation) { + if (settings.store.showUnblockConfirmation || settings.store.showUnblockConfirmationEverywhere) { const originalOnClick = originalProps.onClick!; originalProps.onClick = e => { - if (e.shiftKey) return originalOnClick(e); - - openModal(m => { - originalOnClick(e); - }}> -
-
- {`Are you sure you want to ${isBlocked ? "unblock" : "unignore"} this user?`} - {isBlocked ? {`This will allow ${user.username} to see your profile and message you again.`} : null} -
- {`You can always ${isBlocked ? "block" : "ignore"} them again later.`} -
- {"If you just want to read the chat logs instead, you can just click on their profile."} - {"Alternatively, you can enable a button to show DMs in the blocklist through the plugin settings."} -
-
-
); + if (!isBlocked) return originalOnClick(e); + this.openConfirmationModal(e, () => originalOnClick(e), user, true); }; } - const originalButton = ; + const unblockButton = ; - if (!settings.store.addDmsButton) return originalButton; + if (!settings.store.addDmsButton) return unblockButton; const dmButton = this.openDMChannel(user)}>Show DMs; return
{dmButton} - {originalButton} + {unblockButton}
; }, @@ -190,4 +212,33 @@ export default definePlugin({ this.closeSettingsWindow(); return null; }, + openConfirmationModal(event: MouseEvent, callback: () => any, user: User | string, isSettingsOrigin: boolean = false) { + if (event.shiftKey) return callback(); + + if (typeof user === "string") { + user = UserStore.getUser(user); + } + + return openModal(m => { + callback(); + }}> +
+
+ {`Are you sure you want to unblock ${user?.username ?? "this user"}?`} + {`This will allow ${user?.username ?? "them"} to see your profile and message you again.`} +
+ {"You can always block them again later."} + {isSettingsOrigin ?
+ {"If you just want to read the chat logs instead, you can just click on their profile."} + {"Alternatively, you can enable a button to jump to DMs in the blocklist through the plugin settings."} +
: {"If you just want to read the chat logs, you can do this without unblocking them."}} +
+
); + }, });