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();
|
return OwnCloudServiceEntryPoint().code();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OwnCloudServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
|
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
|
||||||
|
return ServiceRoot::markAsReadUnread(status);
|
||||||
|
}
|
||||||
|
|
||||||
OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
||||||
return m_network;
|
return m_network;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
void start(bool freshly_activated);
|
void start(bool freshly_activated);
|
||||||
void stop();
|
void stop();
|
||||||
QString code() const;
|
QString code() const;
|
||||||
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
|
||||||
OwnCloudNetworkFactory *network() const;
|
OwnCloudNetworkFactory *network() const;
|
||||||
|
|
||||||
|
|
|
@ -124,18 +124,8 @@ bool TtRssFeed::deleteViaGui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
|
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
|
||||||
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
|
||||||
status == RootItem::Unread ?
|
|
||||||
UpdateArticle::SetToTrue :
|
|
||||||
UpdateArticle::SetToFalse);
|
|
||||||
|
|
||||||
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getParentServiceRoot()->markFeedsReadUnread(QList<Feed*>() << this, status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
||||||
|
|
|
@ -33,16 +33,6 @@ TtRssServiceRoot *TtRssRecycleBin::serviceRoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
bool TtRssRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
serviceRoot()->addMessageStatesToCache(getParentServiceRoot()->customIDSOfMessagesForItem(this), status);
|
||||||
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
return RecycleBin::markAsReadUnread(status);
|
||||||
status == RootItem::Unread ?
|
|
||||||
UpdateArticle::SetToTrue :
|
|
||||||
UpdateArticle::SetToFalse);
|
|
||||||
|
|
||||||
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return RecycleBin::markAsReadUnread(status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
|
|
||||||
TtRssServiceRoot::TtRssServiceRoot(RootItem *parent)
|
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()) {
|
m_actionSyncIn(nullptr), m_serviceMenu(QList<QAction*>()), m_network(new TtRssNetworkFactory()) {
|
||||||
setIcon(TtRssServiceEntryPoint().icon());
|
setIcon(TtRssServiceEntryPoint().icon());
|
||||||
}
|
}
|
||||||
|
@ -88,18 +88,8 @@ bool TtRssServiceRoot::deleteViaGui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
QStringList ids = customIDSOfMessagesForItem(this);
|
addMessageStatesToCache(customIDSOfMessagesForItem(this), status);
|
||||||
TtRssUpdateArticleResponse response = m_network->updateArticles(ids, UpdateArticle::Unread,
|
return ServiceRoot::markAsReadUnread(status);
|
||||||
status == RootItem::Unread ?
|
|
||||||
UpdateArticle::SetToTrue :
|
|
||||||
UpdateArticle::SetToFalse);
|
|
||||||
|
|
||||||
if (m_network->lastError() != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return ServiceRoot::markAsReadUnread(status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::supportsFeedAdding() const {
|
bool TtRssServiceRoot::supportsFeedAdding() const {
|
||||||
|
@ -166,6 +156,37 @@ RecycleBin *TtRssServiceRoot::recycleBin() const {
|
||||||
return m_recycleBin;
|
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() {
|
QList<QAction*> TtRssServiceRoot::serviceMenu() {
|
||||||
if (m_serviceMenu.isEmpty()) {
|
if (m_serviceMenu.isEmpty()) {
|
||||||
m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Sync in"), this);
|
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) {
|
bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, RootItem::ReadStatus read) {
|
||||||
Q_UNUSED(selected_item)
|
Q_UNUSED(selected_item)
|
||||||
|
|
||||||
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(messages),
|
addMessageStatesToCache(customIDsOfMessages(messages), read);
|
||||||
UpdateArticle::Unread,
|
return true;
|
||||||
read == RootItem::Unread ?
|
|
||||||
UpdateArticle::SetToTrue :
|
|
||||||
UpdateArticle::SetToFalse);
|
|
||||||
|
|
||||||
if (m_network->lastError() == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes) {
|
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#define TTRSSSERVICEROOT_H
|
#define TTRSSSERVICEROOT_H
|
||||||
|
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
#include "services/abstract/cacheforserviceroot.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ class TtRssFeed;
|
||||||
class TtRssNetworkFactory;
|
class TtRssNetworkFactory;
|
||||||
class TtRssRecycleBin;
|
class TtRssRecycleBin;
|
||||||
|
|
||||||
class TtRssServiceRoot : public ServiceRoot {
|
class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -48,6 +49,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
QList<QAction*> serviceMenu();
|
QList<QAction*> serviceMenu();
|
||||||
RecycleBin *recycleBin() const;
|
RecycleBin *recycleBin() const;
|
||||||
|
void saveAllCachedData();
|
||||||
|
|
||||||
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||||
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes);
|
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<ImportanceChange> &changes);
|
||||||
|
|
Loading…
Add table
Reference in a new issue