handle notifications throttling on backlog finish event

This commit is contained in:
kosyak 2024-05-21 17:23:54 +02:00
parent 501de4f997
commit 888ed9643f

View file

@ -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;