commit de1b80c2a4b21c1596e1deb456f601c82edf51e9
parent 8f699e39020422f18a77dc6f0b0c9f373572a9a2
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 15 Oct 2023 23:23:13 +0200

fix(notifications): blacklist aliases

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 5++---
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/data/SnapEnums.kt | 14+++++++++++---
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt | 10++++++----
3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -635,9 +635,8 @@ "snap": "Snap", "typing": "Typing", "stories": "Stories", - "chat_reaction": "Chat Reaction", - "snap_reaction": "Snap Reaction", - "voicenote_reaction": "Voice note Reaction", + "chat_reaction": "DM Reaction", + "group_chat_reaction": "Group Reaction", "initiate_audio": "Incoming Audio Call", "abandon_audio": "Missed Audio Call", "initiate_video": "Incoming Video Call", diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/data/SnapEnums.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/data/SnapEnums.kt @@ -10,6 +10,7 @@ enum class NotificationType ( val key: String, val isIncoming: Boolean = false, val associatedOutgoingContentType: ContentType? = null, + private vararg val aliases: String ) { SCREENSHOT("chat_screenshot", true, ContentType.STATUS_CONVERSATION_CAPTURE_SCREENSHOT), SCREEN_RECORD("chat_screen_record", true, ContentType.STATUS_CONVERSATION_CAPTURE_RECORD), @@ -20,15 +21,22 @@ enum class NotificationType ( CHAT_REPLY("chat_reply",true), TYPING("typing", true), STORIES("stories",true), - CHAT_REACTION("chat_reaction", true), - SNAP_REACTION("snap_reaction", true), - VOICENOTE_REACTION("voicenote_reaction", true), + DM_REACTION("chat_reaction", true, null,"snap_reaction", "voicenote_reaction"), + GROUP_REACTION("group_chat_reaction", true, null,"group_snap_reaction", "group_voicenote_reaction"), INITIATE_AUDIO("initiate_audio",true), ABANDON_AUDIO("abandon_audio", false, ContentType.STATUS_CALL_MISSED_AUDIO), INITIATE_VIDEO("initiate_video",true), ABANDON_VIDEO("abandon_video", false, ContentType.STATUS_CALL_MISSED_VIDEO); + fun isMatch(key: String): Boolean { + return this.key == key || aliases.contains(key) + } + companion object { + fun getByKey(key: String): NotificationType? { + return entries.firstOrNull { it.key == key } + } + fun getIncomingValues(): List<NotificationType> { return entries.filter { it.isIncoming }.toList() } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/Notifications.kt @@ -14,6 +14,7 @@ import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.XposedHelpers import me.rhunk.snapenhance.common.data.ContentType import me.rhunk.snapenhance.common.data.MediaReferenceType +import me.rhunk.snapenhance.common.data.NotificationType import me.rhunk.snapenhance.common.data.download.SplitMediaAssetType import me.rhunk.snapenhance.common.util.protobuf.ProtoReader import me.rhunk.snapenhance.common.util.snap.MediaDownloaderHelper @@ -354,10 +355,11 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN context.log.debug("received message type: $messageType") - if (states.contains(messageType.replaceFirst("mischief_", "") - .replaceFirst("group_your_", "") - .replaceFirst("group_other_", "")) - ) { + val formattedMessageType = messageType.replaceFirst("mischief_", "") + .replaceFirst("group_your_", "group_") + .replaceFirst("group_other_", "group_") + + if (states.mapNotNull { NotificationType.getByKey(it) }.any { it.isMatch(formattedMessageType) }) { param.setResult(null) } }