1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-02-25 15:32:52 +00:00

Make sure answers are being sent

This commit is contained in:
M66B 2020-02-21 17:38:46 +01:00
parent d7fc63aa77
commit 9df27c1240
2 changed files with 19 additions and 0 deletions

View file

@ -104,6 +104,8 @@ public class EntityRule {
static final String EXTRA_SENDER = "sender"; static final String EXTRA_SENDER = "sender";
static final String EXTRA_SUBJECT = "subject"; static final String EXTRA_SUBJECT = "subject";
private static final long SEND_DELAY = 5000L; // milliseconds
boolean matches(Context context, EntityMessage message, Message imessage) throws MessagingException { boolean matches(Context context, EntityMessage message, Message imessage) throws MessagingException {
try { try {
JSONObject jcondition = new JSONObject(condition); JSONObject jcondition = new JSONObject(condition);
@ -422,6 +424,9 @@ public class EntityRule {
EntityOperation.queue(context, reply, EntityOperation.SEND); EntityOperation.queue(context, reply, EntityOperation.SEND);
// Batch send operations, wait until after commit
ServiceSend.schedule(context, SEND_DELAY);
return true; return true;
} }

View file

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2020 by Marcel Bokhorst (M66B) Copyright 2018-2020 by Marcel Bokhorst (M66B)
*/ */
import android.app.AlarmManager;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -34,6 +35,7 @@ import android.os.PowerManager;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
@ -67,6 +69,7 @@ public class ServiceSend extends ServiceBase {
private PowerManager.WakeLock wlOutbox; private PowerManager.WakeLock wlOutbox;
private ExecutorService executor = Helper.getBackgroundExecutor(1, "send"); private ExecutorService executor = Helper.getBackgroundExecutor(1, "send");
private static final int PI_SEND = 1;
private static final int IDENTITY_ERROR_AFTER = 30; // minutes private static final int IDENTITY_ERROR_AFTER = 30; // minutes
@Override @Override
@ -542,6 +545,17 @@ public class ServiceSend extends ServiceBase {
new Intent(context, ServiceSend.class)); new Intent(context, ServiceSend.class));
} }
static void schedule(Context context, long delay) {
Intent intent = new Intent(context, ServiceSend.class);
PendingIntent pi = PendingIntentCompat.getForegroundService(
context, PI_SEND, intent, PendingIntent.FLAG_UPDATE_CURRENT);
long trigger = System.currentTimeMillis() + delay;
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi);
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, trigger, pi);
}
static void watchdog(Context context) { static void watchdog(Context context) {
boot(context); boot(context);
} }