|
|
@ -17,6 +17,7 @@ package org.dystopia.email; |
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
Copyright 2018, Marcel Bokhorst (M66B) |
|
|
|
Copyright 2018, Distopico (dystopia project) <distopico@riseup.net> and contributors |
|
|
|
*/ |
|
|
|
|
|
|
|
import androidx.lifecycle.LiveData; |
|
|
@ -27,76 +28,53 @@ import java.util.List; |
|
|
|
|
|
|
|
@Dao |
|
|
|
public interface DaoFolder { |
|
|
|
@Query( |
|
|
|
"SELECT * FROM folder" |
|
|
|
+ " WHERE account = :account" |
|
|
|
+ " ORDER BY CASE WHEN folder.type = '" |
|
|
|
+ EntityFolder.USER |
|
|
|
+ "' THEN 1 ELSE 0 END") |
|
|
|
@Query("SELECT * FROM folder" + " WHERE account = :account" |
|
|
|
+ " ORDER BY CASE WHEN folder.type = '" + EntityFolder.USER + "' THEN 1 ELSE 0 END") |
|
|
|
List<EntityFolder> getFolders(long account); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT * FROM folder" |
|
|
|
+ " WHERE account = :account" |
|
|
|
+ " AND synchronize = :synchronize" |
|
|
|
+ " ORDER BY CASE WHEN folder.type = '" |
|
|
|
+ EntityFolder.USER |
|
|
|
+ "' THEN 1 ELSE 0 END") |
|
|
|
@Query("SELECT * FROM folder" + " WHERE account = :account" + " AND synchronize = :synchronize" |
|
|
|
+ " ORDER BY CASE WHEN folder.type = '" + EntityFolder.USER + "' THEN 1 ELSE 0 END") |
|
|
|
List<EntityFolder> getFolders(long account, boolean synchronize); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT * FROM folder" |
|
|
|
+ " WHERE account = :account" |
|
|
|
+ " AND type = '" |
|
|
|
+ EntityFolder.USER |
|
|
|
+ "'") |
|
|
|
@Query("SELECT * FROM folder" + " WHERE account = :account" + " AND type = '" + EntityFolder.USER |
|
|
|
+ "'") |
|
|
|
List<EntityFolder> getUserFolders(long account); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT folder.*, account.name AS accountName" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" |
|
|
|
+ " FROM folder" |
|
|
|
+ " LEFT JOIN account ON account.id = folder.account" |
|
|
|
+ " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE folder.account = :account OR folder.account IS NULL" |
|
|
|
+ " GROUP BY folder.id") |
|
|
|
@Query("SELECT * FROM folder WHERE unified") |
|
|
|
List<EntityFolder> getUnifiedFolders(); |
|
|
|
|
|
|
|
@Query("SELECT folder.*, account.name AS accountName, account.state as accountState" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + " FROM folder" |
|
|
|
+ " LEFT JOIN account ON account.id = folder.account" |
|
|
|
+ " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE folder.account = :account OR folder.account IS NULL" + " GROUP BY folder.id") |
|
|
|
LiveData<List<TupleFolderEx>> liveFolders(long account); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT * FROM folder" |
|
|
|
+ " WHERE (:account < 0 OR folder.account = :account)" |
|
|
|
+ " AND type <> '" |
|
|
|
+ EntityFolder.USER |
|
|
|
+ "'") |
|
|
|
@Query("SELECT * FROM folder" + " WHERE (:account < 0 OR folder.account = :account)" |
|
|
|
+ " AND type <> '" + EntityFolder.USER + "'") |
|
|
|
LiveData<List<EntityFolder>> liveSystemFolders(long account); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT folder.*, account.name AS accountName" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" |
|
|
|
+ " FROM folder" |
|
|
|
+ " JOIN account ON account.id = folder.account" |
|
|
|
+ " JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE account.`synchronize`" |
|
|
|
+ " AND folder.unified" |
|
|
|
+ " GROUP BY folder.id") |
|
|
|
@Query("SELECT folder.*, account.name AS accountName, account.state as accountState" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + " FROM folder" |
|
|
|
+ " JOIN account ON account.id = folder.account" |
|
|
|
+ " JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE account.`synchronize`" + " AND folder.unified" + " GROUP BY folder.id") |
|
|
|
LiveData<List<TupleFolderEx>> liveUnified(); |
|
|
|
|
|
|
|
@Query("SELECT folder.* FROM folder WHERE folder.id = :id") |
|
|
|
LiveData<EntityFolder> liveFolder(long id); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT folder.*, account.name AS accountName" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" |
|
|
|
+ " FROM folder" |
|
|
|
+ " LEFT JOIN account ON account.id = folder.account" |
|
|
|
+ " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE folder.id = :id") |
|
|
|
@Query("SELECT folder.*, account.name AS accountName, account.state as accountState" |
|
|
|
+ ", COUNT(message.id) AS messages" |
|
|
|
+ ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" |
|
|
|
+ ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + " FROM folder" |
|
|
|
+ " LEFT JOIN account ON account.id = folder.account" |
|
|
|
+ " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" |
|
|
|
+ " WHERE folder.id = :id") |
|
|
|
LiveData<TupleFolderEx> liveFolderEx(long id); |
|
|
|
|
|
|
|
@Query("SELECT * FROM folder WHERE id = :id") |
|
|
@ -109,20 +87,12 @@ public interface DaoFolder { |
|
|
|
EntityFolder getFolderByType(long account, String type); |
|
|
|
|
|
|
|
// For debug/crash info |
|
|
|
@Query( |
|
|
|
"SELECT folder.* FROM folder" |
|
|
|
+ " JOIN account ON account.id = folder.account" |
|
|
|
+ " WHERE `primary` AND type = '" |
|
|
|
+ EntityFolder.DRAFTS |
|
|
|
+ "'") |
|
|
|
@Query("SELECT folder.* FROM folder" + " JOIN account ON account.id = folder.account" |
|
|
|
+ " WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'") |
|
|
|
EntityFolder getPrimaryDrafts(); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"SELECT folder.* FROM folder" |
|
|
|
+ " JOIN account ON account.id = folder.account" |
|
|
|
+ " WHERE `primary` AND type = '" |
|
|
|
+ EntityFolder.ARCHIVE |
|
|
|
+ "'") |
|
|
|
@Query("SELECT folder.* FROM folder" + " JOIN account ON account.id = folder.account" |
|
|
|
+ " WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'") |
|
|
|
EntityFolder getPrimaryArchive(); |
|
|
|
|
|
|
|
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'") |
|
|
@ -134,6 +104,9 @@ public interface DaoFolder { |
|
|
|
@Query("UPDATE folder SET state = :state WHERE id = :id") |
|
|
|
int setFolderState(long id, String state); |
|
|
|
|
|
|
|
@Query("UPDATE folder SET sync_state = :state WHERE id = :id") |
|
|
|
int setFolderSyncState(long id, String state); |
|
|
|
|
|
|
|
@Query("UPDATE folder SET error = :error WHERE id = :id") |
|
|
|
int setFolderError(long id, String error); |
|
|
|
|
|
|
@ -143,23 +116,11 @@ public interface DaoFolder { |
|
|
|
@Query("UPDATE folder" + " SET type = '" + EntityFolder.USER + "'" + " WHERE account = :account") |
|
|
|
int setFoldersUser(long account); |
|
|
|
|
|
|
|
@Query( |
|
|
|
"UPDATE folder" |
|
|
|
+ " SET name = :name" |
|
|
|
+ ", display = :display" |
|
|
|
+ ", hide = :hide" |
|
|
|
+ ", synchronize = :synchronize" |
|
|
|
+ ", unified = :unified" |
|
|
|
+ ", `after` = :after" |
|
|
|
+ " WHERE id = :id") |
|
|
|
int setFolderProperties( |
|
|
|
long id, |
|
|
|
String name, |
|
|
|
String display, |
|
|
|
boolean hide, |
|
|
|
boolean synchronize, |
|
|
|
boolean unified, |
|
|
|
int after); |
|
|
|
@Query("UPDATE folder" + " SET name = :name" + ", display = :display" + ", hide = :hide" |
|
|
|
+ ", synchronize = :synchronize" + ", unified = :unified" + ", `after` = :after" |
|
|
|
+ " WHERE id = :id") |
|
|
|
int setFolderProperties(long id, String name, String display, boolean hide, boolean synchronize, |
|
|
|
boolean unified, int after); |
|
|
|
|
|
|
|
@Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old") |
|
|
|
int renameFolder(long account, String old, String name); |
|
|
|