IconJob: Send request through the accounts NAS

This helps tracking requests on the server

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
This commit is contained in:
Felix Weilbach 2021-11-09 11:58:33 +01:00
parent db337c4457
commit 3e368ee4df
4 changed files with 15 additions and 15 deletions

View file

@ -113,7 +113,7 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
a._icon = json.value("icon").toString();
if (!a._icon.isEmpty()) {
auto *iconJob = new IconJob(QUrl(a._icon));
auto *iconJob = new IconJob(_accountState->account(), QUrl(a._icon));
iconJob->setProperty("activityId", a._id);
connect(iconJob, &IconJob::jobFinished, this, &ServerNotificationHandler::slotIconDownloaded);
}

View file

@ -16,22 +16,23 @@
namespace OCC {
IconJob::IconJob(const QUrl &url, QObject *parent) :
QObject(parent)
IconJob::IconJob(AccountPtr account, const QUrl &url, QObject *parent)
: QObject(parent)
{
connect(&_accessManager, &QNetworkAccessManager::finished,
this, &IconJob::finished);
QNetworkRequest request(url);
#if (QT_VERSION >= 0x050600)
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
#endif
_accessManager.get(request);
const auto reply = account->sendRawRequest(QByteArrayLiteral("GET"), url, request);
connect(reply, &QNetworkReply::finished, this, &IconJob::finished);
}
void IconJob::finished(QNetworkReply *reply)
void IconJob::finished()
{
reply->deleteLater();
const auto reply = qobject_cast<QNetworkReply *>(sender());
if (!reply) {
return;
}
deleteLater();
const auto networkError = reply->error();

View file

@ -15,6 +15,8 @@
#ifndef ICONJOB_H
#define ICONJOB_H
#include "account.h"
#include "accountfwd.h"
#include "owncloudlib.h"
#include <QObject>
@ -33,17 +35,14 @@ class OWNCLOUDSYNC_EXPORT IconJob : public QObject
{
Q_OBJECT
public:
explicit IconJob(const QUrl &url, QObject *parent = nullptr);
explicit IconJob(AccountPtr account, const QUrl &url, QObject *parent = nullptr);
signals:
void jobFinished(QByteArray iconData);
void error(QNetworkReply::NetworkError errorType);
private slots:
void finished(QNetworkReply *reply);
private:
QNetworkAccessManager _accessManager;
void finished();
};
}

View file

@ -145,7 +145,7 @@ void OcsProfileConnector::loadHovercardActionIcon(const std::size_t hovercardAct
void OcsProfileConnector::startFetchIconJob(const std::size_t hovercardActionIndex)
{
const auto hovercardAction = _currentHovercard._actions[hovercardActionIndex];
const auto iconJob = new IconJob{hovercardAction._iconUrl, this};
const auto iconJob = new IconJob{_account, hovercardAction._iconUrl, this};
connect(iconJob, &IconJob::jobFinished,
[this, hovercardActionIndex](QByteArray iconData) { loadHovercardActionIcon(hovercardActionIndex, iconData); });
connect(iconJob, &IconJob::error, this, [](QNetworkReply::NetworkError errorType) {