Added operation cleanup

This commit is contained in:
M66B 2019-09-28 16:16:55 +02:00
parent c09290b569
commit 5e98bbb645
2 changed files with 30 additions and 4 deletions

View File

@ -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();

View File

@ -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;