fix(core): snap save policy

This commit is contained in:
rhunk
2024-03-17 12:59:55 +01:00
parent 598128ea0d
commit aa936cb5ae
2 changed files with 6 additions and 12 deletions

View File

@ -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()

View File

@ -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()