From 888ed9643f2dfe6d25cd3ede4a7ac3ff04064bb4 Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 21 May 2024 17:23:54 +0200 Subject: [PATCH] handle notifications throttling on backlog finish event --- .../services/NotificationService.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index d8d959ee5..6ee478939 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -395,7 +395,23 @@ public class NotificationService { count = getBacklogMessageCount(account); } - updateNotification(count > 0, conversations); + boolean shouldNotify = count > 0; + + if (shouldNotify) { + boolean allConversationsShouldBeThrottled = true; + for (String c : conversations) { + if (!shouldNotificationSoundBeThrottled(c)) { + allConversationsShouldBeThrottled = false; + break; + } + } + + if (allConversationsShouldBeThrottled) { + shouldNotify = false; + } + } + + updateNotification(shouldNotify, conversations); } } synchronized (mMissedCalls) { @@ -733,7 +749,7 @@ public class NotificationService { (!(this.mIsInForeground && this.mOpenConversation == null) || isScreenLocked) && !account.inGracePeriod() && !this.inMiniGracePeriod(account) && - !shouldNotificationSoundBeThrottled(conversation); + !shouldNotificationSoundBeThrottled(conversation.getUuid()); updateNotification(doNotify, Collections.singletonList(conversation.getUuid())); @@ -940,8 +956,8 @@ public class NotificationService { } } - private boolean shouldNotificationSoundBeThrottled(@Nullable Conversational conversation) { - if (conversation == null) { + private boolean shouldNotificationSoundBeThrottled(@Nullable String conversationUuid) { + if (conversationUuid == null) { return false; } @@ -951,7 +967,7 @@ public class NotificationService { return false; } - long lastNotificationTimestamp = ensureLastNotificationTimeByConversation().getLong(conversation.getUuid(), -1L); + long lastNotificationTimestamp = ensureLastNotificationTimeByConversation().getLong(conversationUuid, -1L); if (lastNotificationTimestamp <= 0L) { return false;