Experimental async msg state change support for TT-RSS.
This commit is contained in:
parent
8aaf0d1b5b
commit
858184b6ff
6 changed files with 49 additions and 50 deletions
|
@ -108,6 +108,11 @@ QString OwnCloudServiceRoot::code() const {
|
|||
return OwnCloudServiceEntryPoint().code();
|
||||
}
|
||||
|
||||
bool OwnCloudServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
|
||||
return ServiceRoot::markAsReadUnread(status);
|
||||
}
|
||||
|
||||
OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
||||
return m_network;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
|||
void start(bool freshly_activated);
|
||||
void stop();
|
||||
QString code() const;
|
||||
bool markAsReadUnread(ReadStatus status);
|
||||
|
||||
OwnCloudNetworkFactory *network() const;
|
||||
|
||||
|
|
|
@ -124,18 +124,8 @@ bool TtRssFeed::deleteViaGui() {
|
|||
}
|
||||
|
||||
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
|
||||
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
||||
status == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
UpdateArticle::SetToFalse);
|
||||
|
||||
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
|
||||
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
||||
|
|
|
@ -33,16 +33,6 @@ TtRssServiceRoot *TtRssRecycleBin::serviceRoot() {
|
|||
}
|
||||
|
||||
bool TtRssRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
||||
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
||||
status == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
UpdateArticle::SetToFalse);
|
||||
|
||||
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
|
||||
return RecycleBin::markAsReadUnread(status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
|
||||
TtRssServiceRoot::TtRssServiceRoot(RootItem *parent)
|
||||
: ServiceRoot(parent), m_recycleBin(new TtRssRecycleBin(this)),
|
||||
: ServiceRoot(parent), CacheForServiceRoot(), m_recycleBin(new TtRssRecycleBin(this)),
|
||||
m_actionSyncIn(nullptr), m_serviceMenu(QList<QAction*>()), m_network(new TtRssNetworkFactory()) {
|
||||
setIcon(TtRssServiceEntryPoint().icon());
|
||||
}
|
||||
|
@ -88,18 +88,8 @@ bool TtRssServiceRoot::deleteViaGui() {
|
|||
}
|
||||
|
||||
bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
QStringList ids = customIDSOfMessagesForItem(this);
|
||||
TtRssUpdateArticleResponse response = m_network->updateArticles(ids, UpdateArticle::Unread,
|
||||
status == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
UpdateArticle::SetToFalse);
|
||||
|
||||
if (m_network->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
|
||||
return ServiceRoot::markAsReadUnread(status);
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::supportsFeedAdding() const {
|
||||
|
@ -166,6 +156,37 @@ RecycleBin *TtRssServiceRoot::recycleBin() const {
|
|||
return m_recycleBin;
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::saveAllCachedData() {
|
||||
/*TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages),
|
||||
UpdateArticle::Unread,
|
||||
read == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
UpdateArticle::SetToFalse);
|
||||
|
||||
if (m_network->lastError() == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
QPair<QMap<RootItem::ReadStatus, QStringList>, QMap<RootItem::Importance, QStringList>> msgCache = takeMessageCache();
|
||||
QMapIterator<RootItem::ReadStatus, QStringList> i(msgCache.first);
|
||||
|
||||
// Save the actual data read/unread.
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
auto key = i.key();
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->updateArticles(ids,
|
||||
UpdateArticle::Unread,
|
||||
key == RootItem::Unread ? UpdateArticle::SetToTrue : UpdateArticle::SetToFalse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> TtRssServiceRoot::serviceMenu() {
|
||||
if (m_serviceMenu.isEmpty()) {
|
||||
m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Sync in"), this);
|
||||
|
@ -180,18 +201,8 @@ QList<QAction*> TtRssServiceRoot::serviceMenu() {
|
|||
bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
|
||||
Q_UNUSED(selected_item)
|
||||
|
||||
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages),
|
||||
UpdateArticle::Unread,
|
||||
read == RootItem::Unread ?
|
||||
UpdateArticle::SetToTrue :
|
||||
UpdateArticle::SetToFalse);
|
||||
|
||||
if (m_network->lastError() == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
|
||||
addMessageStatesToCache(customIDsOfMessages(messages), read);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define TTRSSSERVICEROOT_H
|
||||
|
||||
#include "services/abstract/serviceroot.h"
|
||||
#include "services/abstract/cacheforserviceroot.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
@ -28,7 +29,7 @@ class TtRssFeed;
|
|||
class TtRssNetworkFactory;
|
||||
class TtRssRecycleBin;
|
||||
|
||||
class TtRssServiceRoot : public ServiceRoot {
|
||||
class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -48,6 +49,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||
QVariant data(int column, int role) const;
|
||||
QList<QAction*> serviceMenu();
|
||||
RecycleBin *recycleBin() const;
|
||||
void saveAllCachedData();
|
||||
|
||||
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes);
|
||||
|
|
Loading…
Add table
Reference in a new issue