mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 21:27:47 +02:00
feat(core): auto mark as read
This commit is contained in:
@ -64,10 +64,10 @@ class FeatureManager(
|
||||
ScopeSync(),
|
||||
PreventMessageListAutoScroll(),
|
||||
Messaging(),
|
||||
AutoMarkAsRead(),
|
||||
MediaDownloader(),
|
||||
StealthMode(),
|
||||
MenuViewInjector(),
|
||||
PreventReadReceipts(),
|
||||
MessageLogger(),
|
||||
ConvertMessageLocally(),
|
||||
SnapchatPlus(),
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user