mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 13:17:42 +02:00
feat: unsaveable messages
- fix(auto_save): prevent saving unsaveable messages
This commit is contained in:
@ -47,7 +47,7 @@ class AutoSave : MessagingRuleFeature("Auto Save", MessagingRuleType.AUTO_SAVE,
|
||||
}
|
||||
|
||||
fun canSaveMessage(message: Message, headless: Boolean = false): Boolean {
|
||||
if (message.messageState != MessageState.COMMITTED) return false
|
||||
if (message.messageState != MessageState.COMMITTED || message.messageMetadata?.isSaveable != true) return false
|
||||
|
||||
if (!headless && (context.mainActivity == null || context.isMainActivityPaused)) return false
|
||||
if (message.messageMetadata!!.savedBy!!.any { uuid -> uuid.toString() == context.database.myUserId }) return false
|
||||
|
@ -3,8 +3,8 @@ package me.rhunk.snapenhance.core.features.impl.messaging
|
||||
import me.rhunk.snapenhance.common.data.ContentType
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoEditor
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
|
||||
import me.rhunk.snapenhance.core.event.events.impl.SendMessageWithContentEvent
|
||||
import me.rhunk.snapenhance.core.event.events.impl.NativeUnaryCallEvent
|
||||
import me.rhunk.snapenhance.core.event.events.impl.SendMessageWithContentEvent
|
||||
import me.rhunk.snapenhance.core.features.Feature
|
||||
import me.rhunk.snapenhance.core.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.core.messaging.MessageSender
|
||||
@ -40,11 +40,8 @@ class SendOverride : Feature("Send Override", loadParams = FeatureLoadParams.INI
|
||||
}
|
||||
//make snaps savable in chat
|
||||
protoEditor.edit(4) {
|
||||
val savableState = firstOrNull(7)?.value ?: return@edit
|
||||
if (savableState == 2L) {
|
||||
remove(7)
|
||||
addVarInt(7, 3)
|
||||
}
|
||||
remove(7)
|
||||
addVarInt(7, 3)
|
||||
}
|
||||
}
|
||||
event.buffer = protoEditor.toByteArray()
|
||||
|
@ -0,0 +1,45 @@
|
||||
package me.rhunk.snapenhance.core.features.impl.tweaks
|
||||
|
||||
import me.rhunk.snapenhance.common.data.ContentType
|
||||
import me.rhunk.snapenhance.common.data.MessagingRuleType
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoEditor
|
||||
import me.rhunk.snapenhance.common.util.protobuf.ProtoReader
|
||||
import me.rhunk.snapenhance.core.event.events.impl.NativeUnaryCallEvent
|
||||
import me.rhunk.snapenhance.core.features.FeatureLoadParams
|
||||
import me.rhunk.snapenhance.core.features.MessagingRuleFeature
|
||||
import me.rhunk.snapenhance.core.wrapper.impl.SnapUUID
|
||||
|
||||
class UnsaveableMessages : MessagingRuleFeature(
|
||||
"Unsaveable Messages",
|
||||
MessagingRuleType.UNSAVEABLE_MESSAGES,
|
||||
loadParams = FeatureLoadParams.INIT_SYNC
|
||||
) {
|
||||
override fun init() {
|
||||
if (context.config.rules.getRuleState(MessagingRuleType.UNSAVEABLE_MESSAGES) == null) return
|
||||
|
||||
context.event.subscribe(NativeUnaryCallEvent::class) { event ->
|
||||
if (event.uri != "/messagingcoreservice.MessagingCoreService/CreateContentMessage") return@subscribe
|
||||
|
||||
val protoReader = ProtoReader(event.buffer)
|
||||
val conversationIds = mutableListOf<String>()
|
||||
|
||||
protoReader.eachBuffer(3) {
|
||||
if (contains(2)) {
|
||||
return@eachBuffer
|
||||
}
|
||||
conversationIds.add(SnapUUID.fromBytes(getByteArray(1, 1, 1) ?: return@eachBuffer).toString())
|
||||
}
|
||||
|
||||
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()) {
|
||||
remove(7)
|
||||
addVarInt(7, 3)
|
||||
}
|
||||
}
|
||||
}.toByteArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import me.rhunk.snapenhance.core.features.impl.spying.StealthMode
|
||||
import me.rhunk.snapenhance.core.features.impl.tweaks.BypassScreenshotDetection
|
||||
import me.rhunk.snapenhance.core.features.impl.tweaks.CameraTweaks
|
||||
import me.rhunk.snapenhance.core.features.impl.tweaks.PreventMessageListAutoScroll
|
||||
import me.rhunk.snapenhance.core.features.impl.tweaks.UnsaveableMessages
|
||||
import me.rhunk.snapenhance.core.features.impl.ui.*
|
||||
import me.rhunk.snapenhance.core.logger.CoreLogger
|
||||
import me.rhunk.snapenhance.core.manager.Manager
|
||||
@ -80,6 +81,7 @@ class FeatureManager(
|
||||
AutoSave::class,
|
||||
UITweaks::class,
|
||||
ConfigurationOverride::class,
|
||||
UnsaveableMessages::class,
|
||||
SendOverride::class,
|
||||
UnlimitedSnapViewTime::class,
|
||||
BypassVideoLengthRestriction::class,
|
||||
|
@ -23,4 +23,6 @@ class MessageMetadata(obj: Any?) : AbstractWrapper(obj){
|
||||
var reactions by field("mReactions") {
|
||||
(it as ArrayList<*>).map { i -> UserIdToReaction(i) }.toMutableList()
|
||||
}
|
||||
@get:JSGetter @set:JSSetter
|
||||
var isSaveable by field<Boolean>("mIsSaveable")
|
||||
}
|
Reference in New Issue
Block a user