FairEmail/app/src/main/java/eu/faircode/email/DaoFolder.java

264 lines
12 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2018-12-31 08:04:33 +00:00
Copyright 2018-2019 by Marcel Bokhorst (M66B)
2018-08-02 13:33:06 +00:00
*/
2018-08-08 06:55:47 +00:00
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
2018-08-02 13:33:06 +00:00
@Dao
public interface DaoFolder {
2019-05-21 13:21:03 +00:00
@Query("SELECT * FROM folder WHERE account = :account")
2018-08-05 06:18:43 +00:00
List<EntityFolder> getFolders(long account);
2019-05-25 20:51:44 +00:00
@Query("SELECT folder.*" +
2019-06-08 07:51:00 +00:00
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
2019-05-25 20:51:44 +00:00
", 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" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" 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 AND account.synchronize" +
" GROUP BY folder.id")
List<TupleFolderEx> getFoldersEx(long account);
2018-12-16 07:40:25 +00:00
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
2019-02-28 15:19:15 +00:00
" WHERE account.synchronize" +
" AND folder.synchronize AND unified")
2018-12-11 18:01:44 +00:00
List<EntityFolder> getFoldersSynchronizingUnified();
2018-12-03 15:29:49 +00:00
2019-01-22 14:29:45 +00:00
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
2019-01-26 15:49:49 +00:00
" WHERE folder.id = :folder" +
2019-01-23 09:31:31 +00:00
" AND (:search OR (account.synchronize AND account.browse))")
2019-01-26 15:49:49 +00:00
EntityFolder getBrowsableFolder(long folder, boolean search);
2019-01-22 14:29:45 +00:00
2019-05-01 05:58:45 +00:00
@Query("SELECT folder.*" +
2019-05-06 20:34:18 +00:00
", account.`order` AS accountOrder, account.name AS accountName" +
2019-05-01 05:58:45 +00:00
" FROM folder" +
" JOIN account ON account.id = folder.account" +
2019-05-01 05:58:45 +00:00
" WHERE account.`synchronize`")
2019-05-08 18:33:40 +00:00
List<TupleFolderSort> getSortedFolders();
2019-05-01 05:58:45 +00:00
2019-02-27 19:55:33 +00:00
@Query("SELECT folder.*" +
2019-06-08 07:51:00 +00:00
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
2018-08-02 13:33:06 +00:00
", COUNT(message.id) AS messages" +
2018-09-16 18:07:26 +00:00
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
2018-08-02 13:33:06 +00:00
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
2018-08-02 13:33:06 +00:00
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
2018-12-06 10:59:57 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" WHERE CASE WHEN :account IS NULL" +
" THEN folder.unified AND account.synchronize" +
2019-03-18 13:35:45 +00:00
" ELSE folder.account = :account AND account.synchronize" +
" END" +
2018-08-02 13:33:06 +00:00
" GROUP BY folder.id")
2019-05-25 20:09:15 +00:00
LiveData<List<TupleFolderEx>> liveFolders(Long account);
2018-08-05 15:42:02 +00:00
2019-02-27 19:55:33 +00:00
@Query("SELECT folder.*" +
2019-06-08 07:51:00 +00:00
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
2018-08-23 11:43:27 +00:00
", COUNT(message.id) AS messages" +
2018-09-16 18:07:26 +00:00
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
2018-08-23 11:43:27 +00:00
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
2018-08-23 11:43:27 +00:00
" FROM folder" +
" JOIN account ON account.id = folder.account" +
2019-02-28 12:35:19 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
2018-08-24 18:16:08 +00:00
" WHERE account.`synchronize`" +
" AND folder.unified" +
2018-08-23 11:43:27 +00:00
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveUnified();
@Query("SELECT folder.*" +
2019-05-06 20:34:18 +00:00
", account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id) AS operations" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" WHERE account.id IS NULL" +
" OR (account.`synchronize` AND folder.navigation)" +
" GROUP BY folder.id")
LiveData<List<TupleFolderNav>> liveNavigation();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
2019-03-06 17:08:29 +00:00
" WHERE account.synchronize" +
" AND account.`primary`" +
" AND folder.type = '" + EntityFolder.DRAFTS + "'")
LiveData<EntityFolder> livePrimaryDrafts();
2019-03-20 14:52:51 +00:00
@Query("SELECT COUNT(id) FROM folder" +
" WHERE sync_state = 'syncing'" +
" AND folder.type <> '" + EntityFolder.OUTBOX + "'")
LiveData<Integer> liveSynchronizing();
2019-02-27 19:55:33 +00:00
@Query("SELECT folder.*" +
2019-06-08 07:51:00 +00:00
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
2018-08-02 13:33:06 +00:00
", COUNT(message.id) AS messages" +
2018-09-16 18:07:26 +00:00
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
2018-08-02 13:33:06 +00:00
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
2018-08-02 13:33:06 +00:00
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
2018-12-06 10:59:57 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
2018-08-02 13:33:06 +00:00
" WHERE folder.id = :id")
LiveData<TupleFolderEx> liveFolderEx(long id);
2019-04-27 19:43:48 +00:00
@Query("SELECT * FROM folder ORDER BY account, name COLLATE NOCASE")
2018-11-26 16:04:32 +00:00
List<EntityFolder> getFolders();
2018-12-05 10:50:07 +00:00
@Query("SELECT * FROM folder" +
" WHERE folder.account = :account" +
" AND type <> '" + EntityFolder.USER + "'")
List<EntityFolder> getSystemFolders(long account);
2018-08-02 13:33:06 +00:00
@Query("SELECT * FROM folder WHERE id = :id")
EntityFolder getFolder(Long id);
@Query("SELECT * FROM folder WHERE account = :account AND name = :name")
2018-08-04 18:52:09 +00:00
EntityFolder getFolderByName(Long account, String name);
2018-08-02 13:33:06 +00:00
@Query("SELECT folder.* FROM folder" +
2018-08-04 18:52:09 +00:00
" WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String type);
2018-08-02 13:33:06 +00:00
2018-08-10 09:45:36 +00:00
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
2018-08-10 09:45:36 +00:00
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
EntityFolder getPrimaryDrafts();
2018-08-08 11:21:19 +00:00
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'")
EntityFolder getPrimaryArchive();
2018-08-09 07:02:41 +00:00
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'")
2018-08-02 13:33:06 +00:00
EntityFolder getOutbox();
@Query("SELECT download FROM folder WHERE id = :id")
2018-12-25 08:37:19 +00:00
boolean getFolderDownload(long id);
2018-08-12 08:16:41 +00:00
@Insert
2018-08-02 13:33:06 +00:00
long insertFolder(EntityFolder folder);
2019-05-25 15:14:51 +00:00
@Query("UPDATE folder SET unified = :unified WHERE id = :id")
int setFolderUnified(long id, boolean unified);
@Query("UPDATE folder SET navigation = :navigation WHERE id = :id")
int setFolderNavigation(long id, boolean navigation);
@Query("UPDATE folder SET notify = :notify WHERE id = :id")
int setFolderNotify(long id, boolean notify);
@Query("UPDATE folder SET synchronize = :synchronize WHERE id = :id")
int setFolderSynchronize(long id, boolean synchronize);
2018-08-13 14:44:47 +00:00
@Query("UPDATE folder SET state = :state WHERE id = :id")
int setFolderState(long id, String state);
2018-12-03 12:41:36 +00:00
@Query("UPDATE folder SET sync_state = :state WHERE id = :id")
int setFolderSyncState(long id, String state);
2019-03-09 08:20:46 +00:00
@Query("UPDATE folder SET total = :total WHERE id = :id")
int setFolderTotal(long id, Integer total);
2018-08-13 14:44:47 +00:00
@Query("UPDATE folder SET error = :error WHERE id = :id")
int setFolderError(long id, String error);
2019-04-25 15:23:56 +00:00
@Query("UPDATE folder SET subscribed = :subscribed WHERE id = :id")
int setFolderSubscribed(long id, Boolean subscribed);
2018-08-13 14:44:47 +00:00
@Query("UPDATE folder SET type = :type WHERE id = :id")
int setFolderType(long id, String type);
2018-12-22 17:39:16 +00:00
@Query("UPDATE folder SET display = :display WHERE id = :id")
int setFolderDisplay(long id, String display);
2019-04-29 11:09:11 +00:00
@Query("UPDATE folder SET `order` = :order WHERE id = :id")
int setFolderOrder(long id, Integer order);
2019-03-17 19:32:57 +00:00
@Query("UPDATE folder SET parent = :parent WHERE id = :id")
int setFolderParent(long id, Long parent);
2019-03-18 08:33:40 +00:00
@Query("UPDATE folder SET collapsed = :collapsed WHERE id = :id")
int setFolderCollapsed(long id, boolean collapsed);
2018-08-15 09:50:39 +00:00
@Query("UPDATE folder" +
" SET type = '" + EntityFolder.USER + "'" +
2018-12-31 10:04:18 +00:00
" WHERE account = :account" +
2019-02-02 11:50:57 +00:00
" AND type <> '" + EntityFolder.INBOX + "'" +
2018-12-31 10:04:18 +00:00
" AND type <> '" + EntityFolder.SYSTEM + "'")
int setFoldersUser(long account);
@Query("UPDATE folder" +
2018-12-22 11:40:47 +00:00
" SET display = :display" +
", unified = :unified" +
", navigation = :navigation" +
", notify = :notify" +
", synchronize = :synchronize" +
", poll = :poll" +
", download = :download" +
2018-11-14 09:49:59 +00:00
", `sync_days` = :sync_days" +
", `keep_days` = :keep_days" +
", auto_delete = :auto_delete" +
" WHERE id = :id")
int setFolderProperties(
long id,
2019-06-05 05:13:15 +00:00
String display, boolean unified, boolean navigation, boolean notify,
boolean synchronize, boolean poll, boolean download,
int sync_days, int keep_days, boolean auto_delete);
2018-08-02 13:33:06 +00:00
2018-11-26 08:12:44 +00:00
@Query("UPDATE folder SET keywords = :keywords WHERE id = :id")
int setFolderKeywords(long id, String keywords);
2018-09-14 06:28:23 +00:00
@Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old")
int renameFolder(long account, String old, String name);
@Query("UPDATE folder SET initialize = 0 WHERE id = :id")
int setFolderInitialized(long id);
2019-01-01 18:49:21 +00:00
@Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id")
int setFolderSync(long id, long last_sync);
2019-04-30 07:06:32 +00:00
@Query("UPDATE folder SET read_only = :read_only WHERE id = :id")
int setFolderReadOnly(long id, boolean read_only);
2019-02-04 10:08:09 +00:00
@Query("UPDATE folder SET tbc = null WHERE id = :id")
2018-12-22 11:40:47 +00:00
int resetFolderTbc(long id);
@Query("UPDATE folder SET tbd = 1 WHERE id = :id")
int setFolderTbd(long id);
@Query("DELETE FROM folder WHERE id = :id")
void deleteFolder(long id);
2018-12-22 11:40:47 +00:00
@Query("DELETE FROM folder WHERE account = :account AND name = :name")
void deleteFolder(long account, String name);
2018-08-02 13:33:06 +00:00
}