commit 8da3bf86b4e1d2ce4cac2f1e64906adf14646060
parent f2762840f06b8b6f11496849347d64531b4c5548
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Wed, 10 Apr 2024 22:50:04 +0200
feat(core): auto mark as read
Diffstat:
6 files changed, 68 insertions(+), 35 deletions(-)
diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json
@@ -488,6 +488,10 @@
"name": "Unlimited Snap View Time",
"description": "Removes the Time Limit for viewing Snaps"
},
+ "auto_mark_as_read": {
+ "name": "Auto Mark as Read",
+ "description": "Automatically marks messages as read when sending a message to a conversation, even when Stealth Mode is enabled"
+ },
"loop_media_playback": {
"name": "Loop Media Playback",
"description": "Loops media playback when viewing Snaps / Stories"
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
@@ -55,6 +55,7 @@ class MessagingTweaks : ConfigContainer() {
val hideBitmojiPresence = boolean("hide_bitmoji_presence")
val hideTypingNotifications = boolean("hide_typing_notifications")
val unlimitedSnapViewTime = boolean("unlimited_snap_view_time")
+ val autoMarkAsRead = boolean("auto_mark_as_read") { requireRestart() }
val loopMediaPlayback = boolean("loop_media_playback") { requireRestart() }
val disableReplayInFF = boolean("disable_replay_in_ff")
val halfSwipeNotifier = container("half_swipe_notifier", HalfSwipeNotifierConfig()) { requireRestart()}
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/FeatureManager.kt
@@ -64,10 +64,10 @@ class FeatureManager(
ScopeSync(),
PreventMessageListAutoScroll(),
Messaging(),
+ AutoMarkAsRead(),
MediaDownloader(),
StealthMode(),
MenuViewInjector(),
- PreventReadReceipts(),
MessageLogger(),
ConvertMessageLocally(),
SnapchatPlus(),
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/AutoMarkAsRead.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/AutoMarkAsRead.kt
@@ -0,0 +1,26 @@
+package me.rhunk.snapenhance.core.features.impl.messaging
+
+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.features.impl.spying.StealthMode
+
+class AutoMarkAsRead : Feature("Auto Mark As Read", loadParams = FeatureLoadParams.INIT_SYNC) {
+ override fun init() {
+ if (!context.config.messaging.autoMarkAsRead.get()) return
+
+ context.event.subscribe(SendMessageWithContentEvent::class) { event ->
+ event.addCallbackResult("onSuccess") {
+ event.destinations.conversations!!.map { it.toString() }.forEach { conversationId ->
+ val lastClientMessageId = context.database.getMessagesFromConversationId(conversationId, 1)?.firstOrNull()?.clientMessageId?.toLong() ?: Long.MAX_VALUE
+ context.feature(StealthMode::class).addDisplayedMessageException(lastClientMessageId)
+ context.feature(Messaging::class).conversationManager?.displayedMessages(conversationId, lastClientMessageId) {
+ if (it != null) {
+ context.log.warn("Failed to mark message $lastClientMessageId as read in conversation $conversationId")
+ }
+ }
+ }
+ }
+ }
+ }
+}+
\ No newline at end of file
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/PreventReadReceipts.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/PreventReadReceipts.kt
@@ -1,31 +0,0 @@
-package me.rhunk.snapenhance.core.features.impl.messaging
-
-import me.rhunk.snapenhance.core.event.events.impl.OnSnapInteractionEvent
-import me.rhunk.snapenhance.core.features.Feature
-import me.rhunk.snapenhance.core.features.FeatureLoadParams
-import me.rhunk.snapenhance.core.features.impl.spying.StealthMode
-import me.rhunk.snapenhance.core.util.hook.HookStage
-import me.rhunk.snapenhance.core.util.hook.Hooker
-import me.rhunk.snapenhance.core.wrapper.impl.SnapUUID
-
-class PreventReadReceipts : Feature("PreventReadReceipts", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
- override fun onActivityCreate() {
- val isConversationInStealthMode: (SnapUUID) -> Boolean = hook@{
- context.feature(StealthMode::class).canUseRule(it.toString())
- }
-
- arrayOf("mediaMessagesDisplayed", "displayedMessages").forEach { methodName: String ->
- Hooker.hook(context.classCache.conversationManager, methodName, HookStage.BEFORE, { isConversationInStealthMode(
- SnapUUID(it.arg(0))
- ) }) {
- it.setResult(null)
- }
- }
-
- context.event.subscribe(OnSnapInteractionEvent::class) { event ->
- if (isConversationInStealthMode(event.conversationId)) {
- event.canceled = true
- }
- }
- }
-}-
\ No newline at end of file
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/StealthMode.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/spying/StealthMode.kt
@@ -1,6 +1,39 @@
package me.rhunk.snapenhance.core.features.impl.spying
import me.rhunk.snapenhance.common.data.MessagingRuleType
+import me.rhunk.snapenhance.core.event.events.impl.OnSnapInteractionEvent
+import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.features.MessagingRuleFeature
+import me.rhunk.snapenhance.core.util.hook.HookStage
+import me.rhunk.snapenhance.core.util.hook.hook
+import me.rhunk.snapenhance.core.wrapper.impl.SnapUUID
+import java.util.concurrent.CopyOnWriteArraySet
-class StealthMode : MessagingRuleFeature("StealthMode", MessagingRuleType.STEALTH)-
\ No newline at end of file
+class StealthMode : MessagingRuleFeature("StealthMode", MessagingRuleType.STEALTH, loadParams = FeatureLoadParams.INIT_SYNC) {
+ private val displayedMessageQueue = CopyOnWriteArraySet<Long>()
+
+ fun addDisplayedMessageException(clientMessageId: Long) {
+ displayedMessageQueue.add(clientMessageId)
+ }
+
+ override fun init() {
+ val isConversationInStealthMode: (SnapUUID) -> Boolean = hook@{
+ context.feature(StealthMode::class).canUseRule(it.toString())
+ }
+
+ arrayOf("mediaMessagesDisplayed", "displayedMessages").forEach { methodName: String ->
+ context.classCache.conversationManager.hook(methodName, HookStage.BEFORE) { param ->
+ if (displayedMessageQueue.removeIf { param.arg<Long>(1) == it }) return@hook
+ if (isConversationInStealthMode(SnapUUID(param.arg(0)))) {
+ param.setResult(null)
+ }
+ }
+ }
+
+ context.event.subscribe(OnSnapInteractionEvent::class) { event ->
+ if (isConversationInStealthMode(event.conversationId)) {
+ event.canceled = true
+ }
+ }
+ }
+}+
\ No newline at end of file