diff --git a/app/src/main/java/eu/faircode/email/AdapterOperation.java b/app/src/main/java/eu/faircode/email/AdapterOperation.java index 36156f9592..887b91f2b6 100644 --- a/app/src/main/java/eu/faircode/email/AdapterOperation.java +++ b/app/src/main/java/eu/faircode/email/AdapterOperation.java @@ -60,7 +60,7 @@ public class AdapterOperation extends RecyclerView.Adapter getOperationsByFolder(long folder, boolean outbox); - - @Query("SELECT operation.*, account.name AS accountName, folder.name AS folderName" + - " FROM operation" + - " JOIN folder ON folder.id = operation.folder" + - " LEFT JOIN account ON account.id = folder.account" + - " ORDER BY operation.id") LiveData> liveOperations(); - @Query("SELECT * FROM operation WHERE folder = :folder ORDER BY id") + @Query("SELECT operation.* FROM operation" + + " JOIN folder ON folder.id = operation.folder" + + " LEFT JOIN message ON message.id = operation.message" + + " LEFT JOIN account ON account.id = message.account" + + " LEFT JOIN identity ON identity.id = message.identity" + + " WHERE operation.folder = :folder" + + " AND (account.synchronize IS NULL OR account.synchronize)" + + " AND (NOT folder.account IS NULL OR identity.synchronize)" + + " ORDER BY" + + " CASE WHEN operation.name = '" + EntityOperation.SYNC + "' THEN" + + " CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox + " ELSE 0" + + " END" + + ", id") LiveData> liveOperations(long folder); @Query("SELECT * FROM operation ORDER BY id") diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 0bc7f8ab34..3bb098b58b 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1189,7 +1189,7 @@ public class ServiceSynchronize extends LifecycleService { PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":folder." + folder.id); @Override - public void onChanged(List operations) { + public void onChanged(final List operations) { boolean process = false; List current = new ArrayList<>(); for (EntityOperation op : operations) { @@ -1229,7 +1229,7 @@ public class ServiceSynchronize extends LifecycleService { db.folder().setFolderError(folder.id, null); } - processOperations(account, folder, isession, istore, ifolder, state); + processOperations(account, folder, operations, isession, istore, ifolder, state); } catch (Throwable ex) { Log.e(folder.name, ex); @@ -1432,13 +1432,14 @@ public class ServiceSynchronize extends LifecycleService { } } - private void processOperations(EntityAccount account, EntityFolder folder, Session isession, IMAPStore istore, IMAPFolder ifolder, ServiceState state) throws MessagingException, JSONException, IOException { + private void processOperations( + EntityAccount account, EntityFolder folder, List ops, Session isession, + IMAPStore istore, IMAPFolder ifolder, ServiceState state) + throws MessagingException, JSONException, IOException { try { Log.i(folder.name + " start process"); DB db = DB.getInstance(this); - List ops = db.operation().getOperationsByFolder( - folder.id, EntityFolder.OUTBOX.equals(folder.type)); Log.i(folder.name + " pending operations=" + ops.size()); for (int i = 0; i < ops.size() && state.running(); i++) { EntityOperation op = ops.get(i); @@ -1866,11 +1867,8 @@ public class ServiceSynchronize extends LifecycleService { private void doSend(EntityMessage message, DB db) throws MessagingException, IOException { // Send message EntityIdentity ident = db.identity().getIdentity(message.identity); - if (!ident.synchronize) { - // Message will remain in outbox - return; - } + // Mark attempt if (message.last_attempt == null) { message.last_attempt = new Date().getTime(); db.message().setMessageLastAttempt(message.id, message.last_attempt); @@ -3005,7 +3003,7 @@ public class ServiceSynchronize extends LifecycleService { PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":outbox"); @Override - public void onChanged(List operations) { + public void onChanged(final List operations) { boolean process = false; List current = new ArrayList<>(); for (EntityOperation op : operations) { @@ -3025,7 +3023,7 @@ public class ServiceSynchronize extends LifecycleService { Log.i(outbox.name + " process"); db.folder().setFolderSyncState(outbox.id, "syncing"); - processOperations(null, outbox, null, null, null, state); + processOperations(null, outbox, operations, null, null, null, state); db.folder().setFolderError(outbox.id, null); } catch (Throwable ex) { Log.e(outbox.name, ex); diff --git a/app/src/main/java/eu/faircode/email/TupleOperationEx.java b/app/src/main/java/eu/faircode/email/TupleOperationEx.java index d2ad0ec903..8999f4dc7b 100644 --- a/app/src/main/java/eu/faircode/email/TupleOperationEx.java +++ b/app/src/main/java/eu/faircode/email/TupleOperationEx.java @@ -22,6 +22,7 @@ package eu.faircode.email; public class TupleOperationEx extends EntityOperation { public String accountName; public String folderName; + public boolean synchronize; @Override public boolean equals(Object obj) { @@ -29,7 +30,8 @@ public class TupleOperationEx extends EntityOperation { TupleOperationEx other = (TupleOperationEx) obj; return (super.equals(obj) && (this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)) && - (this.folderName == null ? other.folderName == null : this.folderName.equals(other.folderName))); + (this.folderName == null ? other.folderName == null : this.folderName.equals(other.folderName)) && + this.synchronize == other.synchronize); } else return false; } diff --git a/app/src/main/res/layout/item_operation.xml b/app/src/main/res/layout/item_operation.xml index db11621b30..dd2266553e 100644 --- a/app/src/main/res/layout/item_operation.xml +++ b/app/src/main/res/layout/item_operation.xml @@ -1,74 +1,80 @@ - + android:layout_height="wrap_content"> - + android:layout_marginTop="3dp" + android:layout_marginBottom="3dp"> - + - + - + - + - - \ No newline at end of file + + + + + \ No newline at end of file