commit debaecf91d7031f1797398be12fdfef28206bcc4
parent 7fc3ec9d104c1df6c9a441736b7d9b60f69d89f5
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Fri, 26 Apr 2024 17:37:55 +0200
fix(core): hide streak restore
Diffstat:
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/HideStreakRestore.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/HideStreakRestore.kt
@@ -2,22 +2,44 @@ package me.rhunk.snapenhance.core.features.impl.ui
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
+import me.rhunk.snapenhance.core.features.impl.messaging.Messaging
import me.rhunk.snapenhance.core.util.dataBuilder
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.hookConstructor
+import me.rhunk.snapenhance.core.util.ktx.getObjectField
+import me.rhunk.snapenhance.core.util.ktx.getObjectFieldOrNull
+import me.rhunk.snapenhance.core.util.ktx.setObjectField
+import me.rhunk.snapenhance.core.wrapper.impl.SnapUUID
class HideStreakRestore : Feature("HideStreakRestore", loadParams = FeatureLoadParams.INIT_SYNC) {
override fun init() {
if (!context.config.userInterface.hideStreakRestore.get()) return
+ findClass("com.snapchat.client.messaging.FeedEntry").hookConstructor(HookStage.AFTER) { param ->
+ val instance = param.thisObject<Any>()
+ if (instance.getObjectFieldOrNull("mDisplayInfo")
+ ?.getObjectFieldOrNull("mFeedItem")
+ ?.getObjectFieldOrNull("mConversation")
+ ?.getObjectFieldOrNull("mState")
+ ?.toString() == "STREAK_RESTORE") {
+ instance.getObjectFieldOrNull("mDisplayInfo")
+ ?.getObjectFieldOrNull("mFeedItem")
+ ?.setObjectField("mConversation", null)
+ val conversationId = SnapUUID(instance.getObjectField("mConversationId")).toString()
+ context.feature(Messaging::class).conversationManager?.dismissStreakRestore(
+ conversationId,
+ onError = {
+ context.log.error("Failed to dismiss streak restore: $it")
+ }, onSuccess = {
+ context.log.info("Dismissed streak restore for conversation $conversationId")
+ }
+ )
+ }
+ }
+
findClass("com.snapchat.client.messaging.StreakMetadata").hookConstructor(HookStage.AFTER) { param ->
param.thisObject<Any>().dataBuilder {
- val currentTimeMillis = System.currentTimeMillis()
- val expiration = get<Long>("mExpirationTimestampMs") ?: return@hookConstructor
set("mExpiredStreak", null)
- if (expiration < currentTimeMillis) {
- set("mExpirationTimestampMs", currentTimeMillis + 60000L)
- }
}
}
}
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/wrapper/impl/ConversationManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/wrapper/impl/ConversationManager.kt
@@ -26,6 +26,7 @@ class ConversationManager(
private val fetchMessage by lazy { findMethodByName("fetchMessage") }
private val clearConversation by lazy { findMethodByName("clearConversation") }
private val getOneOnOneConversationIds by lazy { findMethodByName("getOneOnOneConversationIds") }
+ private val dismissStreakRestore by lazy { findMethodByName("dismissStreakRestore") }
private fun getCallbackClass(name: String): Class<*> {
@@ -175,4 +176,11 @@ class ConversationManager(
}
fun isEditMessageSupported() = instanceNonNull()::class.java.methods.any { it.name == "editMessage" }
+
+ fun dismissStreakRestore(conversationId: String, onSuccess: () -> Unit, onError: (error: String) -> Unit) {
+ val callback = CallbackBuilder(getCallbackClass("Callback"))
+ .override("onSuccess") { onSuccess() }
+ .override("onError") { onError(it.arg<Any>(0).toString()) }.build()
+ dismissStreakRestore.invoke(instanceNonNull(), conversationId.toSnapUUID().instanceNonNull(), callback)
+ }
}
\ No newline at end of file