mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-27 02:07:12 +00:00
Synchronize message updates and message operations
This commit is contained in:
parent
92e9120e06
commit
a46874130f
1 changed files with 121 additions and 113 deletions
|
@ -97,13 +97,13 @@ import androidx.lifecycle.Observer;
|
|||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
public class ServiceSynchronize extends LifecycleService {
|
||||
private final Object lock = new Object();
|
||||
private ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private static final int NOTIFICATION_SYNCHRONIZE = 1;
|
||||
private static final int NOTIFICATION_UNSEEN = 2;
|
||||
|
||||
private static final long NOOP_INTERVAL = 9 * 60 * 1000L; // ms
|
||||
private static final int FETCH_BATCH_SIZE = 10;
|
||||
private static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes
|
||||
|
||||
static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS";
|
||||
|
@ -607,6 +607,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
ifolder.addMessageCountListener(new MessageCountAdapter() {
|
||||
@Override
|
||||
public void messagesAdded(MessageCountEvent e) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " messages added");
|
||||
for (Message imessage : e.getMessages())
|
||||
|
@ -625,9 +626,11 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messagesRemoved(MessageCountEvent e) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " messages removed");
|
||||
for (Message imessage : e.getMessages())
|
||||
|
@ -653,6 +656,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Fetch e-mail
|
||||
|
@ -664,6 +668,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
ifolder.addMessageChangedListener(new MessageChangedListener() {
|
||||
@Override
|
||||
public void messageChanged(MessageChangedEvent e) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " message changed");
|
||||
synchronizeMessage(folder, ifolder, (IMAPMessage) e.getMessage());
|
||||
|
@ -684,6 +689,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Keep alive
|
||||
|
@ -734,6 +740,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
private void processOperations(EntityFolder folder, Session isession, IMAPStore istore, IMAPFolder ifolder) throws MessagingException, JSONException, IOException {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Log.i(Helper.TAG, folder.name + " start process");
|
||||
|
||||
|
@ -812,6 +819,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
Log.i(Helper.TAG, folder.name + " end process");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doSeen(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs) throws MessagingException, JSONException {
|
||||
// Mark message (un)seen
|
||||
|
|
Loading…
Reference in a new issue