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.
|
|
|
|
|
|
|
|
NetGuard is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-08 06:55:47 +00:00
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
import androidx.room.Dao;
|
|
|
|
import androidx.room.Insert;
|
|
|
|
import androidx.room.Query;
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Dao
|
|
|
|
public interface DaoFolder {
|
2018-08-26 08:33:22 +00:00
|
|
|
@Query("SELECT * FROM folder" +
|
|
|
|
" WHERE account = :account" +
|
|
|
|
" ORDER BY CASE WHEN folder.type = '" + EntityFolder.USER + "' THEN 1 ELSE 0 END")
|
2018-08-05 06:18:43 +00:00
|
|
|
List<EntityFolder> getFolders(long account);
|
|
|
|
|
2018-08-13 18:54:16 +00:00
|
|
|
@Query("SELECT * FROM folder" +
|
|
|
|
" WHERE account = :account" +
|
|
|
|
" AND synchronize = :synchronize" +
|
|
|
|
" ORDER BY CASE WHEN folder.type = '" + EntityFolder.USER + "' THEN 1 ELSE 0 END")
|
2018-08-02 13:33:06 +00:00
|
|
|
List<EntityFolder> getFolders(long account, boolean synchronize);
|
|
|
|
|
2018-08-13 18:54:16 +00:00
|
|
|
@Query("SELECT * FROM folder" +
|
|
|
|
" WHERE account = :account" +
|
|
|
|
" AND type = '" + EntityFolder.USER + "'")
|
2018-08-02 13:33:06 +00:00
|
|
|
List<EntityFolder> getUserFolders(long account);
|
|
|
|
|
|
|
|
@Query("SELECT folder.*, account.name AS accountName" +
|
|
|
|
", COUNT(message.id) AS messages" +
|
|
|
|
", 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" +
|
2018-08-08 11:21:19 +00:00
|
|
|
" WHERE folder.account = :account OR folder.account IS NULL" +
|
2018-08-02 13:33:06 +00:00
|
|
|
" GROUP BY folder.id")
|
2018-08-07 20:30:45 +00:00
|
|
|
LiveData<List<TupleFolderEx>> liveFolders(long account);
|
2018-08-05 15:42:02 +00:00
|
|
|
|
2018-08-23 11:43:27 +00:00
|
|
|
@Query("SELECT folder.*, account.name AS accountName" +
|
|
|
|
", COUNT(message.id) AS messages" +
|
|
|
|
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
|
|
|
" FROM folder" +
|
|
|
|
" JOIN account ON account.id = folder.account" +
|
2018-08-24 18:16:08 +00:00
|
|
|
" JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
|
|
|
|
" WHERE account.`synchronize`" +
|
2018-09-05 09:41:16 +00:00
|
|
|
" AND folder.unified" +
|
2018-08-23 11:43:27 +00:00
|
|
|
" GROUP BY folder.id")
|
|
|
|
LiveData<List<TupleFolderEx>> liveUnified();
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@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.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")
|
|
|
|
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
|
|
|
// For debug/crash info
|
|
|
|
@Query("SELECT folder.* FROM folder" +
|
|
|
|
" JOIN account ON account.id = folder.account" +
|
|
|
|
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
|
|
|
|
EntityFolder getPrimaryDrafts();
|
2018-08-08 11:21:19 +00:00
|
|
|
|
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();
|
|
|
|
|
2018-08-12 08:16:41 +00:00
|
|
|
@Insert
|
2018-08-02 13:33:06 +00:00
|
|
|
long insertFolder(EntityFolder folder);
|
|
|
|
|
2018-08-13 14:44:47 +00:00
|
|
|
@Query("UPDATE folder SET state = :state WHERE id = :id")
|
|
|
|
int setFolderState(long id, String state);
|
|
|
|
|
|
|
|
@Query("UPDATE folder SET error = :error WHERE id = :id")
|
|
|
|
int setFolderError(long id, String error);
|
|
|
|
|
|
|
|
@Query("UPDATE folder SET type = :type WHERE id = :id")
|
|
|
|
int setFolderType(long id, String type);
|
|
|
|
|
2018-08-15 09:50:39 +00:00
|
|
|
@Query("UPDATE folder" +
|
|
|
|
" SET type = '" + EntityFolder.USER + "'" +
|
|
|
|
" WHERE account = :account" +
|
|
|
|
" AND type = :type")
|
|
|
|
int setFolderUser(long account, String type);
|
2018-08-14 06:40:36 +00:00
|
|
|
|
2018-09-05 09:41:16 +00:00
|
|
|
@Query("UPDATE folder SET synchronize = :synchronize, unified = :unified, after = :after WHERE id = :id")
|
|
|
|
int setFolderProperties(long id, boolean synchronize, boolean unified, int after);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
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);
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Query("DELETE FROM folder WHERE account= :account AND name = :name")
|
2018-08-04 15:52:03 +00:00
|
|
|
void deleteFolder(Long account, String name);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|