Moved exists/reply to sync service

This commit is contained in:
M66B
2021-05-10 14:52:39 +02:00
parent df62478c64
commit 902213e935
3 changed files with 40 additions and 49 deletions

View File

@@ -159,6 +159,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
static final int PI_POLL = 5;
static final int PI_WATCHDOG = 6;
static final int PI_UNSNOOZE = 7;
static final int PI_EXISTS = 8;
@Override
public void onCreate() {
@@ -823,6 +824,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
onUnsnooze(intent);
break;
case "exists":
onExists(intent);
break;
case "state":
onState(intent);
break;
@@ -985,6 +990,39 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
});
}
private void onExists(Intent intent) {
String action = intent.getAction();
long id = Long.parseLong(action.split(":")[1]);
executor.submit(new Runnable() {
@Override
public void run() {
try {
DB db = DB.getInstance(ServiceSynchronize.this);
try {
db.beginTransaction();
// Message could have been deleted in the meantime
EntityMessage message = db.message().getMessage(id);
if (message == null)
return;
EntityOperation.queue(ServiceSynchronize.this, message, EntityOperation.EXISTS, true);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
eval(ServiceSynchronize.this, "exists/delayed");
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
private void onState(Intent intent) {
foreground = intent.getBooleanExtra("foreground", false);
}