commit 80e37306a4a52ef79aedf6c2a1acaf0601a1fc26
parent dd8c51fe55220ad86d37b560b90bd66768bc91ab
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun,  3 Dec 2023 19:04:34 +0100

feat: half swipe notifier duration range

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 12+++++++++++-
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt | 12+++++++++++-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/HalfSwipeNotifier.kt | 13+++++++++----
3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -363,7 +363,17 @@ }, "half_swipe_notifier": { "name": "Half Swipe Notifier", - "description": "Notifies you when someone half swipes into a conversation" + "description": "Notifies you when someone half swipes into a conversation", + "properties": { + "min_duration": { + "name": "Minimum Duration", + "description": "The minimum duration of the half swipe (in seconds)" + }, + "max_duration": { + "name": "Maximum Duration", + "description": "The maximum duration of the half swipe (in seconds)" + } + } }, "message_preview_length": { "name": "Message Preview Length", diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt @@ -2,9 +2,19 @@ package me.rhunk.snapenhance.common.config.impl import me.rhunk.snapenhance.common.config.ConfigContainer import me.rhunk.snapenhance.common.config.FeatureNotice +import me.rhunk.snapenhance.common.config.PropertyValue import me.rhunk.snapenhance.common.data.NotificationType class MessagingTweaks : ConfigContainer() { + inner class HalfSwipeNotifierConfig : ConfigContainer(hasGlobalState = true) { + val minDuration: PropertyValue<Int> = integer("min_duration", defaultValue = 0) { + inputCheck = { it.toIntOrNull()?.coerceAtLeast(0) != null && maxDuration.get() >= it.toInt() } + } + val maxDuration: PropertyValue<Int> = integer("max_duration", defaultValue = 20) { + inputCheck = { it.toIntOrNull()?.coerceAtLeast(0) != null && minDuration.get() <= it.toInt() } + } + } + val bypassScreenshotDetection = boolean("bypass_screenshot_detection") { requireRestart() } val anonymousStoryViewing = boolean("anonymous_story_viewing") val preventStoryRewatchIndicator = boolean("prevent_story_rewatch_indicator") { requireRestart() } @@ -13,7 +23,7 @@ class MessagingTweaks : ConfigContainer() { val hideTypingNotifications = boolean("hide_typing_notifications") val unlimitedSnapViewTime = boolean("unlimited_snap_view_time") val disableReplayInFF = boolean("disable_replay_in_ff") - val halfSwipeNotifier = boolean("half_swipe_notifier") { requireRestart() } + val halfSwipeNotifier = container("half_swipe_notifier", HalfSwipeNotifierConfig()) { requireRestart()} val messagePreviewLength = integer("message_preview_length", defaultValue = 20) val callStartConfirmation = boolean("call_start_confirmation") { requireRestart() } val autoSaveMessagesInConversations = multiple("auto_save_messages_in_conversations", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/HalfSwipeNotifier.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/HalfSwipeNotifier.kt @@ -36,7 +36,7 @@ class HalfSwipeNotifier : Feature("Half Swipe Notifier", loadParams = FeatureLoa override fun init() { - if (!context.config.messaging.halfSwipeNotifier.get()) return + if (context.config.messaging.halfSwipeNotifier.globalState != true) return lateinit var presenceService: Any findClass("com.snapchat.talkcorev3.PresenceService\$CppProxy").hookConstructor(HookStage.AFTER) { @@ -84,7 +84,12 @@ class HalfSwipeNotifier : Feature("Half Swipe Notifier", loadParams = FeatureLoa private fun endPeeking(conversationId: String, userId: String) { startPeekingTimestamps[conversationId + userId]?.let { startPeekingTimestamp -> - val peekingDuration = (System.currentTimeMillis() - startPeekingTimestamp).milliseconds.inWholeSeconds.toString() + val peekingDuration = (System.currentTimeMillis() - startPeekingTimestamp).milliseconds.inWholeSeconds + val minDuration = context.config.messaging.halfSwipeNotifier.minDuration.get().toLong() + val maxDuration = context.config.messaging.halfSwipeNotifier.maxDuration.get().toLong() + + if (minDuration > peekingDuration || maxDuration < peekingDuration) return + val groupName = context.database.getFeedEntryByConversationId(conversationId)?.feedDisplayName val friendInfo = context.database.getFriendInfo(userId) ?: return @@ -94,12 +99,12 @@ class HalfSwipeNotifier : Feature("Half Swipe Notifier", loadParams = FeatureLoa translation.format("notification_content_group", "friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(), "group" to groupName, - "duration" to peekingDuration + "duration" to peekingDuration.toString() ) } else { translation.format("notification_content_dm", "friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(), - "duration" to peekingDuration + "duration" to peekingDuration.toString() ) }) .setContentIntent(