|
|
@ -35,15 +35,17 @@ 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 |
|
|
|
|
|
|
|
@Query("SELECT message.*, account.name AS accountName, folder.name as folderName, folder.type as folderType" + |
|
|
|
@Query("SELECT message.*, maccount.name AS accountName, folder.name as folderName, folder.type as folderType" + |
|
|
|
", COUNT(message.id) as count" + |
|
|
|
", SUM(CASE WHEN message.ui_seen THEN 0 ELSE 1 END) as unseen" + |
|
|
|
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" + |
|
|
|
", MAX(CASE WHEN folder.type = '" + EntityFolder.INBOX + "' THEN message.id ELSE 0 END) as dummy" + |
|
|
|
" FROM message" + |
|
|
|
" LEFT JOIN account ON account.id = message.account" + |
|
|
|
" LEFT JOIN account maccount ON maccount.id = message.account" + |
|
|
|
" JOIN folder ON folder.id = message.folder" + |
|
|
|
" WHERE (NOT message.ui_hide OR :debug)" + |
|
|
|
" JOIN account ON account.id = folder.account" + |
|
|
|
" WHERE account.`synchronize`" + |
|
|
|
" AND (NOT message.ui_hide OR :debug)" + |
|
|
|
" GROUP BY CASE WHEN message.thread IS NULL THEN message.id ELSE message.thread END" + |
|
|
|
" HAVING SUM(CASE WHEN folder.type = '" + EntityFolder.INBOX + "' THEN 1 ELSE 0 END) > 0" + |
|
|
|
" ORDER BY message.received DESC") |
|
|
|