Refactored common code.
This commit is contained in:
parent
27faa7dfc5
commit
a643307508
9 changed files with 67 additions and 89 deletions
|
@ -24,10 +24,6 @@
|
|||
#include "services/inoreader/inoreaderentrypoint.h"
|
||||
#endif
|
||||
|
||||
#include "services/owncloud/owncloudserviceentrypoint.h"
|
||||
#include "services/standard/standardserviceentrypoint.h"
|
||||
#include "services/tt-rss/ttrssserviceentrypoint.h"
|
||||
|
||||
#include "core/feeddownloader.h"
|
||||
#include "core/feedsmodel.h"
|
||||
#include "core/feedsproxymodel.h"
|
||||
|
@ -36,6 +32,10 @@
|
|||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasecleaner.h"
|
||||
#include "miscellaneous/mutex.h"
|
||||
#include "services/abstract/cacheforserviceroot.h"
|
||||
#include "services/owncloud/owncloudserviceentrypoint.h"
|
||||
#include "services/standard/standardserviceentrypoint.h"
|
||||
#include "services/tt-rss/ttrssserviceentrypoint.h"
|
||||
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QThread>
|
||||
|
@ -224,8 +224,11 @@ void FeedReader::executeNextAutoUpdate() {
|
|||
|
||||
void FeedReader::checkServicesForAsyncOperations() {
|
||||
foreach (ServiceRoot* service, m_feedsModel->serviceRoots()) {
|
||||
// Store any cached data.
|
||||
service->saveAllCachedData();
|
||||
auto cache = dynamic_cast<CacheForServiceRoot*>(service);
|
||||
|
||||
if (cache != nullptr) {
|
||||
cache->saveAllCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
asyncCacheSaveFinished();
|
||||
|
|
|
@ -196,7 +196,12 @@ void Feed::run() {
|
|||
<< QThread::currentThreadId() << "\'.";
|
||||
|
||||
// Save all cached data first.
|
||||
getParentServiceRoot()->saveAllCachedData();
|
||||
auto cache = dynamic_cast<CacheForServiceRoot*>(getParentServiceRoot());
|
||||
|
||||
if (cache != nullptr) {
|
||||
cache->saveAllCachedData();
|
||||
}
|
||||
|
||||
bool error_during_obtaining;
|
||||
|
||||
QList<Message> msgs = obtainNewMessages(&error_during_obtaining);
|
||||
|
|
|
@ -203,8 +203,6 @@ QList<Message> ServiceRoot::undeletedMessages() const {
|
|||
return DatabaseQueries::getUndeletedMessagesForAccount(database, accountId());
|
||||
}
|
||||
|
||||
void ServiceRoot::saveAllCachedData() {}
|
||||
|
||||
void ServiceRoot::itemChanged(const QList<RootItem*>& items) {
|
||||
emit dataChanged(items);
|
||||
}
|
||||
|
@ -447,9 +445,14 @@ bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) {
|
|||
}
|
||||
|
||||
bool ServiceRoot::onBeforeSetMessagesRead(RootItem* selected_item, const QList<Message>& messages, RootItem::ReadStatus read) {
|
||||
Q_UNUSED(messages)
|
||||
Q_UNUSED(read)
|
||||
Q_UNUSED(selected_item)
|
||||
|
||||
auto cache = dynamic_cast<CacheForServiceRoot*>(this);
|
||||
|
||||
if (cache != nullptr) {
|
||||
cache->addMessageStatesToCache(customIDsOfMessages(messages), read);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -463,7 +466,32 @@ bool ServiceRoot::onAfterSetMessagesRead(RootItem* selected_item, const QList<Me
|
|||
|
||||
bool ServiceRoot::onBeforeSwitchMessageImportance(RootItem* selected_item, const QList<ImportanceChange>& changes) {
|
||||
Q_UNUSED(selected_item)
|
||||
Q_UNUSED(changes)
|
||||
|
||||
auto cache = dynamic_cast<CacheForServiceRoot*>(this);
|
||||
|
||||
if (cache != nullptr) {
|
||||
// Now, we need to separate the changes because of ownCloud API limitations.
|
||||
QList<Message> mark_starred_msgs;
|
||||
QList<Message> mark_unstarred_msgs;
|
||||
|
||||
foreach (const ImportanceChange& pair, changes) {
|
||||
if (pair.second == RootItem::Important) {
|
||||
mark_starred_msgs.append(pair.first);
|
||||
}
|
||||
else {
|
||||
mark_unstarred_msgs.append(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mark_starred_msgs.isEmpty()) {
|
||||
cache->addMessageStatesToCache(mark_starred_msgs, RootItem::Important);
|
||||
}
|
||||
|
||||
if (!mark_unstarred_msgs.isEmpty()) {
|
||||
cache->addMessageStatesToCache(mark_unstarred_msgs, RootItem::NotImportant);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,6 @@ class ServiceRoot : public RootItem {
|
|||
// user explicitly deletes existing service instance.
|
||||
virtual void start(bool freshly_activated) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void saveAllCachedData();
|
||||
|
||||
// Account ID corresponds with DB attribute Accounts (id).
|
||||
int accountId() const;
|
||||
|
|
|
@ -151,7 +151,25 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, bool*
|
|||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {}
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {
|
||||
QString target_url = INOREADER_API_EDIT_TAG;
|
||||
|
||||
if (status == RootItem::ReadStatus::Read) {
|
||||
target_url += QString("?a=user/-/") + INOREADER_STATE_READ + "&";
|
||||
}
|
||||
else {
|
||||
target_url += QString("?r=user/-/") + INOREADER_STATE_READ + "&";
|
||||
}
|
||||
|
||||
QStringList trimmed_ids;
|
||||
|
||||
foreach (const QString& id, custom_ids) {
|
||||
trimmed_ids.append(QString("i=") + id);
|
||||
}
|
||||
|
||||
QString full_url = target_url + trimmed_ids.join(QL1C('&'));
|
||||
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids) {}
|
||||
|
||||
|
|
|
@ -143,42 +143,6 @@ void OwnCloudServiceRoot::saveAllCachedData() {
|
|||
}
|
||||
}
|
||||
|
||||
bool OwnCloudServiceRoot::onBeforeSetMessagesRead(RootItem* selected_item,
|
||||
const QList<Message>& messages,
|
||||
RootItem::ReadStatus read) {
|
||||
Q_UNUSED(selected_item)
|
||||
addMessageStatesToCache(customIDsOfMessages(messages), read);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OwnCloudServiceRoot::onBeforeSwitchMessageImportance(RootItem* selected_item,
|
||||
const QList<ImportanceChange>& changes) {
|
||||
Q_UNUSED(selected_item)
|
||||
|
||||
// Now, we need to separate the changes because of ownCloud API limitations.
|
||||
QList<Message> mark_starred_msgs;
|
||||
QList<Message> mark_unstarred_msgs;
|
||||
|
||||
foreach (const ImportanceChange& pair, changes) {
|
||||
if (pair.second == RootItem::Important) {
|
||||
mark_starred_msgs.append(pair.first);
|
||||
}
|
||||
else {
|
||||
mark_unstarred_msgs.append(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mark_starred_msgs.isEmpty()) {
|
||||
addMessageStatesToCache(mark_starred_msgs, RootItem::Important);
|
||||
}
|
||||
|
||||
if (!mark_unstarred_msgs.isEmpty()) {
|
||||
addMessageStatesToCache(mark_unstarred_msgs, RootItem::NotImportant);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OwnCloudServiceRoot::updateTitle() {
|
||||
setTitle(m_network->authUsername() + QSL(" (Nextcloud News)"));
|
||||
}
|
||||
|
|
|
@ -47,9 +47,6 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
|||
QString code() const;
|
||||
OwnCloudNetworkFactory* network() const;
|
||||
|
||||
bool onBeforeSetMessagesRead(RootItem* selected_item, const QList<Message>& messages, ReadStatus read);
|
||||
bool onBeforeSwitchMessageImportance(RootItem* selected_item, const QList<ImportanceChange>& changes);
|
||||
|
||||
void updateTitle();
|
||||
void saveAccountDataToDatabase();
|
||||
|
||||
|
|
|
@ -193,39 +193,6 @@ QList<QAction*> TtRssServiceRoot::serviceMenu() {
|
|||
return m_serviceMenu;
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem* selected_item, const QList<Message>& messages, RootItem::ReadStatus read) {
|
||||
Q_UNUSED(selected_item)
|
||||
addMessageStatesToCache(customIDsOfMessages(messages), read);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem* selected_item, const QList<ImportanceChange>& changes) {
|
||||
Q_UNUSED(selected_item)
|
||||
|
||||
// Now, we need to separate the changes because of ownCloud API limitations.
|
||||
QList<Message> mark_starred_msgs;
|
||||
QList<Message> mark_unstarred_msgs;
|
||||
|
||||
foreach (const ImportanceChange& pair, changes) {
|
||||
if (pair.second == RootItem::Important) {
|
||||
mark_starred_msgs.append(pair.first);
|
||||
}
|
||||
else {
|
||||
mark_unstarred_msgs.append(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mark_starred_msgs.isEmpty()) {
|
||||
addMessageStatesToCache(mark_starred_msgs, RootItem::Important);
|
||||
}
|
||||
|
||||
if (!mark_unstarred_msgs.isEmpty()) {
|
||||
addMessageStatesToCache(mark_unstarred_msgs, RootItem::NotImportant);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TtRssNetworkFactory* TtRssServiceRoot::network() const {
|
||||
return m_network;
|
||||
}
|
||||
|
|
|
@ -49,9 +49,6 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
|||
|
||||
void saveAllCachedData();
|
||||
|
||||
bool onBeforeSetMessagesRead(RootItem* selected_item, const QList<Message>& messages, ReadStatus read);
|
||||
bool onBeforeSwitchMessageImportance(RootItem* selected_item, const QList<ImportanceChange>& changes);
|
||||
|
||||
// Access to network.
|
||||
TtRssNetworkFactory* network() const;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue