From c2f2afe0f5d1845bab0cf29dda92b3a4672f6a8a Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 5 Aug 2019 16:48:01 +0200 Subject: [PATCH] Optimize new message notifications (2) --- app/src/main/java/eu/faircode/email/Core.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 455cf1f7b6..2096d5aaf8 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1986,8 +1986,9 @@ class Core { // Difference for (String group : groupMessages.keySet()) { // Difference - final List add = new ArrayList<>(); - final List remove = new ArrayList<>(groupNotifying.get(group)); + List add = new ArrayList<>(); + List remove = new ArrayList<>(groupNotifying.get(group)); + List notify = new ArrayList<>(); for (TupleMessageEx message : groupMessages.get(group)) { long id = (message.content ? message.id : -message.id); if (remove.contains(id)) { @@ -1996,6 +1997,7 @@ class Core { } else { remove.remove(-id); add.add(id); + notify.add(message); Log.i("Notify adding=" + id); } } @@ -2006,7 +2008,7 @@ class Core { } // Build notifications - List notifications = getNotificationUnseen(context, group, groupMessages.get(group)); + List notifications = getNotificationUnseen(context, group, notify); Log.i("Notify group=" + group + " count=" + notifications.size() + " added=" + add.size() + " removed=" + remove.size()); @@ -2025,7 +2027,7 @@ class Core { for (Notification notification : notifications) { long id = notification.extras.getLong("id", 0); - if ((id == 0 && add.size() + remove.size() > 0) || add.contains(id)) { + if (id != 0 || add.size() + remove.size() > 0) { String tag = "unseen." + group + "." + Math.abs(id); Log.i("Notifying tag=" + tag + (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId()));