From 5e98bbb645e4b3e2089fb577c3464be0dccb736e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 28 Sep 2019 16:16:55 +0200 Subject: [PATCH] Added operation cleanup --- app/src/main/java/eu/faircode/email/Core.java | 14 +++++++++---- .../eu/faircode/email/EntityOperation.java | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 001d415e01..099aad78d7 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -195,8 +195,9 @@ class Core { case EntityOperation.MOVE: if (EntityOperation.MOVE.equals(next.name)) { JSONArray jnext = new JSONArray(next.args); - // Same target, etc - if (jargs.equals(jnext)) { + // Same target, autoread + if (jargs.getLong(0) == jnext.getLong(0) && + jargs.getBoolean(1) == jnext.getBoolean(1)) { EntityMessage m = db.message().getMessage(next.message); if (m != null) { processed.add(next.id); @@ -421,17 +422,22 @@ class Core { for (EntityOperation s : similar.keySet()) db.operation().deleteOperation(s.id); - // Cleanup + // Cleanup folder if (EntityOperation.SYNC.equals(op.name)) db.folder().setFolderSyncState(folder.id, null); - // Cleanup + // Cleanup messages if (message != null && ex instanceof MessageRemovedException) { db.message().deleteMessage(message.id); for (EntityMessage m : similar.values()) db.message().deleteMessage(m.id); } + // Cleanup operations + op.cleanup(context); + for (EntityOperation s : similar.keySet()) + s.cleanup(context); + db.setTransactionSuccessful(); } finally { db.endTransaction(); diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 1f93e3f083..dce5ef0e3f 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -92,6 +92,24 @@ public class EntityOperation { static final String SEND = "send"; static final String EXISTS = "exists"; + void cleanup(Context context) { + if (EntityOperation.MOVE.equals(name) || + EntityOperation.ADD.equals(name) || + EntityOperation.RAW.equals(name)) + try { + JSONArray jargs = new JSONArray(args); + long tmpid = jargs.optLong(2, -1); + if (tmpid < 0) + return; + + DB db = DB.getInstance(context); + db.message().deleteMessage(tmpid); + db.message().setMessageUiHide(message, false); + } catch (JSONException ex) { + Log.e(ex); + } + } + static void queue(Context context, EntityMessage message, String name, Object... values) { DB db = DB.getInstance(context); @@ -125,6 +143,7 @@ public class EntityOperation { // Parameters: // 0: target folder // 1: auto read + // 2: temporary message SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoread = prefs.getBoolean("autoread", false); @@ -188,6 +207,7 @@ public class EntityOperation { message.id = db.message().insertMessage(message); File mtarget = message.getFile(context); long tmpid = message.id; + jargs.put(2, tmpid); message.id = id; message.account = source.account;