Fixed notification race condition

pull/162/head
M66B 6 years ago
parent a233a1c9a4
commit ebf783e159

@ -2083,9 +2083,12 @@ class Core {
if (message.notifying != 0) { if (message.notifying != 0) {
long id = message.id * message.notifying; long id = message.id * message.notifying;
if (!groupNotifying.get(group).contains(id)) if (!groupNotifying.get(group).contains(id) &&
!groupNotifying.get(group).contains(-id)) {
Log.i("Notify database=" + id);
groupNotifying.get(group).add(id); groupNotifying.get(group).add(id);
} }
}
if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0)) { if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0)) {
// This assumes the messages are properly ordered // This assumes the messages are properly ordered
@ -2143,7 +2146,7 @@ class Core {
for (Long id : remove) { for (Long id : remove) {
String tag = "unseen." + group + "." + Math.abs(id); String tag = "unseen." + group + "." + Math.abs(id);
Log.i("Notify cancel tag=" + tag); Log.i("Notify cancel tag=" + tag + " id=" + id);
nm.cancel(tag, 1); nm.cancel(tag, 1);
groupNotifying.get(group).remove(id); groupNotifying.get(group).remove(id);
@ -2154,7 +2157,7 @@ class Core {
long id = notification.extras.getLong("id", 0); 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) || add.contains(id)) {
String tag = "unseen." + group + "." + Math.abs(id); String tag = "unseen." + group + "." + Math.abs(id);
Log.i("Notifying tag=" + tag + Log.i("Notifying tag=" + tag + " id=" + id +
(Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId())); (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "" : " channel=" + notification.getChannelId()));
nm.notify(tag, 1, notification); nm.notify(tag, 1, notification);

@ -169,13 +169,13 @@ public class ServiceSynchronize extends ServiceBase {
if (tag != null && tag.startsWith("unseen.")) { if (tag != null && tag.startsWith("unseen.")) {
String[] p = tag.split(("\\.")); String[] p = tag.split(("\\."));
long group = Long.parseLong(p[1]); long group = Long.parseLong(p[1]);
long id = Long.parseLong(p[2]); long id = sbn.getNotification().extras.getLong("id", 0);
if (!groupNotifying.containsKey(group)) if (!groupNotifying.containsKey(group))
groupNotifying.put(group, new ArrayList<>()); groupNotifying.put(group, new ArrayList<>());
if (id > 0) { if (id > 0) {
Log.i("Notify restore " + tag); Log.i("Notify restore " + tag + " id=" + id);
groupNotifying.get(group).add(id); groupNotifying.get(group).add(id);
} }
} }

Loading…
Cancel
Save