|
| 1 | +import { before, after } from "@vendetta/patcher"; |
| 2 | +import { getAssetIDByName } from "@vendetta/ui/assets"; |
| 3 | +import { findInReactTree } from "@vendetta/utils"; |
| 4 | +import { FluxDispatcher, React } from "@vendetta/metro/common"; |
| 5 | +import { showToast } from "@vendetta/ui/toasts"; |
| 6 | +import { findByProps } from '@vendetta/metro'; |
| 7 | +import { regexEscaper, isEnabled } from ".."; |
| 8 | + |
| 9 | +const ActionSheet = findByProps("openLazy", "hideActionSheet") |
| 10 | +const MessageStore = findByProps("getMessage", "getMessages"); |
| 11 | +const ChannelStore = findByProps("getChannel", "getDMFromUserId"); |
| 12 | +const ChannelMessages = findByProps("_channelMessages"); |
| 13 | +const { ActionSheetRow } = findByProps("ActionSheetRow"); |
| 14 | + |
| 15 | +function someFunc(a) { |
| 16 | + // return a?.props?.label == i18n?.Messages?.MESSAGE_ACTION_REPLY |
| 17 | + return a?.props?.label?.toLowerCase?.() == 'reply' |
| 18 | +} |
| 19 | + |
| 20 | +export default () => before("openLazy", ActionSheet, ([component, args, actionMessage]) => { |
| 21 | + if(isEnabled) { |
| 22 | + try { |
| 23 | + const message = actionMessage?.message; |
| 24 | + |
| 25 | + if (args !== "MessageLongPressActionSheet" || !message) return; |
| 26 | + |
| 27 | + component.then((instance) => { |
| 28 | + const unpatch = after("default", instance, (_, comp) => { |
| 29 | + try { |
| 30 | + |
| 31 | + React.useEffect(() => () => { unpatch() }, []); |
| 32 | + |
| 33 | + const buttons = findInReactTree(comp, c => c?.find?.(someFunc)) |
| 34 | + if (!buttons) return comp; |
| 35 | + |
| 36 | + const position = Math.max( |
| 37 | + buttons.findIndex(someFunc), |
| 38 | + buttons.length - 1 |
| 39 | + ); |
| 40 | + |
| 41 | + let originalMessage = null; |
| 42 | + |
| 43 | + if (message?.channel_id && message?.id) { |
| 44 | + originalMessage = MessageStore.getMessage(message?.channel_id, message?.id); |
| 45 | + |
| 46 | + if(!originalMessage) { |
| 47 | + const channel = ChannelMessages.get(message?.channel_id); |
| 48 | + originalMessage = channel?.get(message?.id); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + if(!originalMessage) return comp; |
| 53 | + |
| 54 | + const escapedBuffer = regexEscaper("`[ EDITED ]`\n\n"); |
| 55 | + |
| 56 | + const separator = new RegExp(escapedBuffer, 'gmi'); |
| 57 | + const checkIfBufferExist = separator.test(message.content); |
| 58 | + |
| 59 | + if(checkIfBufferExist) { |
| 60 | + const targetPos = position || 1; |
| 61 | + |
| 62 | + buttons.splice(targetPos, 0, ( |
| 63 | + <ActionSheetRow |
| 64 | + label="Remove Edit History" |
| 65 | + subLabel={`Added by Antied Zero`} |
| 66 | + icon={<ActionSheetRow.Icon source={getAssetIDByName("ic_edit_24px")}/>} |
| 67 | + onPress={() => { |
| 68 | + |
| 69 | + const lats = message?.content?.split(separator); |
| 70 | + const targetMessage = lats[lats.length - 1]; |
| 71 | + |
| 72 | + FluxDispatcher.dispatch({ |
| 73 | + type: "MESSAGE_UPDATE", |
| 74 | + message: { |
| 75 | + ...message, |
| 76 | + message_reference: message?.message_reference || message?.messageReference || null, |
| 77 | + content: `${targetMessage}`, |
| 78 | + guild_id: ChannelStore.getChannel(originalMessage.channel_id).guild_id, |
| 79 | + }, |
| 80 | + otherPluginBypass: true |
| 81 | + }) |
| 82 | + |
| 83 | + ActionSheet.hideActionSheet() |
| 84 | + showToast("History Removed", getAssetIDByName("ic_edit_24px")) |
| 85 | + |
| 86 | + }}/> |
| 87 | + )) |
| 88 | + } |
| 89 | + } |
| 90 | + catch (e) { |
| 91 | + showToast("[ANTIED Zero] Crash on ActionSheet, check debug log for more info") |
| 92 | + console.error("[ANTIED Zero] Error > ActionSheet:Component Patch\n", e) |
| 93 | + } |
| 94 | + }) |
| 95 | + }) |
| 96 | + } |
| 97 | + catch (e) { |
| 98 | + showToast("[ANTIED Zero] Crash on ActionSheet, check debug log for more info") |
| 99 | + console.error("[ANTIED Zero] Error > ActionSheet Patch\n", e) |
| 100 | + } |
| 101 | + } |
| 102 | +}) |
0 commit comments