From c81755169be88f347be32e317b3281ac658e70f8 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 13 May 2019 13:09:06 +0200 Subject: [PATCH] Simplification --- .../java/eu/faircode/email/DaoMessage.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 211f98378c..d391ac9bcb 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -36,15 +36,10 @@ public interface DaoMessage { // all bare columns in the result set take values from the input row which also contains the minimum or maximum." // https://www.sqlite.org/lang_select.html - String unseen_unified = "SUM(CASE WHEN message.ui_seen" + - " OR folder.type = '" + EntityFolder.ARCHIVE + "'" + - " OR folder.type = '" + EntityFolder.OUTBOX + "'" + - " OR folder.type = '" + EntityFolder.DRAFTS + "' THEN 0 ELSE 1 END)"; + String folder_in = "folder.type IN ('" + EntityFolder.ARCHIVE + "', '" + EntityFolder.OUTBOX + "', '" + EntityFolder.DRAFTS + "')"; - String unflagged_unified = "SUM(CASE WHEN message.ui_flagged" + - " AND NOT folder.type = '" + EntityFolder.ARCHIVE + "'" + - " AND NOT folder.type = '" + EntityFolder.OUTBOX + "'" + - " AND NOT folder.type = '" + EntityFolder.DRAFTS + "' THEN 0 ELSE 1 END)"; + String unseen_unified = "SUM(CASE WHEN message.ui_seen OR " + folder_in + " THEN 0 ELSE 1 END)"; + String unflagged_unified = "SUM(CASE WHEN message.ui_flagged AND NOT " + folder_in + " THEN 0 ELSE 1 END)"; @Query("SELECT message.*" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + @@ -88,14 +83,8 @@ public interface DaoMessage { boolean found, boolean debug); - String unseen_folder = "SUM(CASE WHEN message.ui_seen" + - " OR (folder.id <> :folder AND folder.type = '" + EntityFolder.ARCHIVE + "')" + - " OR (folder.id <> :folder AND folder.type = '" + EntityFolder.OUTBOX + "')" + - " OR (folder.id <> :folder AND folder.type = '" + EntityFolder.DRAFTS + "') THEN 0 ELSE 1 END)"; - String unflagged_folder = "SUM(CASE WHEN message.ui_flagged" + - " AND NOT (folder.id <> :folder AND folder.type = '" + EntityFolder.ARCHIVE + "')" + - " AND NOT (folder.id <> :folder AND folder.type = '" + EntityFolder.OUTBOX + "')" + - " AND NOT (folder.id <> :folder AND folder.type = '" + EntityFolder.DRAFTS + "') THEN 0 ELSE 1 END)"; + String unseen_folder = "SUM(CASE WHEN message.ui_seen OR (folder.id <> :folder AND " + folder_in + ") THEN 0 ELSE 1 END)"; + String unflagged_folder = "SUM(CASE WHEN message.ui_flagged AND NOT (folder.id <> :folder AND " + folder_in + ") THEN 0 ELSE 1 END)"; @Query("SELECT message.*" + ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" +