commit fe95a1bcc64d27d3e7ebd8f55ad7778de77942ed
parent a01c2b09ca9c344d8e95e92a0734c9cf544eb28d
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 11 Oct 2023 23:58:33 +0200

feat(core/experimental): custom story expiration
- refactor send override

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 8++++----
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/SendOverride.kt | 44++++++++++++++++++++++++++------------------
Mnative/src/main/kotlin/me/rhunk/snapenhance/nativelib/NativeLib.kt | 3++-
4 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -460,10 +460,6 @@ "disable_bitmoji": { "name": "Disable Bitmoji", "description": "Disables Friends Profile Bitmoji" - }, - "fix_gallery_media_override": { - "name": "Fix Gallery Media Override", - "description": "Fixes various issues with the Gallery Media Send Override feature (e.g. Save Snaps in chat)" } } }, @@ -519,6 +515,10 @@ "name": "Infinite Story Boost", "description": "Bypass the Story Boost Limit delay" }, + "custom_story_expiration": { + "name": "Custom Story Expiration", + "description": "Set a custom story expiration time in hours (0 to disable)" + }, "meo_passcode_bypass": { "name": "My Eyes Only Passcode Bypass", "description": "Bypass the My Eyes Only passcode\nThis will only work if the passcode has been entered correctly before" 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 @@ -6,7 +6,6 @@ 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() } @@ -15,6 +14,7 @@ class Experimental : ConfigContainer() { val appPasscode = string("app_passcode") val appLockOnResume = boolean("app_lock_on_resume") val infiniteStoryBoost = boolean("infinite_story_boost") + val customStoryExpiration = integer("custom_story_expiration") { requireRestart(); nativeHooks() } val meoPasscodeBypass = boolean("meo_passcode_bypass") val unlimitedMultiSnap = boolean("unlimited_multi_snap") { addNotices(FeatureNotice.BAN_RISK)} val noFriendScoreDelay = boolean("no_friend_score_delay") { requireRestart()} diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/SendOverride.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/SendOverride.kt @@ -10,49 +10,57 @@ import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.FeatureLoadParams import me.rhunk.snapenhance.core.messaging.MessageSender import me.rhunk.snapenhance.core.ui.ViewAppearanceHelper +import me.rhunk.snapenhance.nativelib.NativeLib +import kotlin.math.absoluteValue class SendOverride : Feature("Send Override", loadParams = FeatureLoadParams.INIT_SYNC) { private var isLastSnapSavable = false - - override fun init() { - val fixGalleryMediaSendOverride = context.config.experimental.nativeHooks.let { - it.globalState == true && it.fixGalleryMediaOverride.get() - } - val typeNames = mutableListOf( + private val typeNames by lazy { + mutableListOf( "ORIGINAL", "SNAP", "NOTE" ).also { - if (fixGalleryMediaSendOverride) { + if (NativeLib.initialized) { it.add("SAVABLE_SNAP") } }.associateWith { - it + it } + } - context.event.subscribe(UnaryCallEvent::class, { fixGalleryMediaSendOverride }) { event -> + override fun init() { + context.event.subscribe(UnaryCallEvent::class) { event -> if (event.uri != "/messagingcoreservice.MessagingCoreService/CreateContentMessage") return@subscribe - if (!isLastSnapSavable) return@subscribe - ProtoReader(event.buffer).also { - // only affect snaps - if (!it.containsPath(*Constants.ARROYO_MEDIA_CONTAINER_PROTO_PATH, 11)) return@subscribe + val protoEditor = ProtoEditor(event.buffer) + + context.config.experimental.customStoryExpiration.get().takeIf { it > 0 }?.absoluteValue?.also { expirationInHours -> + protoEditor.edit(3, 2, 2) { + remove(1) + add(1) { + from(2) { + addVarInt(1, expirationInHours) + context.log.verbose("add story expiration to $expirationInHours hours") + } + } + } } - event.buffer = ProtoEditor(event.buffer).apply { - //remove the max view time - edit(*Constants.ARROYO_MEDIA_CONTAINER_PROTO_PATH, 11, 5, 2) { + if (isLastSnapSavable && ProtoReader(event.buffer).containsPath(*Constants.ARROYO_MEDIA_CONTAINER_PROTO_PATH, 11)) { + protoEditor.edit(*Constants.ARROYO_MEDIA_CONTAINER_PROTO_PATH, 11, 5, 2) { remove(8) addBuffer(6, byteArrayOf()) } //make snaps savable in chat - edit(4) { + protoEditor.edit(4) { val savableState = firstOrNull(7)?.value ?: return@edit if (savableState == 2L) { remove(7) addVarInt(7, 3) } } - }.toByteArray() + } + event.buffer = protoEditor.toByteArray() } context.event.subscribe(SendMessageWithContentEvent::class, { diff --git a/native/src/main/kotlin/me/rhunk/snapenhance/nativelib/NativeLib.kt b/native/src/main/kotlin/me/rhunk/snapenhance/nativelib/NativeLib.kt @@ -5,7 +5,8 @@ import android.util.Log class NativeLib { var nativeUnaryCallCallback: (NativeRequestData) -> Unit = {} companion object { - private var initialized = false + var initialized = false + private set } fun initOnce(classloader: ClassLoader) {