diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index a9010d3d66..f4a085ff67 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1585,7 +1585,8 @@ class Core { } } - if (!message.seen.equals(seen) || !message.seen.equals(message.ui_seen)) { + if ((!message.seen.equals(seen) || !message.ui_seen.equals(seen)) && + db.operation().getOperationCount(folder.id, message.id, EntityOperation.SEEN) == 0) { update = true; message.seen = seen; message.ui_seen = seen; @@ -1594,7 +1595,8 @@ class Core { Log.i(folder.name + " updated id=" + message.id + " uid=" + message.uid + " seen=" + seen); } - if (!message.answered.equals(answered) || !message.answered.equals(message.ui_answered)) { + if ((!message.answered.equals(answered) || !message.ui_answered.equals(message.answered)) && + db.operation().getOperationCount(folder.id, message.id, EntityOperation.ANSWERED) == 0) { if (!answered && message.ui_answered && ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { // This can happen when the answered operation was skipped because the message was moving answered = true; @@ -1606,7 +1608,8 @@ class Core { Log.i(folder.name + " updated id=" + message.id + " uid=" + message.uid + " answered=" + answered); } - if (!message.flagged.equals(flagged) || !message.flagged.equals(message.ui_flagged)) { + if ((!message.flagged.equals(flagged) || !message.ui_flagged.equals(flagged)) && + db.operation().getOperationCount(folder.id, message.id, EntityOperation.FLAG) == 0) { update = true; message.flagged = flagged; message.ui_flagged = flagged; diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index 0edaa5b111..0ba9454272 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -97,14 +97,20 @@ public interface DaoOperation { @Query("SELECT COUNT(id) FROM operation" + " WHERE folder = :folder" + - " AND (:name IS NULL OR operation.name = :name)") + " AND (:name IS NULL OR name = :name)") int getOperationCount(long folder, String name); @Query("SELECT COUNT(id) FROM operation" + " WHERE folder = :folder" + - " AND message = :message") + " AND message = :message") int getOperationCount(long folder, long message); + @Query("SELECT COUNT(id) FROM operation" + + " WHERE folder = :folder" + + " AND message = :message" + + " AND name = :name") + int getOperationCount(long folder, long message, String name); + @Query("UPDATE operation SET state = :state WHERE id = :id") int setOperationState(long id, String state);