reedah tested with greader plugin.
This commit is contained in:
parent
9562c5f9ed
commit
f24f03e6df
@ -1812,32 +1812,6 @@ bool DatabaseQueries::deleteOwnCloudAccount(const QSqlDatabase& db, int account_
|
||||
return q.exec();
|
||||
}
|
||||
|
||||
bool DatabaseQueries::overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password,
|
||||
const QString& url, int batch_size, int account_id) {
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("UPDATE GoogleReaderApiAccounts "
|
||||
"SET username = :username, password = :password, url = :url, "
|
||||
"msg_limit = :msg_limit "
|
||||
"WHERE id = :id;");
|
||||
query.bindValue(QSL(":username"), username);
|
||||
query.bindValue(QSL(":password"), TextFactory::encrypt(password));
|
||||
query.bindValue(QSL(":url"), url);
|
||||
query.bindValue(QSL(":id"), account_id);
|
||||
query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GREADER_UNLIMITED_BATCH_SIZE : batch_size);
|
||||
|
||||
if (query.exec()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qWarningNN << LOGSEC_GREADER
|
||||
<< "Updating account failed: '"
|
||||
<< query.lastError().text()
|
||||
<< "'.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QString& username, const QString& password,
|
||||
const QString& url, bool force_server_side_feed_update, int batch_size,
|
||||
bool download_only_unread_messages, int account_id) {
|
||||
@ -1893,6 +1867,33 @@ bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_ass
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseQueries::overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password,
|
||||
GreaderServiceRoot::Service service, const QString& url,
|
||||
int batch_size, int account_id) {
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("UPDATE GoogleReaderApiAccounts "
|
||||
"SET username = :username, password = :password, url = :url, type = :service, msg_limit = :msg_limit "
|
||||
"WHERE id = :id;");
|
||||
query.bindValue(QSL(":username"), username);
|
||||
query.bindValue(QSL(":password"), TextFactory::encrypt(password));
|
||||
query.bindValue(QSL(":url"), url);
|
||||
query.bindValue(QSL(":service"), int(service));
|
||||
query.bindValue(QSL(":id"), account_id);
|
||||
query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GREADER_UNLIMITED_BATCH_SIZE : batch_size);
|
||||
|
||||
if (query.exec()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qWarningNN << LOGSEC_GREADER
|
||||
<< "Updating account failed: '"
|
||||
<< query.lastError().text()
|
||||
<< "'.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseQueries::createOwnCloudAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
|
||||
const QString& password, const QString& url,
|
||||
bool force_server_side_feed_update,
|
||||
|
@ -157,7 +157,8 @@ class DatabaseQueries {
|
||||
const QString& password, GreaderServiceRoot::Service service,
|
||||
const QString& url, int batch_size);
|
||||
static bool overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password,
|
||||
const QString& url, int batch_size, int account_id);
|
||||
GreaderServiceRoot::Service service, const QString& url, int batch_size,
|
||||
int account_id);
|
||||
|
||||
// Nextcloud account.
|
||||
static QList<ServiceRoot*> getOwnCloudAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
||||
|
@ -18,10 +18,10 @@
|
||||
#define GREADER_API_SUBSCRIPTION_LIST "reader/api/0/subscription/list?output=json"
|
||||
#define GREADER_API_STREAM_CONTENTS "reader/api/0/stream/contents/%1?output=json&n=%2"
|
||||
#define GREADER_API_EDIT_TAG "reader/api/0/edit-tag"
|
||||
#define GREADER_API_TOKEN "reader/api/0/token"
|
||||
|
||||
// Misc.
|
||||
#define GREADER_API_EDIT_TAG_BATCH 200
|
||||
#define GREADER_API_ANY_LABEL "user/-/label"
|
||||
|
||||
// The Old Reader.
|
||||
#define TOR_SPONSORED_STREAM_ID "tor/sponsored"
|
||||
|
@ -62,6 +62,10 @@ QNetworkReply::NetworkError GreaderNetwork::editLabels(const QString& state,
|
||||
|
||||
args += working_subset.join(QL1C('&'));
|
||||
|
||||
if (m_service == GreaderServiceRoot::Service::Reedah) {
|
||||
args += QSL("&T=%1").arg(m_authToken);
|
||||
}
|
||||
|
||||
// We send this batch.
|
||||
QByteArray output;
|
||||
auto result_edit = NetworkFactory::performNetworkOperation(full_url,
|
||||
@ -103,7 +107,9 @@ QNetworkReply::NetworkError GreaderNetwork::markMessagesStarred(RootItem::Import
|
||||
QList<Message> GreaderNetwork::streamContents(ServiceRoot* root, const QString& stream_id,
|
||||
Feed::Status& error, const QNetworkProxy& proxy) {
|
||||
QString full_url = generateFullUrl(Operations::StreamContents).arg(stream_id,
|
||||
QString::number(batchSize()));
|
||||
QString::number(batchSize() <= 0
|
||||
? 2000000
|
||||
: batchSize()));
|
||||
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
|
||||
if (!ensureLogin(proxy)) {
|
||||
@ -190,7 +196,8 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
QList<RootItem*> lbls;
|
||||
QJsonArray json;
|
||||
|
||||
if (m_service == GreaderServiceRoot::Service::Bazqux) {
|
||||
if (m_service == GreaderServiceRoot::Service::Bazqux ||
|
||||
m_service == GreaderServiceRoot::Service::Reedah) {
|
||||
// We need to process subscription list first and extract categories.
|
||||
json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray();
|
||||
|
||||
@ -223,9 +230,9 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
|
||||
if ((label["type"].toString() == QL1S("folder")) ||
|
||||
(m_service == GreaderServiceRoot::Service::TheOldReader &&
|
||||
label_id.startsWith(GREADER_API_ANY_LABEL))) {
|
||||
label_id.contains(QSL("/label/")))) {
|
||||
|
||||
// We have label (not "state").
|
||||
// We have category (not "state" or "tag" or "label").
|
||||
auto* category = new Category();
|
||||
|
||||
category->setDescription(label["htmlUrl"].toString());
|
||||
@ -242,7 +249,8 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
new_lbl->setCustomId(label_id);
|
||||
lbls.append(new_lbl);
|
||||
}
|
||||
else if (m_service == GreaderServiceRoot::Service::Bazqux &&
|
||||
else if ((m_service == GreaderServiceRoot::Service::Bazqux ||
|
||||
m_service == GreaderServiceRoot::Service::Reedah) &&
|
||||
label_id.contains(QSL("/label/"))) {
|
||||
if (!cats.contains(label_id)) {
|
||||
// This stream is not a category, it is label, bitches!
|
||||
@ -357,7 +365,7 @@ QNetworkReply::NetworkError GreaderNetwork::clientLogin(const QNetworkProxy& pro
|
||||
}
|
||||
}
|
||||
|
||||
QRegularExpression exp("^(unused|none|null)$");
|
||||
QRegularExpression exp("^(NA|unused|none|null)$");
|
||||
|
||||
if (exp.match(m_authSid).hasMatch()) {
|
||||
m_authSid = QString();
|
||||
@ -371,6 +379,29 @@ QNetworkReply::NetworkError GreaderNetwork::clientLogin(const QNetworkProxy& pro
|
||||
clearCredentials();
|
||||
return QNetworkReply::NetworkError::InternalServerError;
|
||||
}
|
||||
|
||||
if (m_service == GreaderServiceRoot::Service::Reedah) {
|
||||
// We need "T=" token for editing.
|
||||
full_url = generateFullUrl(Operations::Token);
|
||||
|
||||
network_result = NetworkFactory::performNetworkOperation(full_url,
|
||||
timeout,
|
||||
args,
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
{ authHeader() },
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
proxy);
|
||||
|
||||
if (network_result.first == QNetworkReply::NetworkError::NoError) {
|
||||
m_authToken = output;
|
||||
}
|
||||
else {
|
||||
clearCredentials();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return network_result.first;
|
||||
@ -416,11 +447,14 @@ QString GreaderNetwork::serviceToString(GreaderServiceRoot::Service service) {
|
||||
case GreaderServiceRoot::Service::Bazqux:
|
||||
return QSL("Bazqux");
|
||||
|
||||
case GreaderServiceRoot::Service::Reedah:
|
||||
return QSL("Reedah");
|
||||
|
||||
case GreaderServiceRoot::Service::TheOldReader:
|
||||
return QSL("The Old Reader");
|
||||
|
||||
default:
|
||||
return tr("Unknown service");
|
||||
return tr("Other services");
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,7 +568,7 @@ void GreaderNetwork::setBatchSize(int batch_size) {
|
||||
}
|
||||
|
||||
void GreaderNetwork::clearCredentials() {
|
||||
m_authAuth = m_authSid = QString();
|
||||
m_authAuth = m_authSid = m_authToken = QString();
|
||||
}
|
||||
|
||||
QString GreaderNetwork::sanitizedBaseUrl() const {
|
||||
@ -561,6 +595,9 @@ QString GreaderNetwork::generateFullUrl(GreaderNetwork::Operations operation) co
|
||||
case Operations::ClientLogin:
|
||||
return sanitizedBaseUrl() + GREADER_API_CLIENT_LOGIN;
|
||||
|
||||
case Operations::Token:
|
||||
return sanitizedBaseUrl() + GREADER_API_TOKEN;
|
||||
|
||||
case Operations::TagList:
|
||||
return sanitizedBaseUrl() + GREADER_API_TAG_LIST;
|
||||
|
||||
|
@ -18,7 +18,8 @@ class GreaderNetwork : public QObject {
|
||||
TagList,
|
||||
SubscriptionList,
|
||||
StreamContents,
|
||||
EditTag
|
||||
EditTag,
|
||||
Token
|
||||
};
|
||||
|
||||
explicit GreaderNetwork(QObject* parent = nullptr);
|
||||
@ -84,6 +85,7 @@ class GreaderNetwork : public QObject {
|
||||
int m_batchSize;
|
||||
QString m_authSid;
|
||||
QString m_authAuth;
|
||||
QString m_authToken;
|
||||
};
|
||||
|
||||
#endif // GREADERNETWORK_H
|
||||
|
@ -168,8 +168,9 @@ void GreaderServiceRoot::saveAccountDataToDatabase(bool creating_new) {
|
||||
|
||||
if (!creating_new) {
|
||||
if (DatabaseQueries::overwriteGreaderAccount(database, m_network->username(),
|
||||
m_network->password(), m_network->baseUrl(),
|
||||
m_network->batchSize(), accountId())) {
|
||||
m_network->password(), m_network->service(),
|
||||
m_network->baseUrl(), m_network->batchSize(),
|
||||
accountId())) {
|
||||
updateTitleIcon();
|
||||
itemChanged(QList<RootItem*>() << this);
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ class GreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||
enum class Service {
|
||||
FreshRss = 1,
|
||||
TheOldReader = 2,
|
||||
Bazqux = 4
|
||||
Bazqux = 4,
|
||||
Reedah = 8,
|
||||
Other = 1024
|
||||
};
|
||||
|
||||
explicit GreaderServiceRoot(RootItem* parent = nullptr);
|
||||
|
@ -13,7 +13,9 @@ GreaderAccountDetails::GreaderAccountDetails(QWidget* parent) : QWidget(parent)
|
||||
|
||||
for (auto serv : { GreaderServiceRoot::Service::Bazqux,
|
||||
GreaderServiceRoot::Service::FreshRss,
|
||||
GreaderServiceRoot::Service::TheOldReader }) {
|
||||
GreaderServiceRoot::Service::Reedah,
|
||||
GreaderServiceRoot::Service::TheOldReader,
|
||||
GreaderServiceRoot::Service::Other }) {
|
||||
m_ui.m_cmbService->addItem(GreaderNetwork::serviceToString(serv), QVariant::fromValue(serv));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user