Keep volatile record of notifications

pull/160/head
M66B 6 years ago
parent bebc65e8de
commit 2274409b62

@ -1919,7 +1919,7 @@ class Core {
} }
} }
static void notifyMessages(Context context, List<TupleMessageEx> messages) { static void notifyMessages(Context context, List<TupleMessageEx> messages, Map<String, List<Long>> groupNotifying) {
if (messages == null) if (messages == null)
messages = new ArrayList<>(); messages = new ArrayList<>();
Log.i("Notify messages=" + messages.size()); Log.i("Notify messages=" + messages.size());
@ -1934,7 +1934,6 @@ class Core {
// Current // Current
int unseen = 0; int unseen = 0;
final Map<String, List<Long>> groupNotifying = new HashMap<>();
Map<String, List<TupleMessageEx>> groupMessages = new HashMap<>(); Map<String, List<TupleMessageEx>> groupMessages = new HashMap<>();
for (TupleMessageEx message : messages) { for (TupleMessageEx message : messages) {
if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0)) if (!(message.ui_seen || message.ui_ignored || message.ui_hide != 0))
@ -1981,7 +1980,7 @@ class Core {
List<Notification> notifications = getNotificationUnseen(context, group, groupMessages.get(group)); List<Notification> notifications = getNotificationUnseen(context, group, groupMessages.get(group));
final List<Long> add = new ArrayList<>(); final List<Long> add = new ArrayList<>();
final List<Long> remove = groupNotifying.get(group); final List<Long> remove = new ArrayList<>(groupNotifying.get(group));
for (Notification notification : notifications) { for (Notification notification : notifications) {
Long id = notification.extras.getLong("id", 0); Long id = notification.extras.getLong("id", 0);
@ -2023,10 +2022,14 @@ class Core {
if (remove.size() + add.size() > 0) { if (remove.size() + add.size() > 0) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
for (long id : remove) for (long id : remove) {
groupNotifying.get(group).remove(id);
db.message().setMessageNotifying(Math.abs(id), 0); db.message().setMessageNotifying(Math.abs(id), 0);
for (long id : add) }
for (long id : add) {
groupNotifying.get(group).add(id);
db.message().setMessageNotifying(Math.abs(id), (int) Math.signum(id)); db.message().setMessageNotifying(Math.abs(id), (int) Math.signum(id));
}
} }
} }
} }

@ -168,6 +168,7 @@ public class ServiceSynchronize extends ServiceBase {
}); });
db.message().liveUnseenNotify().observe(cowner, new Observer<List<TupleMessageEx>>() { db.message().liveUnseenNotify().observe(cowner, new Observer<List<TupleMessageEx>>() {
private Map<String, List<Long>> groupNotifying = new HashMap<>();
private ExecutorService executor = private ExecutorService executor =
Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
@ -177,7 +178,7 @@ public class ServiceSynchronize extends ServiceBase {
@Override @Override
public void run() { public void run() {
try { try {
Core.notifyMessages(ServiceSynchronize.this, messages); Core.notifyMessages(ServiceSynchronize.this, messages, groupNotifying);
} catch (SecurityException ex) { } catch (SecurityException ex) {
Log.w(ex); Log.w(ex);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);

Loading…
Cancel
Save