Skip to content

Commit

Permalink
fix(core): notification blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Mar 11, 2024
1 parent 31932d7 commit bea8e79
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN
sendNotification(message, data, false)
}

private fun canSendNotification(type: String): Boolean {
val formattedMessageType = type.replaceFirst("mischief_", "")
.replaceFirst("group_your_", "group_")
.replaceFirst("group_other_", "group_")

return context.config.messaging.notificationBlacklist.get().mapNotNull {
NotificationType.getByKey(it)
}.none {
it.isMatch(formattedMessageType)
}.also {
if (!it) context.log.debug("prevented notification of type $type")
}
}

override fun init() {
setupBroadcastReceiverHook()

Expand All @@ -414,6 +428,12 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN

val serverMessageId = extras.getString("message_id") ?: return@hook
val notificationType = extras.getString("notification_type")?.lowercase() ?: return@hook

if (!canSendNotification(notificationType)) {
param.setResult(null)
return@hook
}

if (!betterNotificationFilter.contains("chat_preview") && !betterNotificationFilter.contains("media_preview")) return@hook
if (notificationType == "typing") return@hook
param.setResult(null)
Expand Down Expand Up @@ -466,11 +486,7 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN

context.log.debug("received message type: $messageType")

val formattedMessageType = messageType.replaceFirst("mischief_", "")
.replaceFirst("group_your_", "group_")
.replaceFirst("group_other_", "group_")

if (states.mapNotNull { NotificationType.getByKey(it) }.any { it.isMatch(formattedMessageType) }) {
if (!canSendNotification(messageType)) {
param.setResult(null)
}
}
Expand Down

0 comments on commit bea8e79

Please sign in to comment.