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
2024-01-01 07:50:49 +00:00
Copyright 2018 - 2024 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 ;
2020-08-08 14:28:03 +00:00
import androidx.room.Transaction ;
2021-10-03 14:55:16 +00:00
import androidx.room.Update ;
2018-08-08 06:55:47 +00:00
2019-04-17 18:21:44 +00:00
import java.util.List ;
2018-08-02 13:33:06 +00:00
@Dao
public interface DaoFolder {
2019-07-07 06:17:27 +00:00
@Query ( " SELECT * FROM folder " +
" WHERE account = :account " +
2019-07-07 07:25:52 +00:00
" AND (NOT :writable OR NOT read_only) " +
2019-07-07 06:17:27 +00:00
" AND (NOT :selectable OR selectable) " )
2019-07-07 07:25:52 +00:00
List < EntityFolder > getFolders ( long account , boolean writable , boolean selectable ) ;
2018-08-05 06:18:43 +00:00
2019-05-25 20:51:44 +00:00
@Query ( " SELECT folder.* " +
2019-11-23 12:48:59 +00:00
" , account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder " +
2022-02-18 20:14:43 +00:00
" , account.name AS accountName, account.category AS accountCategory, account.color AS accountColor " +
" , account.state AS accountState, account.error AS accountError " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN rule.enabled THEN rule.id ELSE NULL END) rules " +
2020-04-28 10:35:32 +00:00
" , COUNT(DISTINCT message.id) AS messages " +
" , COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content " +
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen " +
2024-03-03 09:46:48 +00:00
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND message.received > folder.last_view THEN message.id ELSE NULL END) AS unexposed " +
2020-05-19 06:46:49 +00:00
" , COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing " +
2019-05-25 20:51:44 +00:00
" FROM folder " +
" LEFT JOIN account ON account.id = folder.account " +
2020-04-28 10:35:32 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide " +
2019-06-27 06:09:22 +00:00
" LEFT JOIN rule ON rule.folder = folder.id " +
2020-11-27 18:09:14 +00:00
" LEFT JOIN operation ON operation.folder = folder.id " +
2020-04-25 14:40:28 +00:00
" WHERE folder.account = :account AND account.synchronize " +
2019-05-25 20:51:44 +00:00
" GROUP BY folder.id " )
List < TupleFolderEx > getFoldersEx ( long account ) ;
2018-12-16 07:40:25 +00:00
@Query ( " SELECT folder.* FROM folder " +
2019-06-07 16:33:35 +00:00
" JOIN account ON account.id = folder.account " +
2019-02-28 15:19:15 +00:00
" WHERE account.synchronize " +
2020-01-13 19:07:32 +00:00
" AND (NOT :synchronizing OR folder.synchronize) " +
2019-07-22 12:42:03 +00:00
" AND ((:type IS NULL AND folder.unified) OR folder.type = :type) " )
2020-01-13 19:07:32 +00:00
List < EntityFolder > getFoldersUnified ( String type , boolean synchronizing ) ;
2018-12-03 15:29:49 +00:00
2019-01-22 14:29:45 +00:00
@Query ( " SELECT folder.* FROM folder " +
2019-06-07 16:33:35 +00:00
" JOIN account ON account.id = folder.account " +
2019-01-26 15:49:49 +00:00
" WHERE folder.id = :folder " +
2019-11-23 12:48:59 +00:00
" AND (:search OR (account.synchronize AND account.browse AND account.pop = " + EntityAccount . TYPE_IMAP + " )) " )
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 " +
2019-06-07 16:33:35 +00:00
" 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
2020-08-08 14:28:03 +00:00
@Transaction
2019-02-27 19:55:33 +00:00
@Query ( " SELECT folder.* " +
2019-11-23 12:48:59 +00:00
" , account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder " +
2022-02-18 20:14:43 +00:00
" , account.name AS accountName, account.category AS accountCategory, account.color AS accountColor " +
" , account.state AS accountState, account.error AS accountError " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN rule.enabled THEN rule.id ELSE NULL END) rules " +
" , COUNT(DISTINCT CASE WHEN message.ui_hide THEN NULL ELSE message.id END) AS messages " +
" , COUNT(DISTINCT CASE WHEN message.content = 1 AND NOT message.ui_hide THEN message.id ELSE NULL END) AS content " +
2019-09-27 16:25:55 +00:00
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND NOT message.ui_hide THEN message.id ELSE NULL END) AS unseen " +
2024-03-03 09:46:48 +00:00
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND NOT message.ui_hide AND message.received > folder.last_view THEN message.id ELSE NULL END) AS unexposed " +
2020-05-19 06:46:49 +00:00
" , COUNT(DISTINCT CASE WHEN message.ui_flagged AND NOT message.ui_hide THEN message.id ELSE NULL END) AS flagged " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing " +
2018-08-02 13:33:06 +00:00
" FROM folder " +
2020-03-14 13:00:02 +00:00
" JOIN account ON account.id = folder.account " +
2019-06-27 06:09:22 +00:00
" LEFT JOIN message ON message.folder = folder.id " +
" LEFT JOIN rule ON rule.folder = folder.id " +
2020-11-27 18:09:14 +00:00
" LEFT JOIN operation ON operation.folder = folder.id " +
2020-03-14 13:00:02 +00:00
" WHERE CASE WHEN :primary THEN account.`primary` ELSE " +
" CASE WHEN :account IS NULL " +
" THEN folder.unified AND account.synchronize " +
" ELSE folder.account = :account AND account.synchronize " +
" END " +
2018-12-02 09:09:21 +00:00
" END " +
2018-08-02 13:33:06 +00:00
" GROUP BY folder.id " )
2020-03-14 13:00:02 +00:00
LiveData < List < TupleFolderEx > > liveFolders ( Long account , boolean primary ) ;
2018-08-05 15:42:02 +00:00
2023-10-22 13:30:34 +00:00
final String queryUnified = " SELECT folder.* " +
2019-11-23 12:48:59 +00:00
" , account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder " +
2022-02-18 20:14:43 +00:00
" , account.name AS accountName, account.category AS accountCategory, account.color AS accountColor " +
" , account.state AS accountState, account.error AS accountError " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN rule.enabled THEN rule.id ELSE NULL END) rules " +
2020-04-28 10:35:32 +00:00
" , COUNT(DISTINCT message.id) AS messages " +
" , COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content " +
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen " +
2024-03-03 09:46:48 +00:00
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND message.received > folder.last_view THEN message.id ELSE NULL END) AS unexposed " +
2020-05-19 06:46:49 +00:00
" , COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing " +
2018-08-23 11:43:27 +00:00
" FROM folder " +
" JOIN account ON account.id = folder.account " +
2020-04-28 10:35:32 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide " +
2019-06-27 06:09:22 +00:00
" LEFT JOIN rule ON rule.folder = folder.id " +
2020-11-27 18:09:14 +00:00
" LEFT JOIN operation ON operation.folder = folder.id " +
2018-08-24 18:16:08 +00:00
" WHERE account.`synchronize` " +
2019-07-22 11:44:25 +00:00
" AND ((:type IS NULL AND folder.unified) OR folder.type = :type) " +
2023-10-22 13:30:34 +00:00
" GROUP BY folder.id " ;
@Query ( queryUnified )
2019-07-22 11:44:25 +00:00
LiveData < List < TupleFolderEx > > liveUnified ( String type ) ;
2018-08-23 11:43:27 +00:00
2023-10-22 13:30:34 +00:00
@Query ( queryUnified )
List < TupleFolderEx > getUnified ( String type ) ;
2022-05-06 06:14:57 +00:00
@Query ( " SELECT folder.account, folder.id AS folder, unified, sync_state " +
" FROM folder " +
" JOIN account ON account.id = folder.account " +
" WHERE account.`synchronize` " +
" AND sync_state IS NOT NULL " +
2019-03-20 14:52:51 +00:00
" AND folder.type <> ' " + EntityFolder . OUTBOX + " ' " )
2021-09-02 21:06:59 +00:00
LiveData < List < TupleFolderSync > > liveSynchronizing ( ) ;
2019-03-20 14:52:51 +00:00
2019-02-27 19:55:33 +00:00
@Query ( " SELECT folder.* " +
2019-11-23 12:48:59 +00:00
" , account.id AS accountId, account.pop AS accountProtocol, account.`order` AS accountOrder " +
2022-02-18 20:14:43 +00:00
" , account.name AS accountName, account.category AS accountCategory, account.color AS accountColor " +
" , account.state AS accountState, account.error AS accountError " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN rule.enabled THEN rule.id ELSE NULL END) rules " +
2020-04-28 10:35:32 +00:00
" , COUNT(DISTINCT message.id) AS messages " +
" , COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content " +
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen THEN message.id ELSE NULL END) AS unseen " +
2024-03-03 09:46:48 +00:00
" , COUNT(DISTINCT CASE WHEN NOT message.ui_seen AND message.received > folder.last_view THEN message.id ELSE NULL END) AS unexposed " +
2020-05-19 06:46:49 +00:00
" , COUNT(DISTINCT CASE WHEN message.ui_flagged THEN message.id ELSE NULL END) AS flagged " +
2019-06-28 08:37:22 +00:00
" , COUNT(DISTINCT CASE WHEN operation.state = 'executing' THEN operation.id ELSE NULL END) AS executing " +
2018-08-02 13:33:06 +00:00
" FROM folder " +
" LEFT JOIN account ON account.id = folder.account " +
2020-04-28 10:35:32 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide " +
2019-06-27 06:09:22 +00:00
" LEFT JOIN rule ON rule.folder = folder.id " +
2020-11-27 18:09:14 +00:00
" LEFT JOIN operation ON operation.folder = folder.id " +
2019-06-21 06:39:36 +00:00
" WHERE folder.id = :id " +
" GROUP BY folder.id " )
2018-08-02 13:33:06 +00:00
LiveData < TupleFolderEx > liveFolderEx ( long id ) ;
2020-01-22 15:18:21 +00:00
@Query ( TupleFolderView . query )
LiveData < List < TupleFolderView > > liveFolderView ( ) ;
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 ) ;
2021-02-15 19:16:32 +00:00
@Query ( " SELECT * FROM folder " +
" WHERE folder.account = :account " +
" AND type <> ' " + EntityFolder . USER + " ' " )
LiveData < List < EntityFolder > > liveSystemFolders ( long account ) ;
2019-12-07 14:14:35 +00:00
@Query ( " SELECT * FROM folder " +
" WHERE folder.account = :account " +
2020-12-29 17:34:08 +00:00
" AND folder.selectable " +
2019-12-07 14:14:35 +00:00
" AND folder.synchronize " )
List < EntityFolder > getSynchronizingFolders ( long account ) ;
2023-11-05 09:17:59 +00:00
@Query ( " SELECT folder.* FROM folder " +
" JOIN account_view AS account ON account.id = folder.account " +
2020-03-28 09:20:52 +00:00
" WHERE folder.account = :account " +
2023-11-05 09:17:59 +00:00
" AND folder.notify " +
" AND account.`synchronize` " )
2020-03-28 09:20:52 +00:00
List < EntityFolder > getNotifyingFolders ( long account ) ;
2020-10-14 08:10:18 +00:00
@Query ( " SELECT * FROM folder " +
2020-10-18 07:24:41 +00:00
" WHERE parent = :parent " +
" ORDER BY name COLLATE NOCASE " )
2020-10-14 08:10:18 +00:00
List < EntityFolder > getChildFolders ( long parent ) ;
2022-11-06 16:47:46 +00:00
@Query ( " SELECT folder.type, folder.unified " +
2022-05-04 08:00:26 +00:00
" , COUNT(DISTINCT folder.id) AS folders " +
2019-11-08 18:51:02 +00:00
" , COUNT(message.id) AS messages " +
2019-11-08 18:53:45 +00:00
" , SUM(CASE WHEN NOT message.ui_seen THEN 1 ELSE 0 END) AS unseen " +
2024-03-03 09:46:48 +00:00
" , SUM(CASE WHEN NOT message.ui_seen AND message.received > folder.last_view THEN 1 ELSE 0 END) AS unexposed " +
2021-09-11 09:36:22 +00:00
" , CASE WHEN folder.account IS NULL THEN folder.sync_state ELSE NULL END AS sync_state " +
2021-09-22 19:14:37 +00:00
" , folder.color, COUNT (DISTINCT folder.color) AS colorCount " +
2019-07-19 06:27:44 +00:00
" FROM folder " +
2021-09-11 09:36:22 +00:00
" LEFT JOIN account ON account.id = folder.account " +
2019-11-08 18:53:45 +00:00
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide " +
2021-09-11 09:36:22 +00:00
" WHERE (account.id IS NULL OR account.synchronize) " +
2022-11-06 16:47:46 +00:00
" AND ((folder.type <> ' " + EntityFolder . SYSTEM + " ' " +
" AND folder.type <> ' " + EntityFolder . USER + " ') " +
" OR folder.unified) " +
" GROUP BY folder.type, folder.unified " )
2019-11-08 13:48:20 +00:00
LiveData < List < TupleFolderUnified > > liveUnified ( ) ;
2019-07-19 06:27:44 +00:00
2021-04-01 20:00:18 +00:00
@Query ( " SELECT * FROM folder " +
2021-04-19 13:07:01 +00:00
" WHERE account = :account " +
" AND selected_count > 0 " +
2021-04-01 20:00:18 +00:00
" AND NOT folder.id IN (:disabled) " +
" ORDER BY selected_count DESC, selected_last DESC " +
" LIMIT :count " )
2021-04-19 13:07:01 +00:00
List < EntityFolder > getFavoriteFolders ( long account , int count , long [ ] disabled ) ;
2021-04-01 20:00:18 +00:00
@Query ( " UPDATE folder " +
" SET selected_last = :last, selected_count = selected_count + 1 " +
" WHERE id = :id " )
int increaseSelectedCount ( long id , long last ) ;
@Query ( " UPDATE folder " +
2021-04-03 07:41:42 +00:00
" SET selected_last = 0, selected_count = 0 " +
" WHERE account = :account " )
int resetSelectedCount ( long account ) ;
2021-04-01 20:00:18 +00:00
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
2022-03-13 15:00:04 +00:00
@Query ( " SELECT folder.* FROM folder " +
" JOIN account ON account.id = folder.account " +
" WHERE account.synchronize " +
" AND type = :type " )
2021-06-16 16:14:45 +00:00
List < EntityFolder > getFoldersByType ( String type ) ;
2018-08-10 09:45:36 +00:00
@Query ( " SELECT folder.* FROM folder " +
2019-06-07 16:33:35 +00:00
" JOIN account ON account.id = folder.account " +
2019-08-29 15:51:53 +00:00
" WHERE account.synchronize " +
" AND account.`primary` " +
2024-04-13 07:53:00 +00:00
" AND type = :type " )
EntityFolder getFolderPrimary ( String type ) ;
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 ( ) ;
2019-06-07 16:33:35 +00:00
@Query ( " SELECT download FROM folder WHERE id = :id " )
2018-12-25 08:37:19 +00:00
boolean getFolderDownload ( long id ) ;
2023-07-06 09:11:40 +00:00
@Query ( " SELECT COUNT(*) FROM folder " +
" JOIN account ON account.id = folder.account " +
" WHERE account.synchronize " )
2022-01-12 16:13:25 +00:00
int countTotal ( ) ;
2023-07-06 09:11:40 +00:00
@Query ( " SELECT COUNT(*) FROM folder " +
" JOIN account ON account.id = folder.account " +
" WHERE account.synchronize AND folder.synchronize " )
int countSync ( ) ;
2018-08-12 08:16:41 +00:00
@Insert
2018-08-02 13:33:06 +00:00
long insertFolder ( EntityFolder folder ) ;
2021-09-24 07:51:57 +00:00
@Query ( " UPDATE folder " +
" SET namespace = :namespace, separator = :separator " +
" WHERE id = :id AND NOT (namespace IS :namespace AND separator IS :separator) " )
int setFolderNamespace ( long id , String namespace , Character separator ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET unified = :unified WHERE id = :id AND NOT (unified IS :unified) " )
2019-05-25 15:14:51 +00:00
int setFolderUnified ( long id , boolean unified ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET navigation = :navigation WHERE id = :id AND NOT (navigation IS :navigation) " )
2019-05-25 15:14:51 +00:00
int setFolderNavigation ( long id , boolean navigation ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET notify = :notify WHERE id = :id AND NOT (notify IS :notify) " )
2019-05-25 15:14:51 +00:00
int setFolderNotify ( long id , boolean notify ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET synchronize = :synchronize WHERE id = :id AND NOT (synchronize IS :synchronize) " )
2019-05-03 13:18:32 +00:00
int setFolderSynchronize ( long id , boolean synchronize ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET state = :state WHERE id = :id AND NOT (state IS :state) " )
2018-08-13 14:44:47 +00:00
int setFolderState ( long id , String state ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET state = :state WHERE account = :account AND NOT (state IS :state) " )
2019-06-24 06:34:17 +00:00
int setFolderStates ( long account , String state ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET sync_state = :state WHERE id = :id AND NOT (sync_state IS :state) " )
2018-12-03 12:41:36 +00:00
int setFolderSyncState ( long id , String state ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET total = :total WHERE id = :id AND NOT (total IS :total) " )
2019-03-09 08:20:46 +00:00
int setFolderTotal ( long id , Integer total ) ;
2022-05-02 13:23:16 +00:00
@Query ( " UPDATE folder SET total = :total, last_sync = :last_sync " +
" WHERE id = :id " +
" AND NOT (total IS :total AND last_sync IS :last_sync) " )
int setFolderTotal ( long id , Integer total , Long last_sync ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET error = :error WHERE id = :id AND NOT (error IS :error) " )
2018-08-13 14:44:47 +00:00
int setFolderError ( long id , String error ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET subscribed = :subscribed WHERE id = :id AND NOT (subscribed IS :subscribed) " )
2019-04-25 15:23:56 +00:00
int setFolderSubscribed ( long id , Boolean subscribed ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET selectable = :selectable WHERE id = :id AND NOT (selectable IS :selectable) " )
2019-09-18 06:56:33 +00:00
int setFolderSelectable ( long id , Boolean selectable ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET inferiors = :inferiors WHERE id = :id AND NOT (inferiors IS :inferiors) " )
2020-02-24 08:32:03 +00:00
int setFolderInferiors ( long id , Boolean inferiors ) ;
2021-08-19 06:09:08 +00:00
@Query ( " UPDATE folder SET name = :name WHERE id = :id AND NOT (name IS :name) " )
int setFolderName ( long id , String name ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET type = :type WHERE id = :id AND NOT (type IS :type) " )
2018-08-13 14:44:47 +00:00
int setFolderType ( long id , String type ) ;
2022-08-07 13:27:17 +00:00
@Query ( " UPDATE folder SET inherited_type = :type WHERE id = :id AND NOT (inherited_type IS :type) " )
int setFolderInheritedType ( long id , String type ) ;
2023-01-18 19:54:42 +00:00
@Query ( " UPDATE folder SET subtype = :subtype WHERE id = :id AND NOT (subtype IS :subtype) " )
int setFolderSubtype ( long id , String subtype ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET `order` = :order WHERE id = :id AND NOT (`order` IS :order) " )
2019-04-29 11:09:11 +00:00
int setFolderOrder ( long id , Integer order ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET parent = :parent WHERE id = :id AND NOT (parent IS :parent) " )
2019-03-17 19:32:57 +00:00
int setFolderParent ( long id , Long parent ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET collapsed = :collapsed WHERE id = :id AND NOT (collapsed IS :collapsed) " )
2019-03-18 08:33:40 +00:00
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 + " ' " +
2020-11-29 11:14:01 +00:00
" AND type <> ' " + EntityFolder . SYSTEM + " ' " +
" AND type <> ' " + EntityFolder . USER + " ' " )
2018-10-22 18:02:06 +00:00
int setFoldersUser ( long account ) ;
2018-08-14 06:40:36 +00:00
2018-09-21 15:19:37 +00:00
@Query ( " UPDATE folder " +
2019-07-29 19:53:32 +00:00
" SET `rename` = :rename " +
" , display = :display " +
2019-10-07 16:15:02 +00:00
" , color = :color " +
2018-12-06 12:43:00 +00:00
" , unified = :unified " +
2019-04-29 08:14:55 +00:00
" , navigation = :navigation " +
2023-02-03 08:38:06 +00:00
" , count_unread = :count_unread " +
2018-12-14 11:31:25 +00:00
" , notify = :notify " +
2019-06-15 09:58:56 +00:00
" , hide = :hide " +
2022-04-17 14:54:38 +00:00
" , hide_seen = :hide_seen " +
2018-09-21 15:19:37 +00:00
" , synchronize = :synchronize " +
2018-12-05 09:25:35 +00:00
" , poll = :poll " +
2020-02-25 20:06:17 +00:00
" , poll_factor = :poll_factor " +
2018-12-14 11:31:25 +00:00
" , download = :download " +
2021-01-13 09:22:52 +00:00
" , auto_classify_source = :auto_classify_source " +
" , auto_classify_target = :auto_classify_target " +
2018-11-14 09:49:59 +00:00
" , `sync_days` = :sync_days " +
" , `keep_days` = :keep_days " +
2019-05-01 09:26:32 +00:00
" , auto_delete = :auto_delete " +
2018-09-21 15:19:37 +00:00
" WHERE id = :id " )
2018-12-02 09:09:21 +00:00
int setFolderProperties (
2019-07-29 19:53:32 +00:00
long id , String rename ,
2023-02-03 08:38:06 +00:00
String display , Integer color , boolean unified ,
boolean navigation , boolean count_unread , boolean notify ,
2022-04-17 14:54:38 +00:00
boolean hide , boolean hide_seen ,
2021-01-13 09:22:52 +00:00
boolean synchronize , boolean poll , int poll_factor , boolean download ,
boolean auto_classify_source , boolean auto_classify_target ,
2019-05-01 09:26:32 +00:00
int sync_days , int keep_days , boolean auto_delete ) ;
2018-08-02 13:33:06 +00:00
2019-10-19 15:01:59 +00:00
@Query ( " UPDATE folder " +
2020-08-15 18:01:00 +00:00
" SET sync_days = :sync_days, keep_days = :keep_days " +
2021-06-06 08:08:33 +00:00
" WHERE id = :id " +
" AND NOT (sync_days IS :sync_days AND keep_days IS :keep_days) " )
int setFolderProperties ( long id , int sync_days , int keep_days ) ;
2019-10-19 15:01:59 +00:00
2023-04-18 15:59:28 +00:00
@Query ( " UPDATE folder SET flags = :flags WHERE id = :id AND NOT (flags IS :flags) " )
int setFolderFlags ( long id , String flags ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET keywords = :keywords WHERE id = :id AND NOT (keywords IS :keywords) " )
2018-11-26 08:12:44 +00:00
int setFolderKeywords ( long id , String keywords ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET name = :name WHERE account = :account AND name = :old AND NOT (:old IS :name) " )
2018-09-14 06:28:23 +00:00
int renameFolder ( long account , String old , String name ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET initialize = :days WHERE id = :id AND NOT (initialize IS :days) " )
2019-06-24 10:45:52 +00:00
int setFolderInitialize ( long id , int days ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET keep_days = :days WHERE id = :id AND NOT (keep_days IS :days) " )
2019-06-24 10:45:52 +00:00
int setFolderKeep ( long id , int days ) ;
2018-12-11 11:18:26 +00:00
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET uidv = :uidv WHERE id = :id AND NOT (uidv IS :uidv) " )
2019-07-24 20:01:27 +00:00
int setFolderUidValidity ( long id , Long uidv ) ;
2021-04-06 20:25:08 +00:00
@Query ( " UPDATE folder SET modseq = :modseq WHERE id = :id AND NOT (modseq IS :modseq) " )
int setFolderModSeq ( long id , Long modseq ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET last_sync = :last_sync WHERE id = :id AND NOT (last_sync IS :last_sync) " )
2019-07-24 20:01:55 +00:00
int setFolderLastSync ( long id , long last_sync ) ;
2019-01-01 18:49:21 +00:00
2021-12-07 08:16:36 +00:00
@Query ( " UPDATE folder SET last_sync_foreground = :last_sync_foreground WHERE id = :id AND NOT (last_sync_foreground IS :last_sync_foreground) " )
int setFolderLastSyncForeground ( long id , long last_sync_foreground ) ;
2021-07-23 20:31:23 +00:00
@Query ( " UPDATE folder SET last_sync_count = :last_sync_count WHERE id = :id AND NOT (last_sync_count IS :last_sync_count) " )
int setFolderLastSyncCount ( long id , Integer last_sync_count ) ;
2024-03-02 20:37:59 +00:00
@Query ( " UPDATE folder SET last_view = :last_view " +
" WHERE (id = :folder " +
" OR (type = :type AND type <> ' " + EntityFolder . OUTBOX + " ') " +
" OR (account = :account AND :folder IS NULL AND :type IS NULL AND unified)) " )
int setFolderLastView ( Long account , Long folder , String type , long last_view ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET read_only = :read_only WHERE id = :id AND NOT (read_only IS :read_only) " )
2019-04-30 07:06:32 +00:00
int setFolderReadOnly ( long id , boolean read_only ) ;
2021-10-26 07:39:31 +00:00
@Query ( " UPDATE folder SET auto_add = :auto_add WHERE id = :id AND NOT (auto_add IS :auto_add) " )
int setFolderAutoAdd ( long id , Boolean auto_add ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET tbc = NULL WHERE id = :id AND tbc IS NOT NULL " )
2018-12-22 11:40:47 +00:00
int resetFolderTbc ( long id ) ;
2021-03-17 12:08:54 +00:00
@Query ( " UPDATE folder SET tbd = NULL WHERE id = :id AND tbd IS NOT NULL " )
int resetFolderTbd ( long id ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET `rename` = NULL WHERE id = :id AND `rename` IS NOT NULL " )
2019-07-29 19:53:32 +00:00
int resetFolderRename ( long id ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET tbd = 1 WHERE id = :id AND NOT (tbd IS 1) " )
2018-12-06 12:43:00 +00:00
int setFolderTbd ( long id ) ;
2020-11-29 08:22:19 +00:00
@Query ( " UPDATE folder " +
" SET poll = :poll, poll_count = 1 " +
" WHERE id = :id " +
2020-11-29 11:14:01 +00:00
" AND (NOT (poll IS :poll) OR NOT (poll_count IS 1)) " )
2020-10-06 09:35:35 +00:00
int setFolderPoll ( long id , boolean poll ) ;
2020-11-29 11:14:01 +00:00
@Query ( " UPDATE folder SET poll_count = :count WHERE id = :id AND NOT (poll_count IS :count) " )
2020-02-25 20:06:17 +00:00
int setFolderPollCount ( long id , int count ) ;
2021-01-16 14:09:12 +00:00
@Query ( " UPDATE folder SET download = :download WHERE id = :id AND NOT (download IS :download) " )
int setFolderDownload ( long id , boolean download ) ;
2023-01-09 16:42:57 +00:00
@Query ( " UPDATE folder SET hide = :hide WHERE id = :id AND NOT (hide IS :hide) " )
int setFolderHide ( long id , boolean hide ) ;
2021-01-13 09:22:52 +00:00
@Query ( " UPDATE folder " +
" SET auto_classify_source = :source, auto_classify_target = :target " +
" WHERE id = :id " +
" AND NOT (auto_classify_source IS :source AND auto_classify_target IS :target) " )
int setFolderAutoClassify ( long id , boolean source , boolean target ) ;
2021-01-05 09:18:02 +00:00
2021-10-03 14:55:16 +00:00
@Update
int updateFolder ( EntityFolder folder ) ;
2018-09-14 08:15:45 +00:00
@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
}