commit aa936cb5ae2ba3db672966b08aef4b86abeb5555
parent 598128ea0d39667c6282d5d28819b2b99285dbaf
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 17 Mar 2024 12:59:55 +0100

fix(core): snap save policy

Diffstat:
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/SendOverride.kt | 13+++----------
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/UnsaveableMessages.kt | 5+++--
2 files changed, 6 insertions(+), 12 deletions(-)

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 @@ -13,7 +13,6 @@ import me.rhunk.snapenhance.nativelib.NativeLib class SendOverride : Feature("Send Override", loadParams = FeatureLoadParams.INIT_SYNC) { private var isLastSnapSavable = false - private val arroyoMessageContainerPath = intArrayOf(4, 4) private val typeNames by lazy { mutableListOf( "ORIGINAL", @@ -31,20 +30,14 @@ class SendOverride : Feature("Send Override", loadParams = FeatureLoadParams.INI override fun init() { context.event.subscribe(NativeUnaryCallEvent::class) { event -> if (event.uri != "/messagingcoreservice.MessagingCoreService/CreateContentMessage") return@subscribe - val protoEditor = ProtoEditor(event.buffer) - - if (isLastSnapSavable && ProtoReader(event.buffer).containsPath(*arroyoMessageContainerPath, 11)) { - protoEditor.edit(*arroyoMessageContainerPath, 11, 5, 2) { - remove(8) - addBuffer(6, byteArrayOf()) - } - //make snaps savable in chat + if (isLastSnapSavable) { + val protoEditor = ProtoEditor(event.buffer) protoEditor.edit(4) { remove(7) addVarInt(7, 3) } + event.buffer = protoEditor.toByteArray() } - event.buffer = protoEditor.toByteArray() } val stripSnapMetadata = context.config.messaging.stripMediaMetadata.get() diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/UnsaveableMessages.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/UnsaveableMessages.kt @@ -33,9 +33,10 @@ class UnsaveableMessages : MessagingRuleFeature( if (conversationIds.all { canUseRule(it) }) { event.buffer = ProtoEditor(event.buffer).apply { edit(4) { - if ((firstOrNull(7)?.value ?: return@edit) == 2L && firstOrNull(2)?.value != ContentType.SNAP.id.toLong()) { + val contentType = firstOrNull(2)?.value + if (contentType != ContentType.STATUS.id.toLong()) { remove(7) - addVarInt(7, 3) + addVarInt(7, 1) // set savePolicy to PROHIBITED } } }.toByteArray()