diff --git a/package.json b/package.json index bd40c4ae..e426b8a7 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "stylelint": "^16.8.1", "stylelint-config-standard": "^36.0.1", "ts-patch": "^3.2.1", + "ts-pattern": "^5.3.1", "tsx": "^4.16.5", "type-fest": "^4.23.0", "typed-emitter": "^2.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f9a901fd..7e346c39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -134,6 +134,9 @@ importers: ts-patch: specifier: ^3.2.1 version: 3.2.1 + ts-pattern: + specifier: ^5.3.1 + version: 5.3.1 tsx: specifier: ^4.16.5 version: 4.16.5 @@ -2374,6 +2377,9 @@ packages: resolution: {integrity: sha512-hlR43v+GUIUy8/ZGFP1DquEqPh7PFKQdDMTAmYt671kCCA6AkDQMoeFaFmZ7ObPLYOmpMgyKUqL1C+coFMf30w==} hasBin: true + ts-pattern@5.3.1: + resolution: {integrity: sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==} + tsconfig-paths@3.15.0: resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} @@ -4823,6 +4829,8 @@ snapshots: semver: 7.6.3 strip-ansi: 6.0.1 + ts-pattern@5.3.1: {} + tsconfig-paths@3.15.0: dependencies: '@types/json5': 0.0.29 diff --git a/src/plugins/noBlockedMessages/index.ts b/src/plugins/noBlockedMessages/index.ts index 1ea5b529..8931883e 100644 --- a/src/plugins/noBlockedMessages/index.ts +++ b/src/plugins/noBlockedMessages/index.ts @@ -21,6 +21,7 @@ import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; +import { MessageStore } from "@webpack/common"; import { Message } from "discord-types/general"; const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked"); @@ -28,7 +29,7 @@ const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked"); export default definePlugin({ name: "NoBlockedMessages", description: "Hides all blocked messages from chat completely.", - authors: [Devs.rushii, Devs.Samu], + authors: [Devs.rushii, Devs.Samu, Devs.F53], patches: [ { find: "Messages.BLOCKED_MESSAGES_HIDE", @@ -48,10 +49,17 @@ export default definePlugin({ replacement: [ { match: /(?<=MESSAGE_CREATE:function\((\i)\){)/, - replace: (_, props) => `if($self.isBlocked(${props}.message))return;` + replace: (_, props) => `if($self.isBlocked(${props}.message)||$self.isReplyToBlocked(${props}.message))return;` } ] - })) + })), + { + find: ".messageListItem", + replacement: { + match: /(?<=\i=)(?=\(0,(\i)\.jsx)/, + replace: "!$self.isReplyToBlocked(arguments[0].message)&&" + } + } ], options: { ignoreBlockedMessages: { @@ -60,9 +68,26 @@ export default definePlugin({ default: false, restartNeeded: true, }, + hideRepliesToBlockedMessages: { + description: "Hide replies to messages made by users you've blocked", + type: OptionType.BOOLEAN, + default: false, + restartNeeded: false, + } }, - isBlocked(message: Message) { + isReplyToBlocked(message: Message) { + if (!Settings.plugins.NoBlockedMessages.hideRepliesToBlockedMessages) + return false; + + const { messageReference } = message; + if (!messageReference) return false; + const replyMessage = MessageStore.getMessage(messageReference.channel_id, messageReference.message_id); + return this.isBlocked(replyMessage); + }, + + isBlocked(message: Message | undefined) { + if (!message) return false; try { return RelationshipStore.isBlocked(message.author.id); } catch (e) { diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index a5da0c41..83805744 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -52,6 +52,11 @@ export const useDrag = findByCodeLazy("useDrag::spec.begin was deprecated"); // you cant make a better finder i love that they remove display names sm export const useDrop = findByCodeLazy(".options);return", ".collect,"); +export const { match, P }: Pick = mapMangledModuleLazy("@ts-pattern/matcher", { + match: filters.byCode("return new"), + P: filters.byProps("when") +}); + export const lodash: typeof import("lodash") = findByPropsLazy("debounce", "cloneDeep"); export const i18n: t.i18n = findLazy(m => m.Messages?.["en-US"]);