feat: prevent snap replays

This commit is contained in:
rhunk
2023-10-09 21:10:27 +02:00
parent e0f6d05676
commit 1a40856ae7
3 changed files with 16 additions and 1 deletions

View File

@ -622,6 +622,7 @@
"notifications": {
"chat_screenshot": "Screenshot",
"chat_screen_record": "Screen Record",
"snap_replay": "Snap Replay",
"camera_roll_save": "Camera Roll Save",
"chat": "Chat",
"chat_reply": "Chat Reply",

View File

@ -14,6 +14,7 @@ enum class NotificationType (
SCREENSHOT("chat_screenshot", true, ContentType.STATUS_CONVERSATION_CAPTURE_SCREENSHOT),
SCREEN_RECORD("chat_screen_record", true, ContentType.STATUS_CONVERSATION_CAPTURE_RECORD),
CAMERA_ROLL_SAVE("camera_roll_save", true, ContentType.STATUS_SAVE_TO_CAMERA_ROLL),
SNAP_REPLAY("snap_replay", true, ContentType.STATUS),
SNAP("snap",true),
CHAT("chat",true),
CHAT_REPLY("chat_reply",true),

View File

@ -1,6 +1,8 @@
package me.rhunk.snapenhance.features.impl.privacy
import me.rhunk.snapenhance.core.event.events.impl.SendMessageWithContentEvent
import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent
import me.rhunk.snapenhance.core.util.protobuf.ProtoEditor
import me.rhunk.snapenhance.data.NotificationType
import me.rhunk.snapenhance.features.Feature
import me.rhunk.snapenhance.features.FeatureLoadParams
@ -11,8 +13,19 @@ class PreventMessageSending : Feature("Prevent message sending", loadParams = Fe
override fun asyncOnActivityCreate() {
val preventMessageSending by context.config.messaging.preventMessageSending
context.event.subscribe(UnaryCallEvent::class, { preventMessageSending.contains("snap_replay") }) { event ->
if (event.uri != "/messagingcoreservice.MessagingCoreService/UpdateContentMessage") return@subscribe
event.buffer = ProtoEditor(event.buffer).apply {
edit(3) {
// replace replayed to read receipt
remove(13)
addBuffer(4, byteArrayOf())
}
}.toByteArray()
}
context.classCache.conversationManager.hook("updateMessage", HookStage.BEFORE) { param ->
val messageUpdate = param.arg<Any>(2).toString();
val messageUpdate = param.arg<Any>(2).toString()
if (messageUpdate == "SCREENSHOT" && preventMessageSending.contains("chat_screenshot")) {
param.setResult(null)
}