commit 1a7755e45cc02081c9e3a6bf57a938beae6c3947
parent 3c13f14c07e3a95d2aef66d954c69e733b260cfd
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 11 Oct 2023 16:46:21 +0200

refactor: snap to chat media as experimental

Diffstat:
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt | 6++++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt | 1-
Dcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/NativeHooks.kt | 9---------
Acore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/SnapToChatMedia.kt | 26++++++++++++++++++++++++++
Dcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/SnapToChatMedia.kt | 26--------------------------
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt | 2+-
6 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt @@ -4,8 +4,14 @@ import me.rhunk.snapenhance.common.config.ConfigContainer import me.rhunk.snapenhance.common.config.FeatureNotice class Experimental : ConfigContainer() { + class NativeHooks : ConfigContainer(hasGlobalState = true) { + val disableBitmoji = boolean("disable_bitmoji") + val fixGalleryMediaOverride = boolean("fix_gallery_media_override") + } + val nativeHooks = container("native_hooks", NativeHooks()) { icon = "Memory"; requireRestart() } val spoof = container("spoof", Spoof()) { icon = "Fingerprint" } + val snapToChatMedia = boolean("snap_to_chat_media") { requireRestart(); addNotices(FeatureNotice.UNSTABLE) } val appPasscode = string("app_passcode") val appLockOnResume = boolean("app_lock_on_resume") val infiniteStoryBoost = boolean("infinite_story_boost") diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt @@ -17,7 +17,6 @@ class MessagingTweaks : ConfigContainer() { "EXTERNAL_MEDIA", "STICKER" ) { requireRestart() } - val snapToChatMedia = boolean("snap_to_chat_media") { requireRestart() } val preventMessageSending = multiple("prevent_message_sending", *NotificationType.getOutgoingValues().map { it.key }.toTypedArray()) { customOptionTranslationPath = "features.options.notifications" } diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/NativeHooks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/NativeHooks.kt @@ -1,8 +0,0 @@ -package me.rhunk.snapenhance.common.config.impl - -import me.rhunk.snapenhance.common.config.ConfigContainer - -class NativeHooks: ConfigContainer(hasGlobalState = true) { - val disableBitmoji = boolean("disable_bitmoji") - val fixGalleryMediaOverride = boolean("fix_gallery_media_override") -}- \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/SnapToChatMedia.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/SnapToChatMedia.kt @@ -0,0 +1,25 @@ +package me.rhunk.snapenhance.core.features.impl.experiments + +import me.rhunk.snapenhance.common.data.ContentType +import me.rhunk.snapenhance.common.util.protobuf.ProtoReader +import me.rhunk.snapenhance.common.util.protobuf.ProtoWriter +import me.rhunk.snapenhance.core.event.events.impl.BuildMessageEvent +import me.rhunk.snapenhance.core.features.Feature +import me.rhunk.snapenhance.core.features.FeatureLoadParams + +class SnapToChatMedia : Feature("SnapToChatMedia", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { + override fun onActivityCreate() { + if (!context.config.experimental.snapToChatMedia.get()) return + + context.event.subscribe(BuildMessageEvent::class, priority = 100) { event -> + if (event.message.messageContent.contentType != ContentType.SNAP) return@subscribe + + val snapMessageContent = ProtoReader(event.message.messageContent.content).followPath(11)?.getBuffer() ?: return@subscribe + event.message.messageContent.content = ProtoWriter().apply { + from(3) { + addBuffer(3, snapMessageContent) + } + }.toByteArray() + } + } +}+ \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/SnapToChatMedia.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/SnapToChatMedia.kt @@ -1,25 +0,0 @@ -package me.rhunk.snapenhance.core.features.impl.spying - -import me.rhunk.snapenhance.common.data.ContentType -import me.rhunk.snapenhance.common.util.protobuf.ProtoReader -import me.rhunk.snapenhance.common.util.protobuf.ProtoWriter -import me.rhunk.snapenhance.core.event.events.impl.BuildMessageEvent -import me.rhunk.snapenhance.core.features.Feature -import me.rhunk.snapenhance.core.features.FeatureLoadParams - -class SnapToChatMedia : Feature("SnapToChatMedia", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { - override fun onActivityCreate() { - if (!context.config.messaging.snapToChatMedia.get()) return - - context.event.subscribe(BuildMessageEvent::class, priority = 100) { event -> - if (event.message.messageContent.contentType != ContentType.SNAP) return@subscribe - - val snapMessageContent = ProtoReader(event.message.messageContent.content).followPath(11)?.getBuffer() ?: return@subscribe - event.message.messageContent.content = ProtoWriter().apply { - from(3) { - addBuffer(3, snapMessageContent) - } - }.toByteArray() - } - } -}- \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt @@ -15,7 +15,7 @@ import me.rhunk.snapenhance.core.features.impl.experiments.* import me.rhunk.snapenhance.core.features.impl.global.* import me.rhunk.snapenhance.core.features.impl.messaging.* import me.rhunk.snapenhance.core.features.impl.spying.MessageLogger -import me.rhunk.snapenhance.core.features.impl.spying.SnapToChatMedia +import me.rhunk.snapenhance.core.features.impl.experiments.SnapToChatMedia import me.rhunk.snapenhance.core.features.impl.spying.StealthMode import me.rhunk.snapenhance.core.features.impl.tweaks.CameraTweaks import me.rhunk.snapenhance.core.features.impl.ui.*