Added operation cleanup

pull/162/head
M66B 5 years ago
parent c09290b569
commit 5e98bbb645

@ -195,8 +195,9 @@ class Core {
case EntityOperation.MOVE: case EntityOperation.MOVE:
if (EntityOperation.MOVE.equals(next.name)) { if (EntityOperation.MOVE.equals(next.name)) {
JSONArray jnext = new JSONArray(next.args); JSONArray jnext = new JSONArray(next.args);
// Same target, etc // Same target, autoread
if (jargs.equals(jnext)) { if (jargs.getLong(0) == jnext.getLong(0) &&
jargs.getBoolean(1) == jnext.getBoolean(1)) {
EntityMessage m = db.message().getMessage(next.message); EntityMessage m = db.message().getMessage(next.message);
if (m != null) { if (m != null) {
processed.add(next.id); processed.add(next.id);
@ -421,17 +422,22 @@ class Core {
for (EntityOperation s : similar.keySet()) for (EntityOperation s : similar.keySet())
db.operation().deleteOperation(s.id); db.operation().deleteOperation(s.id);
// Cleanup // Cleanup folder
if (EntityOperation.SYNC.equals(op.name)) if (EntityOperation.SYNC.equals(op.name))
db.folder().setFolderSyncState(folder.id, null); db.folder().setFolderSyncState(folder.id, null);
// Cleanup // Cleanup messages
if (message != null && ex instanceof MessageRemovedException) { if (message != null && ex instanceof MessageRemovedException) {
db.message().deleteMessage(message.id); db.message().deleteMessage(message.id);
for (EntityMessage m : similar.values()) for (EntityMessage m : similar.values())
db.message().deleteMessage(m.id); db.message().deleteMessage(m.id);
} }
// Cleanup operations
op.cleanup(context);
for (EntityOperation s : similar.keySet())
s.cleanup(context);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();

@ -92,6 +92,24 @@ public class EntityOperation {
static final String SEND = "send"; static final String SEND = "send";
static final String EXISTS = "exists"; 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) { static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -125,6 +143,7 @@ public class EntityOperation {
// Parameters: // Parameters:
// 0: target folder // 0: target folder
// 1: auto read // 1: auto read
// 2: temporary message
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean autoread = prefs.getBoolean("autoread", false); boolean autoread = prefs.getBoolean("autoread", false);
@ -188,6 +207,7 @@ public class EntityOperation {
message.id = db.message().insertMessage(message); message.id = db.message().insertMessage(message);
File mtarget = message.getFile(context); File mtarget = message.getFile(context);
long tmpid = message.id; long tmpid = message.id;
jargs.put(2, tmpid);
message.id = id; message.id = id;
message.account = source.account; message.account = source.account;

Loading…
Cancel
Save