From 8d862cc0c8f4e0567abf3fc2fb41080c73457692 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 30 Dec 2021 12:19:26 +0100 Subject: [PATCH] Prefer ingoing found messages --- app/src/main/java/eu/faircode/email/DaoMessage.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index a51075b240..9f60577b59 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -42,6 +42,7 @@ public interface DaoMessage { String is_drafts = "folder.type = '" + EntityFolder.DRAFTS + "'"; String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'"; String is_sent = "folder.type = '" + EntityFolder.SENT + "'"; + String is_outgoing = is_drafts + " OR " + is_outbox + " OR " + is_sent; @Transaction @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) @@ -71,9 +72,9 @@ public interface DaoMessage { ", message.priority AS ui_priority" + ", message.importance AS ui_importance" + ", MAX(CASE WHEN" + - " ((:found AND folder.type <> '" + EntityFolder.ARCHIVE + "' AND folder.type <> '" + EntityFolder.DRAFTS + "')" + + " (:found AND folder.type <> '" + EntityFolder.ARCHIVE + "' AND NOT (" + is_outgoing + "))" + " OR (NOT :found AND :type IS NULL AND folder.unified)" + - " OR (NOT :found AND folder.type = :type))" + + " OR (NOT :found AND folder.type = :type)" + " THEN message.received ELSE 0 END) AS dummy" + " FROM (SELECT * FROM message" + " WHERE message.thread IN" + @@ -150,7 +151,10 @@ public interface DaoMessage { ", SUM(message.total) AS totalSize" + ", message.priority AS ui_priority" + ", message.importance AS ui_importance" + - ", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" + + ", MAX(CASE WHEN" + + " (:found AND folder.type <> '" + EntityFolder.ARCHIVE + "' AND NOT (" + is_outgoing + "))" + + " OR (NOT :found AND folder.id = :folder)" + + " THEN message.received ELSE 0 END) AS dummy" + " FROM (SELECT * FROM message" + " WHERE message.thread IN" + " (SELECT DISTINCT mm.thread FROM message mm" + @@ -242,7 +246,6 @@ public interface DaoMessage { " WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN" + " CASE WHEN :filter_archive THEN 9 ELSE 0 END" + " ELSE 999 END") - // The folder type sort order should match the duplicate algorithm DataSource.Factory pagedThread( long account, String thread, Long id, boolean filter_archive,