diff options
author | Hubert Chathi <uhoreg@debian.org> | 2020-04-20 18:01:38 -0400 |
---|---|---|
committer | Hubert Chathi <uhoreg@debian.org> | 2020-04-20 18:01:38 -0400 |
commit | 035d428becd62869b88793bb48d59410056b1f31 (patch) | |
tree | 0cd837955fa1037c74ee524a089ff1b788b75861 /lib/jobs | |
parent | 688dc682e0c6ae12dc87d781ffe53c974dad60df (diff) | |
parent | d8e1f4ee70902e2b9e5e9c699423d7f3fafe6238 (diff) | |
download | libquotient-035d428becd62869b88793bb48d59410056b1f31.tar.gz libquotient-035d428becd62869b88793bb48d59410056b1f31.zip |
Update upstream source from tag 'upstream/0.5.3.2'
Update to upstream version '0.5.3.2'
with Debian dir 49a325a077f4a2ebcd5b73adf3782a6fb5ecb3fe
Diffstat (limited to 'lib/jobs')
-rw-r--r-- | lib/jobs/basejob.cpp | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 0d9b9f10..0e6a8403 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -104,6 +104,7 @@ BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint, BaseJob::~BaseJob() { stop(); + d->retryTimer.stop(); // See #398 qCDebug(d->logCat) << this << "destroyed"; } @@ -197,8 +198,9 @@ void BaseJob::Private::sendRequest(bool inBackground) { makeRequestUrl(connection->baseUrl(), apiEndpoint, requestQuery) }; if (!requestHeaders.contains("Content-Type")) req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - req.setRawHeader("Authorization", - QByteArray("Bearer ") + connection->accessToken()); + if (needsToken) + req.setRawHeader("Authorization", + QByteArray("Bearer ") + connection->accessToken()); req.setAttribute(QNetworkRequest::BackgroundRequestAttribute, inBackground); #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); @@ -209,6 +211,7 @@ void BaseJob::Private::sendRequest(bool inBackground) // some sources claim that there are issues with QT 5.8 req.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); #endif + Q_ASSERT(req.url().isValid()); for (auto it = requestHeaders.cbegin(); it != requestHeaders.cend(); ++it) req.setRawHeader(it.key(), it.value()); switch( verb ) @@ -239,16 +242,23 @@ void BaseJob::beforeAbandon(QNetworkReply*) void BaseJob::start(const ConnectionData* connData, bool inBackground) { - d->connection = connData; - d->retryTimer.setSingleShot(true); - connect (&d->retryTimer, &QTimer::timeout, - this, [this,inBackground] { sendRequest(inBackground); }); - - beforeStart(connData); - if (status().good()) - sendRequest(inBackground); - if (status().good()) - afterStart(connData, d->reply.data()); + if (connData && connData->baseUrl().isValid()) { + d->connection = connData; + d->retryTimer.setSingleShot(true); + connect(&d->retryTimer, &QTimer::timeout, this, + [this, inBackground] { sendRequest(inBackground); }); + + beforeStart(connData); + if (status().good()) + sendRequest(inBackground); + if (status().good()) + afterStart(connData, d->reply.data()); + } else { + qCCritical(d->logCat) + << "Developers, ensure the Connection is valid before using it"; + Q_ASSERT(false); + setStatus(IncorrectRequestError, tr("Invalid server connection")); + } if (!status().good()) QTimer::singleShot(0, this, &BaseJob::finishJob); } @@ -333,7 +343,14 @@ void BaseJob::gotReply() d->status.message = tr("Requested room version: %1") .arg(json.value("room_version").toString()); - } else if (!json.isEmpty()) // Not localisable on the client side + } + else if (errCode == "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM") + setStatus(IncorrectRequestError, + tr("It's not allowed to leave a server notices room")); + else if (errCode == "M_USER_DEACTIVATED") + setStatus(ContentAccessError, + tr("The user has been deactivated")); + else if (!json.isEmpty()) // Not localisable on the client side setStatus(d->status.code, json.value("error"_ls).toString()); } } @@ -633,6 +650,8 @@ void BaseJob::setStatus(int code, QString message) void BaseJob::abandon() { beforeAbandon(d->reply ? d->reply.data() : nullptr); + d->timer.stop(); + d->retryTimer.stop(); // In case abandon() was called between retries setStatus(Abandoned); if (d->reply) d->reply->disconnect(this); |