This commit is contained in:
Martin Rotter 2021-08-15 20:06:50 +02:00
parent b05484b57d
commit 4476dcf811
7 changed files with 37 additions and 21 deletions

View File

@ -1524,7 +1524,10 @@ bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, int account_id) {
return true;
}
bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too) {
bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db,
int account_id,
bool delete_messages_too,
bool delete_labels_too) {
bool result = true;
QSqlQuery q(db);
@ -1545,15 +1548,16 @@ bool DatabaseQueries::deleteAccountData(const QSqlDatabase& db, int account_id,
result &= q.exec();
if (delete_messages_too) {
// If we delete message, make sure to delete message/label assignments too.
q.prepare(QSL("DELETE FROM LabelsInMessages WHERE account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
result &= q.exec();
}
q.prepare(QSL("DELETE FROM Labels WHERE account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
result &= q.exec();
if (delete_labels_too) {
q.prepare(QSL("DELETE FROM Labels WHERE account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
result &= q.exec();
}
return result;
}

View File

@ -116,7 +116,7 @@ class DatabaseQueries {
static QPair<int, int> updateMessages(QSqlDatabase db, const QList<Message>& messages,
Feed* feed, bool force_update, bool* ok = nullptr);
static bool deleteAccount(const QSqlDatabase& db, int account_id);
static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too);
static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too, bool delete_labels_too);
static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label);
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);

View File

@ -167,10 +167,10 @@ bool ServiceRoot::canBeDeleted() const {
void ServiceRoot::completelyRemoveAllData() {
// Purge old data from SQL and clean all model items.
cleanAllItemsFromModel();
removeOldAccountFromDatabase(true);
cleanAllItemsFromModel(true);
removeOldAccountFromDatabase(true, true);
updateCounts(true);
itemChanged(QList<RootItem*>() << this);
itemChanged({ this });
requestReloadMessageList(true);
}
@ -188,13 +188,16 @@ QIcon ServiceRoot::feedIconForMessage(const QString& feed_custom_id) const {
}
}
void ServiceRoot::removeOldAccountFromDatabase(bool including_messages) {
void ServiceRoot::removeOldAccountFromDatabase(bool delete_messages_too, bool delete_labels_too) {
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
DatabaseQueries::deleteAccountData(database, accountId(), including_messages);
DatabaseQueries::deleteAccountData(database,
accountId(),
delete_messages_too,
delete_labels_too);
}
void ServiceRoot::cleanAllItemsFromModel() {
void ServiceRoot::cleanAllItemsFromModel(bool clean_labels_too) {
auto chi = childItems();
for (RootItem* top_level_item : qAsConst(chi)) {
@ -206,7 +209,7 @@ void ServiceRoot::cleanAllItemsFromModel() {
}
}
if (labelsNode() != nullptr) {
if (labelsNode() != nullptr && clean_labels_too) {
auto lbl_chi = labelsNode()->childItems();
for (RootItem* lbl : qAsConst(lbl_chi)) {
@ -425,8 +428,13 @@ void ServiceRoot::syncIn() {
auto feed_custom_data = storeCustomFeedsData();
// Remove from feeds model, then from SQL but leave messages intact.
cleanAllItemsFromModel();
removeOldAccountFromDatabase(false);
bool uses_remote_labels = (supportedLabelOperations() & LabelOperation::Synchronised) == LabelOperation::Synchronised;
// Remove stuff.
cleanAllItemsFromModel(uses_remote_labels);
removeOldAccountFromDatabase(false, uses_remote_labels);
// Restore some local settings to feeds etc.
restoreCustomFeedsData(feed_custom_data, new_tree->getHashedSubTreeFeeds());
// Model is clean, now store new tree into DB and

View File

@ -33,7 +33,11 @@ class ServiceRoot : public RootItem {
enum class LabelOperation {
Adding = 1,
Editing = 2,
Deleting = 4
Deleting = 4,
// NOTE: Service fetches list of labels from remote source
// and does not use local offline labels.
Synchronised = 8
};
enum class BagOfMessages {
@ -226,9 +230,9 @@ class ServiceRoot : public RootItem {
// Removes all messages/categories/feeds which are
// associated with this account.
void removeOldAccountFromDatabase(bool including_messages);
void removeOldAccountFromDatabase(bool delete_messages_too, bool delete_labels_too);
void storeNewFeedTree(RootItem* root);
void cleanAllItemsFromModel();
void cleanAllItemsFromModel(bool clean_labels_too);
void appendCommonNodes();
// Removes messages which do not belong to any

View File

@ -233,7 +233,7 @@ void FeedlyServiceRoot::saveAllCachedData(bool ignore_errors) {
}
ServiceRoot::LabelOperation FeedlyServiceRoot::supportedLabelOperations() const {
return LabelOperation(0);
return ServiceRoot::LabelOperation::Synchronised;
}
void FeedlyServiceRoot::updateTitle() {

View File

@ -257,7 +257,7 @@ void GreaderServiceRoot::saveAllCachedData(bool ignore_errors) {
}
ServiceRoot::LabelOperation GreaderServiceRoot::supportedLabelOperations() const {
return LabelOperation(0);
return ServiceRoot::LabelOperation::Synchronised;
}
void GreaderServiceRoot::updateTitleIcon() {

View File

@ -34,7 +34,7 @@ TtRssServiceRoot::~TtRssServiceRoot() {
}
ServiceRoot::LabelOperation TtRssServiceRoot::supportedLabelOperations() const {
return ServiceRoot::LabelOperation(0);
return ServiceRoot::LabelOperation::Synchronised;
}
void TtRssServiceRoot::start(bool freshly_activated) {