mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 13:00:17 +02:00
refactor: rule features
This commit is contained in:
parent
9e547bfe0c
commit
b46139c3ad
@ -12,7 +12,7 @@ class UserInterfaceTweaks : ConfigContainer() {
|
||||
}
|
||||
|
||||
val friendFeedMenuButtons = multiple(
|
||||
"friend_feed_menu_buttons","conversation_info", *MessagingRuleType.values().toList().filter { it.listMode }.map { it.key }.toTypedArray()
|
||||
"friend_feed_menu_buttons","conversation_info", *MessagingRuleType.values().toList().filter { it.showInFriendMenu }.map { it.key }.toTypedArray()
|
||||
).apply {
|
||||
set(mutableListOf("conversation_info", MessagingRuleType.STEALTH.key))
|
||||
}
|
||||
|
@ -28,16 +28,17 @@ enum class SocialScope(
|
||||
|
||||
enum class MessagingRuleType(
|
||||
val key: String,
|
||||
val listMode: Boolean
|
||||
val listMode: Boolean,
|
||||
val showInFriendMenu: Boolean = true
|
||||
) {
|
||||
AUTO_DOWNLOAD("auto_download", true),
|
||||
STEALTH("stealth", true),
|
||||
AUTO_SAVE("auto_save", true),
|
||||
HIDE_CHAT_FEED("hide_chat_feed", false),
|
||||
PIN_CONVERSATION("pin_conversation", false);
|
||||
HIDE_CHAT_FEED("hide_chat_feed", false, showInFriendMenu = false),
|
||||
PIN_CONVERSATION("pin_conversation", false, showInFriendMenu = false);
|
||||
|
||||
fun translateOptionKey(optionKey: String): String {
|
||||
return "rules.properties.${key}.options.${optionKey}"
|
||||
return if (listMode) "rules.properties.$key.options.$optionKey" else "rules.properties.$key.name"
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -38,7 +38,7 @@ class ProtoEditor(
|
||||
private fun writeAtPath(path: IntArray, currentIndex: Int, rootReader: ProtoReader, wireToWriteCallback: WireCallback): ByteArray {
|
||||
val id = path.getOrNull(currentIndex)
|
||||
val output = ProtoWriter()
|
||||
val wires = mutableMapOf<Int, MutableList<Wire>>()
|
||||
val wires = sortedMapOf<Int, MutableList<Wire>>()
|
||||
|
||||
rootReader.forEach { wireId, value ->
|
||||
wires.putIfAbsent(wireId, mutableListOf())
|
||||
|
@ -34,7 +34,7 @@ abstract class AbstractWrapper(
|
||||
|
||||
fun <T : Enum<*>> getEnumValue(fieldName: String, defaultValue: T?): T? {
|
||||
if (defaultValue == null) return null
|
||||
val mContentType = XposedHelpers.getObjectField(instance, fieldName) as Enum<*>
|
||||
val mContentType = XposedHelpers.getObjectField(instance, fieldName) as? Enum<*> ?: return null
|
||||
return java.lang.Enum.valueOf(defaultValue::class.java, mContentType.name)
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ class SnapUUID(obj: Any?) : AbstractWrapper(obj) {
|
||||
return uuidString
|
||||
}
|
||||
|
||||
fun toBytes() = bytes
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is SnapUUID && other.uuidString == uuidString
|
||||
}
|
||||
|
@ -526,14 +526,11 @@ class MediaDownloader : MessagingRuleFeature("MediaDownloader", MessagingRuleTyp
|
||||
val friendInfo: FriendInfo = context.database.getFriendInfo(message.senderId!!) ?: throw Exception("Friend not found in database")
|
||||
val authorName = friendInfo.usernameForSorting!!
|
||||
|
||||
val decodedAttachments = if (messageLogger.isMessageRemoved(message.clientConversationId!!, message.serverMessageId.toLong())) {
|
||||
val messageObject = messageLogger.getMessageObject(message.clientConversationId!!, message.serverMessageId.toLong()) ?: throw Exception("Message not found in database")
|
||||
MessageDecoder.decode(messageObject.getAsJsonObject("mMessageContent"))
|
||||
} else {
|
||||
MessageDecoder.decode(
|
||||
protoReader = ProtoReader(message.messageContent!!)
|
||||
)
|
||||
}
|
||||
val decodedAttachments = messageLogger.getMessageObject(message.clientConversationId!!, message.serverMessageId.toLong())?.let {
|
||||
MessageDecoder.decode(it.getAsJsonObject("mMessageContent"))
|
||||
} ?: MessageDecoder.decode(
|
||||
protoReader = ProtoReader(message.messageContent!!)
|
||||
)
|
||||
|
||||
if (decodedAttachments.isEmpty()) {
|
||||
context.shortToast(translations["no_attachments_toast"])
|
||||
|
@ -2,8 +2,10 @@ package me.rhunk.snapenhance.manager.impl
|
||||
|
||||
import me.rhunk.snapenhance.ModContext
|
||||
import me.rhunk.snapenhance.core.Logger
|
||||
import me.rhunk.snapenhance.features.impl.experiments.AESMessageEncryption
|
||||
import me.rhunk.snapenhance.features.Feature
|
||||
import me.rhunk.snapenhance.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.features.MessagingRuleFeature
|
||||
import me.rhunk.snapenhance.features.impl.ConfigurationOverride
|
||||
import me.rhunk.snapenhance.features.impl.Messaging
|
||||
import me.rhunk.snapenhance.features.impl.ScopeSync
|
||||
@ -48,6 +50,8 @@ class FeatureManager(private val context: ModContext) : Manager {
|
||||
return features.find { it::class == featureClass } as? T
|
||||
}
|
||||
|
||||
fun getRuleFeatures() = features.filterIsInstance<MessagingRuleFeature>()
|
||||
|
||||
override fun init() {
|
||||
register(
|
||||
ScopeSync::class,
|
||||
|
@ -17,11 +17,7 @@ import me.rhunk.snapenhance.core.database.objects.UserConversationLink
|
||||
import me.rhunk.snapenhance.core.util.snap.BitmojiSelfie
|
||||
import me.rhunk.snapenhance.data.ContentType
|
||||
import me.rhunk.snapenhance.data.FriendLinkType
|
||||
import me.rhunk.snapenhance.features.MessagingRuleFeature
|
||||
import me.rhunk.snapenhance.features.impl.Messaging
|
||||
import me.rhunk.snapenhance.features.impl.downloader.MediaDownloader
|
||||
import me.rhunk.snapenhance.features.impl.spying.StealthMode
|
||||
import me.rhunk.snapenhance.features.impl.tweaks.AutoSave
|
||||
import me.rhunk.snapenhance.ui.ViewAppearanceHelper
|
||||
import me.rhunk.snapenhance.ui.applyTheme
|
||||
import me.rhunk.snapenhance.ui.menu.AbstractMenu
|
||||
@ -247,13 +243,7 @@ class FriendFeedInfoMenu : AbstractMenu() {
|
||||
viewConsumer(previewButton)
|
||||
}
|
||||
|
||||
val rules: Array<MessagingRuleFeature> = arrayOf(
|
||||
StealthMode::class,
|
||||
AutoSave::class,
|
||||
MediaDownloader::class
|
||||
).map { modContext.feature(it) }.toTypedArray()
|
||||
|
||||
rules.forEach { ruleFeature ->
|
||||
modContext.features.getRuleFeatures().forEach { ruleFeature ->
|
||||
if (!friendFeedMenuOptions.contains(ruleFeature.ruleType.key)) return@forEach
|
||||
|
||||
val ruleState = ruleFeature.getRuleState() ?: return@forEach
|
||||
|
Loading…
x
Reference in New Issue
Block a user