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 index d9104f0b..4e3ed4cf 100644 --- 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() + 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().dataBuilder { - val currentTimeMillis = System.currentTimeMillis() - val expiration = get("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 index 6e3986e5..f116311b 100644 --- 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(0).toString()) }.build() + dismissStreakRestore.invoke(instanceNonNull(), conversationId.toSnapUUID().instanceNonNull(), callback) + } } \ No newline at end of file