File indexing completed on 2025-01-05 04:29:53

0001 /**
0002  * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "subscriptionrequest.h"
0008 
0009 #include <QJsonArray>
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 #include <QNetworkReply>
0013 #include <QString>
0014 #include <QStringList>
0015 #include <QUrl>
0016 
0017 #include "synclogging.h"
0018 
0019 SubscriptionRequest::SubscriptionRequest(SyncUtils::Provider provider, QNetworkReply *reply, QObject *parent)
0020     : GenericRequest(provider, reply, parent)
0021 {
0022 }
0023 
0024 QStringList SubscriptionRequest::addList() const
0025 {
0026     return m_add;
0027 }
0028 
0029 QStringList SubscriptionRequest::removeList() const
0030 {
0031     return m_remove;
0032 }
0033 
0034 qulonglong SubscriptionRequest::timestamp() const
0035 {
0036     return m_timestamp;
0037 }
0038 
0039 void SubscriptionRequest::processResults()
0040 {
0041     if (m_reply->error()) {
0042         m_error = m_reply->error();
0043         m_errorString = m_reply->errorString();
0044         qCDebug(kastsSync) << "m_reply error" << m_reply->errorString();
0045     } else {
0046         QJsonParseError *error = nullptr;
0047         QJsonDocument data = QJsonDocument::fromJson(m_reply->readAll(), error);
0048         if (error) {
0049             qCDebug(kastsSync) << "parse error" << error->errorString();
0050             m_error = 1;
0051             m_errorString = error->errorString();
0052         } else {
0053             for (auto jsonFeed : data.object().value(QStringLiteral("add")).toArray()) {
0054                 m_add += cleanupUrl(jsonFeed.toString());
0055             }
0056             for (auto jsonFeed : data.object().value(QStringLiteral("remove")).toArray()) {
0057                 m_remove += cleanupUrl(jsonFeed.toString());
0058             }
0059             m_timestamp = data.object().value(QStringLiteral("timestamp")).toInt();
0060         }
0061     }
0062     Q_EMIT finished();
0063     m_reply->deleteLater();
0064     deleteLater();
0065 }