Prefer ingoing found messages

pull/194/merge
M66B 3 years ago
parent 929f179557
commit 8d862cc0c8

@ -42,6 +42,7 @@ public interface DaoMessage {
String is_drafts = "folder.type = '" + EntityFolder.DRAFTS + "'"; String is_drafts = "folder.type = '" + EntityFolder.DRAFTS + "'";
String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'"; String is_outbox = "folder.type = '" + EntityFolder.OUTBOX + "'";
String is_sent = "folder.type = '" + EntityFolder.SENT + "'"; String is_sent = "folder.type = '" + EntityFolder.SENT + "'";
String is_outgoing = is_drafts + " OR " + is_outbox + " OR " + is_sent;
@Transaction @Transaction
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@ -71,9 +72,9 @@ public interface DaoMessage {
", message.priority AS ui_priority" + ", message.priority AS ui_priority" +
", message.importance AS ui_importance" + ", message.importance AS ui_importance" +
", MAX(CASE WHEN" + ", 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 :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" + " THEN message.received ELSE 0 END) AS dummy" +
" FROM (SELECT * FROM message" + " FROM (SELECT * FROM message" +
" WHERE message.thread IN" + " WHERE message.thread IN" +
@ -150,7 +151,10 @@ public interface DaoMessage {
", SUM(message.total) AS totalSize" + ", SUM(message.total) AS totalSize" +
", message.priority AS ui_priority" + ", message.priority AS ui_priority" +
", message.importance AS ui_importance" + ", 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" + " FROM (SELECT * FROM message" +
" WHERE message.thread IN" + " WHERE message.thread IN" +
" (SELECT DISTINCT mm.thread FROM message mm" + " (SELECT DISTINCT mm.thread FROM message mm" +
@ -242,7 +246,6 @@ public interface DaoMessage {
" WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN" + " WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN" +
" CASE WHEN :filter_archive THEN 9 ELSE 0 END" + " CASE WHEN :filter_archive THEN 9 ELSE 0 END" +
" ELSE 999 END") " ELSE 999 END")
// The folder type sort order should match the duplicate algorithm
DataSource.Factory<Integer, TupleMessageEx> pagedThread( DataSource.Factory<Integer, TupleMessageEx> pagedThread(
long account, String thread, Long id, long account, String thread, Long id,
boolean filter_archive, boolean filter_archive,

Loading…
Cancel
Save