mirror of https://github.com/M66B/FairEmail.git
Get existing notifications on service start
This commit is contained in:
parent
7ca2b51d95
commit
a4e8f8fb3c
|
@ -1967,8 +1967,11 @@ class Core {
|
|||
groupMessages.put(group, new ArrayList<TupleMessageEx>());
|
||||
}
|
||||
|
||||
if (message.notifying != 0)
|
||||
groupNotifying.get(group).add(message.id * message.notifying);
|
||||
if (message.notifying != 0) {
|
||||
long id = message.id * message.notifying;
|
||||
if (!groupNotifying.get(group).contains(id))
|
||||
groupNotifying.get(group).add(id);
|
||||
}
|
||||
|
||||
if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0)) {
|
||||
// This assumes the messages are properly ordered
|
||||
|
@ -2050,6 +2053,8 @@ class Core {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
groupNotifying.clear();
|
||||
}
|
||||
|
||||
private static List<Notification> getNotificationUnseen(Context context, String group, List<TupleMessageEx> messages) {
|
||||
|
|
|
@ -34,6 +34,7 @@ import android.net.NetworkRequest;
|
|||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.AlarmManagerCompat;
|
||||
|
@ -165,8 +166,30 @@ public class ServiceSynchronize extends ServiceBase {
|
|||
}
|
||||
});
|
||||
|
||||
Map<String, List<Long>> groupNotifying = new HashMap<>();
|
||||
|
||||
// Get existing notifications
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
for (StatusBarNotification sbn : nm.getActiveNotifications()) {
|
||||
String tag = sbn.getTag();
|
||||
if (tag != null && tag.startsWith("unseen.")) {
|
||||
String[] p = tag.split(("\\."));
|
||||
String group = p[1];
|
||||
long id = Long.parseLong(p[2]);
|
||||
|
||||
if (!groupNotifying.containsKey(group))
|
||||
groupNotifying.put(group, new ArrayList<>());
|
||||
|
||||
if (id > 0) {
|
||||
Log.i("Notify restore " + tag);
|
||||
groupNotifying.get(group).add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.message().liveUnseenNotify().observe(cowner, new Observer<List<TupleMessageEx>>() {
|
||||
private Map<String, List<Long>> groupNotifying = new HashMap<>();
|
||||
private ExecutorService executor =
|
||||
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||
|
||||
|
|
Loading…
Reference in New Issue