mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-07 18:04:32 +02:00
feat(core/experimental): custom story expiration
- refactor send override
This commit is contained in:
parent
a01c2b09ca
commit
fe95a1bcc6
@ -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"
|
||||
|
@ -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()}
|
||||
|
@ -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, {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user