commit dc5026d39b66cc74a402e62393770e4d1439c895
parent 50af5cfb33655d07d513913a5a21ff3c62a0bb7f
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Fri, 19 Apr 2024 23:55:51 +0200

refactor: move instant delete to disable confirmation dialogs

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 5+----
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt | 2+-
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt | 1-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/FeatureManager.kt | 1-
Dcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/InstantDelete.kt | 106-------------------------------------------------------------------------------
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt | 12++++++++++--
6 files changed, 12 insertions(+), 115 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -534,10 +534,6 @@ "name": "Prevent Message Sending", "description": "Prevents sending certain types of messages" }, - "instant_delete": { - "name": "Instant Delete", - "description": "Removes the confirmation dialog when deleting messages" - }, "friend_mutation_notifier": { "name": "Friend Mutation Notifier", "description": "Notifies you when something changes in a friend's profile" @@ -1055,6 +1051,7 @@ "3d": "3D Bitmoji" }, "disable_confirmation_dialogs": { + "erase_message": "Erase Message", "remove_friend": "Remove Friend", "block_friend": "Block Friend", "ignore_friend": "Ignore Friend", diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt @@ -28,7 +28,7 @@ class Global : ConfigContainer() { } val betterLocation = container("better_location", BetterLocation()) val snapchatPlus = boolean("snapchat_plus") { requireRestart() } - val disableConfirmationDialogs = multiple("disable_confirmation_dialogs", "remove_friend", "block_friend", "ignore_friend", "hide_friend", "hide_conversation", "clear_conversation") { requireRestart() } + val disableConfirmationDialogs = multiple("disable_confirmation_dialogs", "erase_message", "remove_friend", "block_friend", "ignore_friend", "hide_friend", "hide_conversation", "clear_conversation") { requireRestart() } val disableMetrics = boolean("disable_metrics") { requireRestart() } val disableStorySections = multiple("disable_story_sections", "friends", "following", "discover") { requireRestart(); requireCleanCache() } val blockAds = boolean("block_ads") diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt @@ -72,7 +72,6 @@ class MessagingTweaks : ConfigContainer() { customOptionTranslationPath = "features.options.notifications" nativeHooks() } - val instantDelete = boolean("instant_delete") { requireRestart() } val friendMutationNotifier = multiple("friend_mutation_notifier", "remove_friend", "birthday_changes", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/FeatureManager.kt @@ -105,7 +105,6 @@ class FeatureManager( HideQuickAddFriendFeed(), CallStartConfirmation(), SnapPreview(), - InstantDelete(), BypassScreenshotDetection(), HalfSwipeNotifier(), DisableConfirmationDialogs(), diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/InstantDelete.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/InstantDelete.kt @@ -1,105 +0,0 @@ -package me.rhunk.snapenhance.core.features.impl.messaging - -import android.view.View -import android.widget.TextView -import me.rhunk.snapenhance.common.data.MessageUpdate -import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent -import me.rhunk.snapenhance.core.features.Feature -import me.rhunk.snapenhance.core.features.FeatureLoadParams -import me.rhunk.snapenhance.core.ui.iterateParent -import me.rhunk.snapenhance.core.ui.triggerCloseTouchEvent -import me.rhunk.snapenhance.core.util.ktx.getId -import me.rhunk.snapenhance.core.util.ktx.getIdentifier -import me.rhunk.snapenhance.core.util.ktx.setObjectField -import me.rhunk.snapenhance.core.wrapper.impl.CallbackResult -import java.lang.reflect.Modifier - -class InstantDelete : Feature("InstantDelete", loadParams = FeatureLoadParams.ACTIVITY_CREATE_ASYNC) { - override fun asyncOnActivityCreate() { - if (!context.config.messaging.instantDelete.get()) return - val chatActionMenuOptions = listOf( - "chat_action_menu_erase_messages", - "chat_action_menu_erase_quote", - "chat_action_menu_erase_reply", - ).associateWith { context.resources.getString(context.resources.getIdentifier(it, "string")) } - - val chatActionMenuContainerID = context.resources.getId("chat_action_menu_container") - val actionMenuOptionId = context.resources.getId("action_menu_option") - val actionMenuOptionTextId = context.resources.getId("action_menu_option_text") - - context.event.subscribe(BindViewEvent::class) { event -> - if (event.view.id != actionMenuOptionId) return@subscribe - - val menuOptionText = event.view.findViewById<TextView>(actionMenuOptionTextId) ?: return@subscribe - if (!chatActionMenuOptions.values.contains(menuOptionText.text)) return@subscribe - - val viewModel = event.prevModel - - val nestedViewOnClickListenerField = viewModel::class.java.fields.find { - it.type == View.OnClickListener::class.java - } ?: return@subscribe - - val nestedViewOnClickListener = nestedViewOnClickListenerField.get(viewModel) as? View.OnClickListener ?: return@subscribe - - val chatViewModel = nestedViewOnClickListener::class.java.fields.find { - Modifier.isAbstract(it.type.modifiers) && runCatching { - it.get(nestedViewOnClickListener) - }.getOrNull().toString().startsWith("ChatViewModel") - }?.get(nestedViewOnClickListener) ?: return@subscribe - - //[convId]:arroyo-id:[messageId] - val (conversationId, messageId) = chatViewModel.toString().substringAfter("messageId=").substringBefore(",").split(":").let { - if (it.size != 3) return@let null - it[0] to it[2] - } ?: return@subscribe - - viewModel.setObjectField(nestedViewOnClickListenerField.name, View.OnClickListener { view -> - val onCallbackResult: CallbackResult = callbackResult@{ - if (it == null || it == "DUPLICATEREQUEST") return@callbackResult - context.log.error("Error deleting message $messageId: $it") - context.shortToast("Error deleting message $messageId: $it. Using fallback method") - context.runOnUiThread { - nestedViewOnClickListener.onClick(view) - } - } - - runCatching { - val conversationManager = context.feature(Messaging::class).conversationManager ?: return@runCatching - - if (chatActionMenuOptions["chat_action_menu_erase_quote"] == menuOptionText.text) { - conversationManager.fetchMessage(conversationId, messageId.toLong(), onSuccess = { message -> - val quotedMessage = message.messageContent!!.quotedMessage!!.takeIf { it.isPresent() }!! - - conversationManager.updateMessage( - conversationId, - quotedMessage.content!!.messageId!!, - MessageUpdate.ERASE, - onResult = onCallbackResult - ) - }, onError = { - onCallbackResult(it) - }) - return@runCatching - } - - conversationManager.updateMessage( - conversationId, - messageId.toLong(), - MessageUpdate.ERASE, - onResult = onCallbackResult - ) - }.onFailure { - context.log.error("Error deleting message $messageId", it) - onCallbackResult(it.message) - return@OnClickListener - } - - view.iterateParent { - if (it.id != chatActionMenuContainerID) return@iterateParent false - it.triggerCloseTouchEvent() - true - } - }) - } - } -}- \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt @@ -5,6 +5,8 @@ import android.widget.TextView import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.FeatureLoadParams +import me.rhunk.snapenhance.core.ui.children +import me.rhunk.snapenhance.core.ui.triggerRootCloseTouchEvent import me.rhunk.snapenhance.core.util.ktx.getId import me.rhunk.snapenhance.core.util.ktx.getIdentifier import java.util.regex.Pattern @@ -16,6 +18,8 @@ class DisableConfirmationDialogs : Feature("Disable Confirmation Dialogs", loadP val alertDialogTitle = context.resources.getId("alert_dialog_title") val questions = listOf( + "erase_message" to "erase_learn_more_dialog_title", + "erase_message" to "erase_dialog_title", "remove_friend" to "action_menu_remove_friend_question", "block_friend" to "action_menu_block_friend_question", "ignore_friend" to "action_menu_ignore_friend_question", @@ -38,14 +42,18 @@ class DisableConfirmationDialogs : Feature("Disable Confirmation Dialogs", loadP if (event.parent.id != dialogContent || !event.view::class.java.name.endsWith("SnapButtonView")) return@subscribe val dialogTitle = event.parent.findViewById<TextView>(alertDialogTitle)?.text?.toString() ?: return@subscribe + if (event.parent.children().count { it::class.java.name.endsWith("SnapButtonView") } != 0) return@subscribe questions.forEach { (key, value) -> if (!disableConfirmationDialogs.contains(key)) return@forEach if (value?.matcher(dialogTitle)?.matches() == true) { - event.parent.visibility = View.GONE - event.parent.postDelayed({ + event.parent.visibility = View.INVISIBLE + event.parent.post { event.view.callOnClick() + } + event.parent.postDelayed({ + context.mainActivity!!.triggerRootCloseTouchEvent() }, 400) } }