From 192a5225517746a3e9d54dfc28ddcced77591a7f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 23 Jun 2019 13:23:29 +0200 Subject: [PATCH] Minimum hide of 1 minute --- .../eu/faircode/email/AdapterMessage.java | 2 +- app/src/main/java/eu/faircode/email/Core.java | 9 +++--- .../java/eu/faircode/email/DaoAccount.java | 2 +- .../java/eu/faircode/email/DaoFolder.java | 10 +++---- .../java/eu/faircode/email/DaoMessage.java | 28 +++++++++---------- .../java/eu/faircode/email/EntityMessage.java | 2 +- .../eu/faircode/email/EntityOperation.java | 4 +-- .../eu/faircode/email/FragmentCompose.java | 12 ++++---- .../eu/faircode/email/FragmentMessages.java | 6 ++-- .../eu/faircode/email/FragmentOperations.java | 3 +- .../java/eu/faircode/email/ServiceSend.java | 2 +- .../eu/faircode/email/ServiceSynchronize.java | 2 +- 12 files changed, 42 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index c6477af3e5..22bb17fa9e 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -683,7 +683,7 @@ public class AdapterMessage extends RecyclerView.Adapter '" + EntityFolder.DRAFTS + "'" + " AND folder.type <> '" + EntityFolder.OUTBOX + "'" + " AND NOT ui_seen" + - " AND NOT ui_hide) AS unseen" + + " AND ui_hide = 0) AS unseen" + ", (SELECT COUNT(identity.id)" + " FROM identity" + " WHERE identity.account = account.id" + diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index a4410cc400..e0e5c4573d 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -40,7 +40,7 @@ public interface DaoFolder { ", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" + " FROM folder" + " LEFT JOIN account ON account.id = folder.account" + - " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + + " LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" + " WHERE folder.account = :account AND account.synchronize" + " GROUP BY folder.id") List getFoldersEx(long account); @@ -73,7 +73,7 @@ public interface DaoFolder { ", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" + " FROM folder" + " LEFT JOIN account ON account.id = folder.account" + - " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + + " LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" + " WHERE CASE WHEN :account IS NULL" + " THEN folder.unified AND account.synchronize" + " ELSE folder.account = :account AND account.synchronize" + @@ -90,7 +90,7 @@ public interface DaoFolder { ", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" + " FROM folder" + " JOIN account ON account.id = folder.account" + - " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + + " LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" + " WHERE account.`synchronize`" + " AND folder.unified" + " GROUP BY folder.id") @@ -103,7 +103,7 @@ public interface DaoFolder { ", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" + " FROM folder" + " LEFT JOIN account ON account.id = folder.account" + - " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + + " LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" + " WHERE account.id IS NULL" + " OR (account.`synchronize` AND folder.navigation)" + " GROUP BY folder.id") @@ -130,7 +130,7 @@ public interface DaoFolder { ", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" + " FROM folder" + " LEFT JOIN account ON account.id = folder.account" + - " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + + " LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" + " WHERE folder.id = :id" + " GROUP BY folder.id") LiveData liveFolderEx(long id); diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 5159748154..88bd9695bb 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -58,7 +58,7 @@ public interface DaoMessage { " LEFT JOIN identity ON identity.id = message.identity" + " JOIN folder ON folder.id = message.folder" + " WHERE account.`synchronize`" + - " AND (NOT message.ui_hide OR :debug)" + + " AND (message.ui_hide = 0 OR :debug)" + " AND (NOT :found OR ui_found = :found)" + " GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " HAVING (:found OR SUM(folder.unified) > 0)" + @@ -105,7 +105,7 @@ public interface DaoMessage { " JOIN folder ON folder.id = message.folder" + " JOIN folder AS f ON f.id = :folder" + " WHERE (message.account = f.account OR " + is_outbox + ")" + - " AND (NOT message.ui_hide OR :debug)" + + " AND (message.ui_hide = 0 OR :debug)" + " AND (NOT :found OR ui_found = :found)" + " GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " HAVING SUM(CASE WHEN folder.id = :folder THEN 1 ELSE 0 END) > 0" + @@ -148,7 +148,7 @@ public interface DaoMessage { " WHERE message.account = :account" + " AND message.thread = :thread" + " AND (:id IS NULL OR message.id = :id)" + - " AND (NOT message.ui_hide OR :debug)" + + " AND (message.ui_hide = 0 OR :debug)" + " ORDER BY message.received DESC" + ", CASE WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN 1 ELSE 0 END") DataSource.Factory pagedThread(long account, String thread, Long id, boolean debug); @@ -161,20 +161,20 @@ public interface DaoMessage { " WHERE message.account = :account" + " AND message.thread = :thread" + " AND (:id IS NULL OR message.id = :id)" + - " AND NOT message.ui_hide" + + " AND message.ui_hide = 0" + " GROUP BY account.id") LiveData liveThreadStats(long account, String thread, Long id); @Query("SELECT message.id FROM folder" + " JOIN message ON message.folder = folder.id" + " WHERE CASE WHEN :folder IS NULL THEN folder.unified ELSE folder.id = :folder END" + - " AND ui_hide") + " AND ui_hide <> 0") LiveData> liveHidden(Long folder); @Query("SELECT id FROM message" + " WHERE account = :account" + " AND thread = :thread" + - " AND ui_hide") + " AND ui_hide <> 0") LiveData> liveHidden(long account, String thread); @Query("SELECT COUNT(id)" + @@ -196,14 +196,14 @@ public interface DaoMessage { @Query("SELECT id" + " FROM message" + " WHERE folder = :folder" + - " AND NOT ui_hide" + + " AND ui_hide = 0" + " ORDER BY message.received DESC") List getMessageByFolder(long folder); @Query("SELECT id" + " FROM message" + " WHERE (:folder IS NULL OR folder = :folder)" + - " AND NOT ui_hide" + + " AND ui_hide = 0" + " ORDER BY message.received DESC") List getMessageIdsByFolder(Long folder); @@ -211,7 +211,7 @@ public interface DaoMessage { " FROM folder" + " JOIN message ON message.folder = folder.id" + " WHERE CASE WHEN :folder IS NULL THEN folder.unified ELSE folder.id = :folder END" + - " AND NOT ui_hide" + + " AND ui_hide = 0" + " AND (ui_snoozed IS NULL OR :snoozed)" + " ORDER BY message.received DESC") List getMessageAll(Long folder, boolean snoozed); @@ -223,7 +223,7 @@ public interface DaoMessage { " AND (:id IS NULL OR message.id = :id)" + " AND (:folder IS NULL OR message.folder = :folder)" + " AND NOT uid IS NULL" + - " AND NOT ui_hide") + " AND ui_hide = 0") List getMessageByThread(long account, String thread, Long id, Long folder); @Query("SELECT * FROM message" + @@ -273,8 +273,8 @@ public interface DaoMessage { " AND folder.notify" + " AND (account.created IS NULL OR message.received > account.created)" + " AND NOT message.ui_seen" + - " AND NOT message.ui_hide" + " AND NOT message.ui_ignored" + + " AND message.ui_hide = 0" + " ORDER BY message.received") LiveData> liveUnseenNotify(); @@ -285,8 +285,8 @@ public interface DaoMessage { " AND folder.unified" + " AND (account.created IS NULL OR message.received > account.created)" + " AND NOT message.ui_seen" + - " AND NOT message.ui_hide" + " AND NOT message.ui_ignored" + + " AND message.ui_hide = 0" + " ORDER BY message.received") int getUnseenUnified(); @@ -351,10 +351,10 @@ public interface DaoMessage { int setMessageUiAnswered(long id, boolean ui_answered); @Query("UPDATE message SET ui_hide = :ui_hide WHERE id = :id") - int setMessageUiHide(long id, boolean ui_hide); + int setMessageUiHide(long id, long ui_hide); @Query("UPDATE message SET ui_hide = :ui_hide WHERE folder = :folder AND uid = :uid") - int setMessageUiHide(long folder, long uid, boolean ui_hide); + int setMessageUiHide(long folder, long uid, long ui_hide); @Query("UPDATE message SET ui_ignored = :ui_ignored WHERE id = :id") int setMessageUiIgnored(long id, boolean ui_ignored); diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 44ca70e4b7..2e3e909dae 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -135,7 +135,7 @@ public class EntityMessage implements Serializable { @NonNull public Boolean ui_flagged = false; @NonNull - public Boolean ui_hide = false; + public Long ui_hide = 0L; @NonNull public Boolean ui_found = false; @NonNull diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 8250ce957d..c5283a5797 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -132,7 +132,7 @@ public class EntityOperation { return; if (!EntityFolder.ARCHIVE.equals(source.type) || EntityFolder.TRASH.equals(target.type)) - db.message().setMessageUiHide(message.id, true); + db.message().setMessageUiHide(message.id, new Date().getTime()); Calendar cal_keep = Calendar.getInstance(); cal_keep.add(Calendar.DAY_OF_MONTH, -target.keep_days); @@ -204,7 +204,7 @@ public class EntityOperation { name = RAW; } else if (DELETE.equals(name)) - db.message().setMessageUiHide(message.id, true); + db.message().setMessageUiHide(message.id, new Date().getTime()); } catch (JSONException ex) { Log.e(ex); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 513dca3d82..ede19af182 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1926,7 +1926,7 @@ public class FragmentCompose extends FragmentBase { db.beginTransaction(); draft = db.message().getMessage(id); - if (draft == null || draft.ui_hide) { + if (draft == null || draft.ui_hide != 0) { // New draft if ("edit".equals(action)) throw new MessageRemovedException("Draft for edit was deleted hide=" + (draft != null)); @@ -2307,7 +2307,7 @@ public class FragmentCompose extends FragmentBase { @Override public void onChanged(EntityMessage draft) { // Draft was deleted - if (draft == null || draft.ui_hide) + if (draft == null || draft.ui_hide != 0) finish(); else { tvNoInternet.setTag(draft.content); @@ -2399,7 +2399,7 @@ public class FragmentCompose extends FragmentBase { EntityIdentity identity = db.identity().getIdentity(iid); // Draft deleted by server - if (draft == null || draft.ui_hide) + if (draft == null || draft.ui_hide != 0) throw new MessageRemovedException("Draft for action was deleted hide=" + (draft != null)); Log.i("Load action id=" + draft.id + " action=" + getActionName(action)); @@ -2420,7 +2420,7 @@ public class FragmentCompose extends FragmentBase { draft.uid = uid; draft.msgid = msgid; draft.content = false; - draft.ui_hide = true; + draft.ui_hide = new Date().getTime(); draft.id = db.message().insertMessage(draft); EntityOperation.queue(context, draft, EntityOperation.DELETE); // by msgid @@ -2431,7 +2431,7 @@ public class FragmentCompose extends FragmentBase { draft.uid = null; draft.msgid = EntityMessage.generateMessageId(); draft.content = true; - draft.ui_hide = false; + draft.ui_hide = 0L; db.message().updateMessage(draft); EntityOperation.queue(context, draft, EntityOperation.ADD); } @@ -2635,7 +2635,7 @@ public class FragmentCompose extends FragmentBase { draft.id = null; draft.folder = db.folder().getOutbox().id; draft.uid = null; - draft.ui_hide = false; + draft.ui_hide = 0L; draft.id = db.message().insertMessage(draft); Helper.writeText(draft.getFile(context), body); if (refDraftFile.exists()) { diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 603b1c700b..8817e40481 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1235,7 +1235,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. message.account, message.thread, threading && thread ? null : id, message.folder); for (EntityMessage threaded : messages) { result.add(new MessageTarget(threaded, account, target)); - db.message().setMessageUiHide(threaded.id, true); + db.message().setMessageUiHide(threaded.id, new Date().getTime()); // Prevent new message notification on undo db.message().setMessageUiIgnored(threaded.id, true); } @@ -3254,7 +3254,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. ArrayList result = args.getParcelableArrayList("result"); for (MessageTarget target : result) { Log.i("Move undo id=" + target.id); - db.message().setMessageUiHide(target.id, false); + db.message().setMessageUiHide(target.id, 0L); } return null; } @@ -3292,7 +3292,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. for (MessageTarget target : result) { EntityMessage message = db.message().getMessage(target.id); - if (message != null && message.ui_hide) { + if (message != null && message.ui_hide != 0) { Log.i("Move id=" + id + " target=" + target.folder.name); EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); } diff --git a/app/src/main/java/eu/faircode/email/FragmentOperations.java b/app/src/main/java/eu/faircode/email/FragmentOperations.java index 385922cc2b..ec7a46f89f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOperations.java +++ b/app/src/main/java/eu/faircode/email/FragmentOperations.java @@ -41,6 +41,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class FragmentOperations extends FragmentBase { @@ -149,7 +150,7 @@ public class FragmentOperations extends FragmentBase { for (EntityOperation op : ops) { Log.w("Deleting operation=" + op.id + " error=" + op.error); if (op.message != null) - db.message().setMessageUiHide(op.message, false); + db.message().setMessageUiHide(op.message, 0L); db.operation().deleteOperation(op.id); } return null; diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 55e35dfdcd..c2e825cc84 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -356,7 +356,7 @@ public class ServiceSend extends LifecycleService { EntityOperation.queue(this, message, EntityOperation.ADD); } else { if (!BuildConfig.DEBUG && !debug) - db.message().setMessageUiHide(message.id, true); + db.message().setMessageUiHide(message.id, new Date().getTime()); } if (message.inreplyto != null) { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 9d4090f5f6..f40f581818 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -847,7 +847,7 @@ public class ServiceSynchronize extends LifecycleService { long uid = ifolder.getUID(imessage); DB db = DB.getInstance(ServiceSynchronize.this); - int count = db.message().setMessageUiHide(folder.id, uid, true); + int count = db.message().setMessageUiHide(folder.id, uid, new Date().getTime()); // Will be deleted on next sync Log.i(folder.name + " deleted uid=" + uid + " count=" + count);