From 44c6f8678a6d53396f93f85840436b74006c478c Mon Sep 17 00:00:00 2001 From: R0rt1z2 Date: Wed, 29 Jan 2025 17:49:09 +0100 Subject: [PATCH] GrindrPlus: Add toggle for old AntiBlock behavior --- .../java/com/grindrplus/hooks/AntiBlock.kt | 132 ++++++++++-------- .../ui/fragments/SettingsFragment.kt | 2 + 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/grindrplus/hooks/AntiBlock.kt b/app/src/main/java/com/grindrplus/hooks/AntiBlock.kt index 7a6ebba..3a3be7c 100644 --- a/app/src/main/java/com/grindrplus/hooks/AntiBlock.kt +++ b/app/src/main/java/com/grindrplus/hooks/AntiBlock.kt @@ -9,6 +9,7 @@ import com.grindrplus.core.Utils.sendNotification import com.grindrplus.utils.Hook import com.grindrplus.utils.HookStage import com.grindrplus.utils.hook +import com.grindrplus.utils.hookConstructor import de.robv.android.xposed.XposedHelpers.getObjectField import org.json.JSONObject @@ -20,75 +21,84 @@ class AntiBlock : Hook( private val inboxFragmentV2DeleteConversations = "Ma.v0\$a" override fun init() { - findClass(inboxFragmentV2DeleteConversations) - .hook("invokeSuspend", HookStage.BEFORE) { param -> - GrindrPlus.shouldTriggerAntiblock = false - GrindrPlus.blockCaller = "inboxFragmentV2DeleteConversations" - } - - findClass(inboxFragmentV2DeleteConversations) - .hook("invokeSuspend", HookStage.AFTER) { param -> - val numberOfChatsToDelete = (getObjectField(param.thisObject(), "j") as List<*>).size - Thread.sleep((300 * numberOfChatsToDelete).toLong()) // FIXME - GrindrPlus.shouldTriggerAntiblock = true - GrindrPlus.blockCaller = "" - } - - findClass("v4.c").hook("b", HookStage.BEFORE) { param -> - if (!GrindrPlus.shouldTriggerAntiblock) { - val whitelist = listOf( - "inboxFragmentV2DeleteConversations", - ) - if (GrindrPlus.blockCaller !in whitelist) { - param.setResult(null) + if (Config.get("force_old_anti_block_behavior", false) as Boolean) { + findClass("com.grindrapp.android.chat.model.ConversationDeleteNotification") + .hookConstructor(HookStage.BEFORE) { param -> + @Suppress("UNCHECKED_CAST") + val profiles = param.args().firstOrNull() as? List ?: emptyList() + param.setArg(0, emptyList()) } - return@hook - } else { - if (myProfileId == 0L) { - myProfileId = (getObjectField(instanceManager - .getInstance("V8.T"), - "p") as String).toLong() + } else { + findClass(inboxFragmentV2DeleteConversations) + .hook("invokeSuspend", HookStage.BEFORE) { param -> + GrindrPlus.shouldTriggerAntiblock = false + GrindrPlus.blockCaller = "inboxFragmentV2DeleteConversations" + } + + findClass(inboxFragmentV2DeleteConversations) + .hook("invokeSuspend", HookStage.AFTER) { param -> + val numberOfChatsToDelete = (getObjectField(param.thisObject(), "j") as List<*>).size + Thread.sleep((300 * numberOfChatsToDelete).toLong()) // FIXME + GrindrPlus.shouldTriggerAntiblock = true + GrindrPlus.blockCaller = "" } - val conversationId = (param.args().firstOrNull()?.let { getObjectField(it, "payload") } as? JSONObject) - ?.optJSONArray("conversationIds") - ?.let { (0 until it.length()).joinToString(",") { index -> it.getString(index) } } - ?: return@hook + findClass("v4.c").hook("b", HookStage.BEFORE) { param -> + if (!GrindrPlus.shouldTriggerAntiblock) { + val whitelist = listOf( + "inboxFragmentV2DeleteConversations", + ) + if (GrindrPlus.blockCaller !in whitelist) { + param.setResult(null) + } + return@hook + } else { + if (myProfileId == 0L) { + myProfileId = (getObjectField(instanceManager + .getInstance("V8.T"), + "p") as String).toLong() + } + + val conversationId = (param.args().firstOrNull()?.let { getObjectField(it, "payload") } as? JSONObject) + ?.optJSONArray("conversationIds") + ?.let { (0 until it.length()).joinToString(",") { index -> it.getString(index) } } + ?: return@hook - val conversationIds = conversationId.split(":").mapNotNull { it.toLongOrNull() } - val otherProfileId = conversationIds.firstOrNull { it != myProfileId } ?: return@hook + val conversationIds = conversationId.split(":").mapNotNull { it.toLongOrNull() } + val otherProfileId = conversationIds.firstOrNull { it != myProfileId } ?: return@hook - // FIXME: Get rid of this ugly shit - if (otherProfileId == myProfileId) return@hook - Thread.sleep(300) + // FIXME: Get rid of this ugly shit + if (otherProfileId == myProfileId) return@hook + Thread.sleep(300) - try { - if (DatabaseHelper.query( - "SELECT * FROM blocks WHERE profileId = ?", - arrayOf(otherProfileId.toString()) - ).isNotEmpty() - ) { - return@hook + try { + if (DatabaseHelper.query( + "SELECT * FROM blocks WHERE profileId = ?", + arrayOf(otherProfileId.toString()) + ).isNotEmpty() + ) { + return@hook + } + } catch(e: Exception) { + val message = "Error checking if user is blocked: ${e.message}" + GrindrPlus.apply { + showToast(Toast.LENGTH_LONG, message) + logger.log(message) + logger.writeRaw(e.stackTraceToString()) + } } - } catch(e: Exception) { - val message = "Error checking if user is blocked: ${e.message}" - GrindrPlus.apply { - showToast(Toast.LENGTH_LONG, message) - logger.log(message) - logger.writeRaw(e.stackTraceToString()) - } - } - try { - val response = fetchProfileData(otherProfileId.toString()) - handleProfileResponse(otherProfileId, conversationId, response) - param.setResult(null) - } catch (e: Exception) { - val message = "Error handling block/unblock request: ${e.message ?: "Unknown error"}" - GrindrPlus.apply { - showToast(Toast.LENGTH_LONG, message) - logger.log(message) - logger.writeRaw(e.stackTraceToString()) + try { + val response = fetchProfileData(otherProfileId.toString()) + handleProfileResponse(otherProfileId, conversationId, response) + param.setResult(null) + } catch (e: Exception) { + val message = "Error handling block/unblock request: ${e.message ?: "Unknown error"}" + GrindrPlus.apply { + showToast(Toast.LENGTH_LONG, message) + logger.log(message) + logger.writeRaw(e.stackTraceToString()) + } } } } diff --git a/app/src/main/java/com/grindrplus/ui/fragments/SettingsFragment.kt b/app/src/main/java/com/grindrplus/ui/fragments/SettingsFragment.kt index a5a8bd2..175c33d 100644 --- a/app/src/main/java/com/grindrplus/ui/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/grindrplus/ui/fragments/SettingsFragment.kt @@ -519,6 +519,8 @@ class SettingsFragment : Fragment() { ) ) + // force_old_anti_block_behavior + container?.addView(createToggleableSettingView(context, "Force old AntiBlock behavior", "Use the old AntiBlock behavior", "force_old_anti_block_behavior")) container?.addView(createToggleableSettingView(context, "Use toasts for AntiBlock hook", "Instead of receiving Android notifications, use toasts for block/unblock notifications", "anti_block_use_toasts")) container?.addView(createToggleableSettingView(context, "Disable profile swipe", "Disable the swipe gesture on profiles", "disable_profile_swipe"))