mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 05:07:46 +02:00
fix(pin_conversations): set to rule feature
This commit is contained in:
@ -29,7 +29,8 @@ enum class MessagingRuleType(
|
||||
AUTO_DOWNLOAD("auto_download", true),
|
||||
STEALTH("stealth", true),
|
||||
AUTO_SAVE("auto_save", true),
|
||||
HIDE_CHAT_FEED("hide_chat_feed", false);
|
||||
HIDE_CHAT_FEED("hide_chat_feed", false),
|
||||
PIN_CONVERSATION("pin_conversation", false);
|
||||
|
||||
fun translateOptionKey(optionKey: String): String {
|
||||
return "rules.properties.${key}.options.${optionKey}"
|
||||
|
@ -4,11 +4,8 @@ import me.rhunk.snapenhance.core.messaging.MessagingRuleType
|
||||
import me.rhunk.snapenhance.core.messaging.RuleState
|
||||
|
||||
abstract class MessagingRuleFeature(name: String, val ruleType: MessagingRuleType, loadParams: Int = 0) : Feature(name, loadParams) {
|
||||
init {
|
||||
if (!ruleType.listMode) throw IllegalArgumentException("Rule type must be a list mode")
|
||||
}
|
||||
|
||||
fun getRuleState() = context.config.rules.getRuleState(ruleType)
|
||||
open fun getRuleState() = context.config.rules.getRuleState(ruleType)
|
||||
|
||||
fun setState(conversationId: String, state: Boolean) {
|
||||
context.bridgeClient.setRule(
|
||||
|
@ -1,28 +1,28 @@
|
||||
package me.rhunk.snapenhance.features.impl.ui
|
||||
|
||||
import me.rhunk.snapenhance.core.bridge.types.BridgeFileType
|
||||
import me.rhunk.snapenhance.core.messaging.MessagingRuleType
|
||||
import me.rhunk.snapenhance.core.messaging.RuleState
|
||||
import me.rhunk.snapenhance.core.util.ktx.getObjectField
|
||||
import me.rhunk.snapenhance.core.util.ktx.setObjectField
|
||||
import me.rhunk.snapenhance.data.wrapper.impl.SnapUUID
|
||||
import me.rhunk.snapenhance.features.BridgeFileFeature
|
||||
import me.rhunk.snapenhance.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.features.MessagingRuleFeature
|
||||
import me.rhunk.snapenhance.hook.HookStage
|
||||
import me.rhunk.snapenhance.hook.hook
|
||||
import me.rhunk.snapenhance.hook.hookConstructor
|
||||
|
||||
class PinConversations : BridgeFileFeature("PinConversations", BridgeFileType.PINNED_CONVERSATIONS, loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
|
||||
class PinConversations : MessagingRuleFeature("PinConversations", MessagingRuleType.PIN_CONVERSATION, loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
|
||||
override fun onActivityCreate() {
|
||||
context.classCache.feedManager.hook("setPinnedConversationStatus", HookStage.BEFORE) { param ->
|
||||
val conversationUUID = SnapUUID(param.arg(0))
|
||||
val isPinned = param.arg<Any>(1).toString() == "PINNED"
|
||||
|
||||
setState(conversationUUID.toString(), isPinned)
|
||||
}
|
||||
|
||||
context.classCache.conversation.hookConstructor(HookStage.AFTER) { param ->
|
||||
val instance = param.thisObject<Any>()
|
||||
val conversationUUID = SnapUUID(instance.getObjectField("mConversationId"))
|
||||
if (exists(conversationUUID.toString())) {
|
||||
if (getState(conversationUUID.toString())) {
|
||||
instance.setObjectField("mPinnedTimestampMs", 1L)
|
||||
}
|
||||
}
|
||||
@ -30,10 +30,12 @@ class PinConversations : BridgeFileFeature("PinConversations", BridgeFileType.PI
|
||||
context.classCache.feedEntry.hookConstructor(HookStage.AFTER) { param ->
|
||||
val instance = param.thisObject<Any>()
|
||||
val conversationUUID = SnapUUID(instance.getObjectField("mConversationId") ?: return@hookConstructor)
|
||||
val isPinned = exists(conversationUUID.toString())
|
||||
val isPinned = getState(conversationUUID.toString())
|
||||
if (isPinned) {
|
||||
instance.setObjectField("mPinnedTimestampMs", 1L)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getRuleState() = RuleState.WHITELIST
|
||||
}
|
Reference in New Issue
Block a user