diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index f423059ff..8a4a25a20 100755 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -337,7 +337,9 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages const Message msg = messageAt(message.row()); RootItem::Importance message_importance = messageImportance((message.row())); - message_states.append(QPair(msg, message_importance)); + message_states.append(QPair(msg, message_importance == RootItem::Important ? + RootItem::NotImportant : + RootItem::Important)); message_ids.append(QString::number(msg.m_id)); } diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 5cb47e7b3..758adbd72 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -297,6 +297,104 @@ void ServiceRoot::requestItemRemoval(RootItem *item) { emit itemRemovalRequested(item); } +QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem *item) { + if (item->getParentServiceRoot() != this) { + // Not item from this account. + return QStringList(); + } + else { + QStringList list; + + switch (item->kind()) { + case RootItemKind::Category: { + foreach (RootItem *child, item->childItems()) { + list.append(customIDSOfMessagesForItem(child)); + } + + return list; + } + + case RootItemKind::ServiceRoot: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + case RootItemKind::Bin: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + case RootItemKind::Feed: { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query(database); + + query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;")); + query.bindValue(QSL(":account_id"), accountId()); + query.bindValue(QSL(":feed"), item->customId()); + query.exec(); + + while (query.next()) { + list.append(query.value(0).toString()); + } + + break; + } + + default: + break; + } + + return list; + } +} + +bool ServiceRoot::markFeedsReadUnread(QList items, RootItem::ReadStatus read) { + QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + QSqlQuery query_read_msg(db_handle); + query_read_msg.setForwardOnly(true); + query_read_msg.prepare(QString("UPDATE Messages SET is_read = :read " + "WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;").arg(textualFeedIds(items).join(QSL(", ")))); + + query_read_msg.bindValue(QSL(":read"), read == RootItem::Read ? 1 : 0); + query_read_msg.bindValue(QSL(":account_id"), accountId()); + + if (query_read_msg.exec()) { + QList itemss; + + foreach (Feed *feed, items) { + feed->updateCounts(false); + itemss.append(feed); + } + + itemChanged(itemss); + requestReloadMessageList(read == RootItem::Read); + return true; + } + else { + return false; + } +} + QStringList ServiceRoot::textualFeedIds(const QList &feeds) const { QStringList stringy_ids; stringy_ids.reserve(feeds.size()); diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index 9426f3a5b..145b2a870 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -150,6 +150,8 @@ class ServiceRoot : public RootItem { virtual bool onAfterMessagesRestoredFromBin(RootItem *selected_item, const QList &messages); void completelyRemoveAllData(); + QStringList customIDSOfMessagesForItem(RootItem *item); + bool markFeedsReadUnread(QList items, ReadStatus read); // Obvious methods to wrap signals. void itemChanged(const QList &items); @@ -178,7 +180,6 @@ class ServiceRoot : public RootItem { void removeLeftOverMessages(); QStringList textualFeedIds(const QList &feeds) const; - QStringList customIDsOfMessages(const QList &changes); QStringList customIDsOfMessages(const QList &messages); diff --git a/src/services/owncloud/owncloudfeed.cpp b/src/services/owncloud/owncloudfeed.cpp index c3087deac..7580c8824 100755 --- a/src/services/owncloud/owncloudfeed.cpp +++ b/src/services/owncloud/owncloudfeed.cpp @@ -37,6 +37,22 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord &record) : Feed(NULL) { OwnCloudFeed::~OwnCloudFeed() { } +bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) { + QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this); + QNetworkReply::NetworkError response = serviceRoot()->network()->markMessagesRead(status, ids); + + if (response != QNetworkReply::NoError) { + return false; + } + else { + return getParentServiceRoot()->markFeedsReadUnread(QList() << this, status); + } +} + +bool OwnCloudFeed::cleanMessages(bool clear_only_read) { + return getParentServiceRoot()->cleanFeeds(QList() << this, clear_only_read); +} + OwnCloudServiceRoot *OwnCloudFeed::serviceRoot() const { return qobject_cast(getParentServiceRoot()); } diff --git a/src/services/owncloud/owncloudfeed.h b/src/services/owncloud/owncloudfeed.h index 74789af20..4c4fb5db1 100755 --- a/src/services/owncloud/owncloudfeed.h +++ b/src/services/owncloud/owncloudfeed.h @@ -31,6 +31,9 @@ class OwnCloudFeed : public Feed { explicit OwnCloudFeed(const QSqlRecord &record); virtual ~OwnCloudFeed(); + bool markAsReadUnread(ReadStatus status); + bool cleanMessages(bool clear_only_read); + OwnCloudServiceRoot *serviceRoot() const; int messageForeignKeyId() const; diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 66b75f869..512b534e3 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -128,7 +128,7 @@ bool TtRssFeed::deleteViaGui() { } bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) { - QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this); + QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this); TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread, status == RootItem::Unread ? UpdateArticle::SetToTrue : @@ -138,12 +138,12 @@ bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) { return false; } else { - return serviceRoot()->markFeedsReadUnread(QList() << this, status); + return getParentServiceRoot()->markFeedsReadUnread(QList() << this, status); } } bool TtRssFeed::cleanMessages(bool clear_only_read) { - return serviceRoot()->cleanFeeds(QList() << this, clear_only_read); + return getParentServiceRoot()->cleanFeeds(QList() << this, clear_only_read); } bool TtRssFeed::editItself(TtRssFeed *new_feed_data) { diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index 6e2db1597..182168a9a 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -205,7 +205,7 @@ bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, // NOTE: We just toggle it here, because we know, that there is only // toggling of starred status supported by RSS Guard right now and - // Tiny Tiny RSS API allows it, which is greate. + // Tiny Tiny RSS API allows it, which is great. TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(changes), UpdateArticle::Starred, UpdateArticle::Togggle); @@ -222,103 +222,6 @@ TtRssNetworkFactory *TtRssServiceRoot::network() const { return m_network; } -QStringList TtRssServiceRoot::customIDSOfMessagesForItem(RootItem *item) { - if (item->getParentServiceRoot() != this) { - // Not item from this account. - return QStringList(); - } - else { - QStringList list; - - switch (item->kind()) { - case RootItemKind::Category: { - foreach (RootItem *child, item->childItems()) { - list.append(customIDSOfMessagesForItem(child)); - } - - return list; - } - - case RootItemKind::ServiceRoot: { - QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - QSqlQuery query(database); - - query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")); - query.bindValue(QSL(":account_id"), accountId()); - query.exec(); - - while (query.next()) { - list.append(query.value(0).toString()); - } - - break; - } - - case RootItemKind::Bin: { - QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - QSqlQuery query(database); - - query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;")); - query.bindValue(QSL(":account_id"), accountId()); - query.exec(); - - while (query.next()) { - list.append(query.value(0).toString()); - } - - break; - } - - case RootItemKind::Feed: { - QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - QSqlQuery query(database); - - query.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;")); - query.bindValue(QSL(":account_id"), accountId()); - query.bindValue(QSL(":feed"), qobject_cast(item)->customId()); - query.exec(); - - while (query.next()) { - list.append(query.value(0).toString()); - } - - break; - } - - default: - break; - } - - return list; - } -} - -bool TtRssServiceRoot::markFeedsReadUnread(QList items, RootItem::ReadStatus read) { - QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - QSqlQuery query_read_msg(db_handle); - query_read_msg.setForwardOnly(true); - query_read_msg.prepare(QString("UPDATE Messages SET is_read = :read " - "WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0;").arg(textualFeedIds(items).join(QSL(", ")))); - - query_read_msg.bindValue(QSL(":read"), read == RootItem::Read ? 1 : 0); - - if (query_read_msg.exec()) { - QList itemss; - - foreach (Feed *feed, items) { - feed->updateCounts(false); - itemss.append(feed); - } - - itemChanged(itemss); - requestReloadMessageList(read == RootItem::Read); - return true; - } - else { - return false; - } -} - void TtRssServiceRoot::saveAccountDataToDatabase() { if (accountId() != NO_PARENT_CATEGORY) { // We are overwritting previously saved data. diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 128363762..9848225fa 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -55,10 +55,6 @@ class TtRssServiceRoot : public ServiceRoot { // Access to network. TtRssNetworkFactory *network() const; - // Returns list of custom IDS of all DB messages in given item. - QStringList customIDSOfMessagesForItem(RootItem *item); - - bool markFeedsReadUnread(QList items, ReadStatus read); void saveAccountDataToDatabase(); void updateTitle();