mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-28 12:30:12 +02:00
fix(core): hide streak restore
This commit is contained in:
parent
7fc3ec9d10
commit
debaecf91d
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user