diff --git a/CMakeLists.txt b/CMakeLists.txt index aaef3c5a2..313bfecdb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -560,7 +560,7 @@ set(APP_HEADERS # TT-RSS service headers. src/services/tt-rss/ttrssserviceroot.h - src/services/tt-rss/ttrssrecyclebin.h + src/services/tt-rss/ttrssrecyclebin.h; src/services/tt-rss/ttrssfeed.h src/services/tt-rss/ttrsscategory.h src/services/tt-rss/gui/formeditaccount.h diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 455b9e4f8..d83bfa2d4 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -60,6 +60,38 @@ bool ServiceRoot::deleteViaGui() { return data_removed; } +bool ServiceRoot::markAsReadUnread(RootItem::ReadStatus status) { + QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + + if (!db_handle.transaction()) { + qWarning("Starting transaction for feeds read change."); + return false; + } + + QSqlQuery query_read_msg(db_handle); + query_read_msg.setForwardOnly(true); + query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE is_pdeleted = 0 AND account_id = :account_id;")); + + query_read_msg.bindValue(QSL(":account_id"), accountId()); + query_read_msg.bindValue(QSL(":read"), status == RootItem::Read ? 1 : 0); + + if (!query_read_msg.exec()) { + qDebug("Query execution for feeds read change failed."); + db_handle.rollback(); + } + + // Commit changes. + if (db_handle.commit()) { + updateCounts(false); + itemChanged(getSubTree()); + requestReloadMessageList(status == RootItem::Read); + return true; + } + else { + return db_handle.rollback(); + } +} + QList ServiceRoot::undeletedMessages() const { QList messages; int account_id = accountId(); diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index aca20bf3d..c4c3a0455 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -50,6 +50,8 @@ class ServiceRoot : public RootItem { bool deleteViaGui(); + bool markAsReadUnread(ReadStatus status); + // Returns list of specific actions for "Add new item" main window menu. // So typical list of returned actions could look like: // a) Add new feed diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 7a51f291b..512288582 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -118,35 +118,7 @@ bool StandardServiceRoot::deleteViaGui() { } bool StandardServiceRoot::markAsReadUnread(RootItem::ReadStatus status) { - QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - - if (!db_handle.transaction()) { - qWarning("Starting transaction for feeds read change."); - return false; - } - - QSqlQuery query_read_msg(db_handle); - query_read_msg.setForwardOnly(true); - query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE is_pdeleted = 0 AND account_id = :account_id;")); - - query_read_msg.bindValue(QSL(":account_id"), accountId()); - query_read_msg.bindValue(QSL(":read"), status == RootItem::Read ? 1 : 0); - - if (!query_read_msg.exec()) { - qDebug("Query execution for feeds read change failed."); - db_handle.rollback(); - } - - // Commit changes. - if (db_handle.commit()) { - updateCounts(false); - itemChanged(getSubTree()); - requestReloadMessageList(status == RootItem::Read); - return true; - } - else { - return db_handle.rollback(); - } + return ServiceRoot::markAsReadUnread(status); } QVariant StandardServiceRoot::data(int column, int role) const { diff --git a/src/services/tt-rss/ttrsscategory.h b/src/services/tt-rss/ttrsscategory.h index 54e573448..d2355f8e2 100755 --- a/src/services/tt-rss/ttrsscategory.h +++ b/src/services/tt-rss/ttrsscategory.h @@ -31,8 +31,6 @@ class TtRssCategory : public Category { explicit TtRssCategory(const QSqlRecord &record); virtual ~TtRssCategory(); - - int customId() const; void setCustomId(int custom_id); diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 76a4b1ea8..a8b228522 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -144,6 +144,24 @@ QList TtRssFeed::undeletedMessages() const { return messages; } +bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) { + QNetworkReply::NetworkError error; + QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this); + TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread, + status == RootItem::Unread ? + UpdateArticle::SetToTrue : + UpdateArticle::SetToFalse, + error); + + if (error != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) { + return false; + } + else { + // TODO: todo + //return Feed::markAsReadUnread(status); + } +} + int TtRssFeed::customId() const { return m_customId; } diff --git a/src/services/tt-rss/ttrssfeed.h b/src/services/tt-rss/ttrssfeed.h index ccd78d386..c49501049 100755 --- a/src/services/tt-rss/ttrssfeed.h +++ b/src/services/tt-rss/ttrssfeed.h @@ -43,6 +43,8 @@ class TtRssFeed : public Feed { int update(); QList undeletedMessages() const; + bool markAsReadUnread(ReadStatus status); + int customId() const; void setCustomId(int custom_id); diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index ca6061a64..4ae0c6e97 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -86,6 +86,23 @@ bool TtRssServiceRoot::deleteViaGui() { } } +bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) { + QNetworkReply::NetworkError error; + QStringList ids = customIDSOfMessagesForItem(this); + TtRssUpdateArticleResponse response = m_network->updateArticles(ids, UpdateArticle::Unread, + status == RootItem::Unread ? + UpdateArticle::SetToTrue : + UpdateArticle::SetToFalse, + error); + + if (error != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) { + return false; + } + else { + return ServiceRoot::markAsReadUnread(status); + } +} + bool TtRssServiceRoot::canBeEdited() { return true; } diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 6f594ab7f..6dd03a2a7 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -44,6 +44,8 @@ class TtRssServiceRoot : public ServiceRoot { bool editViaGui(); bool deleteViaGui(); + bool markAsReadUnread(ReadStatus status); + QVariant data(int column, int role) const; QList addItemMenu();