commit b46139c3ad8d5aac95689171a501e45f13d94a47
parent 9e547bfe0ccd72feba961336570f42065d8109ae
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 24 Sep 2023 16:51:31 +0200

refactor: rule features

Diffstat:
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/UserInterfaceTweaks.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/messaging/MessagingCoreObjects.kt | 9+++++----
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/util/protobuf/ProtoEditor.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/AbstractWrapper.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/impl/SnapUUID.kt | 2++
Mcore/src/main/kotlin/me/rhunk/snapenhance/features/impl/downloader/MediaDownloader.kt | 13+++++--------
Mcore/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt | 4++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/FriendFeedInfoMenu.kt | 12+-----------
8 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/UserInterfaceTweaks.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/config/impl/UserInterfaceTweaks.kt @@ -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)) } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/messaging/MessagingCoreObjects.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/messaging/MessagingCoreObjects.kt @@ -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 { diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/util/protobuf/ProtoEditor.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/util/protobuf/ProtoEditor.kt @@ -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()) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/AbstractWrapper.kt b/core/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/AbstractWrapper.kt @@ -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) } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/impl/SnapUUID.kt b/core/src/main/kotlin/me/rhunk/snapenhance/data/wrapper/impl/SnapUUID.kt @@ -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 } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/features/impl/downloader/MediaDownloader.kt b/core/src/main/kotlin/me/rhunk/snapenhance/features/impl/downloader/MediaDownloader.kt @@ -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"]) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt @@ -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, diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/FriendFeedInfoMenu.kt b/core/src/main/kotlin/me/rhunk/snapenhance/ui/menu/impl/FriendFeedInfoMenu.kt @@ -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