feat: half swipe notifier duration range

This commit is contained in:
rhunk
2023-12-03 19:04:34 +01:00
parent dd8c51fe55
commit 80e37306a4
3 changed files with 31 additions and 6 deletions

View File

@ -363,7 +363,17 @@
}, },
"half_swipe_notifier": { "half_swipe_notifier": {
"name": "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": { "message_preview_length": {
"name": "Message Preview Length", "name": "Message Preview Length",

View File

@ -2,9 +2,19 @@ package me.rhunk.snapenhance.common.config.impl
import me.rhunk.snapenhance.common.config.ConfigContainer import me.rhunk.snapenhance.common.config.ConfigContainer
import me.rhunk.snapenhance.common.config.FeatureNotice import me.rhunk.snapenhance.common.config.FeatureNotice
import me.rhunk.snapenhance.common.config.PropertyValue
import me.rhunk.snapenhance.common.data.NotificationType import me.rhunk.snapenhance.common.data.NotificationType
class MessagingTweaks : ConfigContainer() { 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 bypassScreenshotDetection = boolean("bypass_screenshot_detection") { requireRestart() }
val anonymousStoryViewing = boolean("anonymous_story_viewing") val anonymousStoryViewing = boolean("anonymous_story_viewing")
val preventStoryRewatchIndicator = boolean("prevent_story_rewatch_indicator") { requireRestart() } val preventStoryRewatchIndicator = boolean("prevent_story_rewatch_indicator") { requireRestart() }
@ -13,7 +23,7 @@ class MessagingTweaks : ConfigContainer() {
val hideTypingNotifications = boolean("hide_typing_notifications") val hideTypingNotifications = boolean("hide_typing_notifications")
val unlimitedSnapViewTime = boolean("unlimited_snap_view_time") val unlimitedSnapViewTime = boolean("unlimited_snap_view_time")
val disableReplayInFF = boolean("disable_replay_in_ff") 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 messagePreviewLength = integer("message_preview_length", defaultValue = 20)
val callStartConfirmation = boolean("call_start_confirmation") { requireRestart() } val callStartConfirmation = boolean("call_start_confirmation") { requireRestart() }
val autoSaveMessagesInConversations = multiple("auto_save_messages_in_conversations", val autoSaveMessagesInConversations = multiple("auto_save_messages_in_conversations",

View File

@ -36,7 +36,7 @@ class HalfSwipeNotifier : Feature("Half Swipe Notifier", loadParams = FeatureLoa
override fun init() { override fun init() {
if (!context.config.messaging.halfSwipeNotifier.get()) return if (context.config.messaging.halfSwipeNotifier.globalState != true) return
lateinit var presenceService: Any lateinit var presenceService: Any
findClass("com.snapchat.talkcorev3.PresenceService\$CppProxy").hookConstructor(HookStage.AFTER) { 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) { private fun endPeeking(conversationId: String, userId: String) {
startPeekingTimestamps[conversationId + userId]?.let { startPeekingTimestamp -> 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 groupName = context.database.getFeedEntryByConversationId(conversationId)?.feedDisplayName
val friendInfo = context.database.getFriendInfo(userId) ?: return val friendInfo = context.database.getFriendInfo(userId) ?: return
@ -94,12 +99,12 @@ class HalfSwipeNotifier : Feature("Half Swipe Notifier", loadParams = FeatureLoa
translation.format("notification_content_group", translation.format("notification_content_group",
"friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(), "friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(),
"group" to groupName, "group" to groupName,
"duration" to peekingDuration "duration" to peekingDuration.toString()
) )
} else { } else {
translation.format("notification_content_dm", translation.format("notification_content_dm",
"friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(), "friend" to (friendInfo.displayName ?: friendInfo.mutableUsername).toString(),
"duration" to peekingDuration "duration" to peekingDuration.toString()
) )
}) })
.setContentIntent( .setContentIntent(