aboutsummaryrefslogtreecommitdiff
path: root/lib/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jobs')
-rw-r--r--lib/jobs/basejob.cpp25
-rw-r--r--lib/jobs/sendeventjob.cpp2
-rw-r--r--lib/jobs/sendeventjob.h4
-rw-r--r--lib/jobs/syncjob.cpp47
-rw-r--r--lib/jobs/syncjob.h2
5 files changed, 43 insertions, 37 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp
index 607a6c04..f9628c19 100644
--- a/lib/jobs/basejob.cpp
+++ b/lib/jobs/basejob.cpp
@@ -19,6 +19,7 @@
#include "basejob.h"
#include "connectiondata.h"
+#include "util.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
@@ -196,7 +197,7 @@ void BaseJob::Private::sendRequest(bool inBackground)
{ makeRequestUrl(connection->baseUrl(), apiEndpoint, requestQuery) };
if (!requestHeaders.contains("Content-Type"))
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
- req.setRawHeader(QByteArray("Authorization"),
+ req.setRawHeader("Authorization",
QByteArray("Bearer ") + connection->accessToken());
req.setAttribute(QNetworkRequest::BackgroundRequestAttribute, inBackground);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
@@ -292,11 +293,12 @@ void BaseJob::gotReply()
if (jsonBody)
{
auto json = QJsonDocument::fromJson(d->rawResponse).object();
+ const auto errCode = json.value("errcode"_ls).toString();
if (error() == TooManyRequestsError ||
- json.value("errcode").toString() == "M_LIMIT_EXCEEDED")
+ errCode == "M_LIMIT_EXCEEDED")
{
QString msg = tr("Too many requests");
- auto retryInterval = json.value("retry_after_ms").toInt(-1);
+ auto retryInterval = json.value("retry_after_ms"_ls).toInt(-1);
if (retryInterval != -1)
msg += tr(", next retry advised after %1 ms")
.arg(retryInterval);
@@ -313,13 +315,14 @@ void BaseJob::gotReply()
emit retryScheduled(d->retriesTaken, retryInterval);
return;
}
- if (json.value("errcode").toString() == "M_CONSENT_NOT_GIVEN")
+ if (errCode == "M_CONSENT_NOT_GIVEN")
{
d->status.code = UserConsentRequiredError;
- d->errorUrl = json.value("consent_uri").toString();
+ d->errorUrl = json.value("consent_uri"_ls).toString();
}
- else if (!json.isEmpty()) // FIXME: The below is not localisable
- setStatus(IncorrectRequestError, json.value("error").toString());
+ else if (!json.isEmpty()) // Not localisable on the client side
+ setStatus(IncorrectRequestError,
+ json.value("error"_ls).toString());
}
}
@@ -366,7 +369,8 @@ BaseJob::Status BaseJob::doCheckReply(QNetworkReply* reply) const
return { NetworkError, reply->errorString() };
}
- const QString replyState = reply->isRunning() ? "(tentative)" : "(final)";
+ const QString replyState = reply->isRunning() ?
+ QStringLiteral("(tentative)") : QStringLiteral("(final)");
const auto urlString = '|' + d->reply->url().toDisplayString();
const auto httpCode = httpCodeHeader.toInt();
const auto reason =
@@ -375,12 +379,11 @@ BaseJob::Status BaseJob::doCheckReply(QNetworkReply* reply) const
{
qCDebug(d->logCat).noquote().nospace() << this << urlString;
qCDebug(d->logCat).noquote() << " " << httpCode << reason << replyState;
- if (checkContentType(reply->rawHeader("Content-Type"),
+ if (!checkContentType(reply->rawHeader("Content-Type"),
d->expectedContentTypes))
- return NoError;
- else // A warning in the logs might be more proper instead
return { UnexpectedResponseTypeWarning,
"Unexpected content type of the response" };
+ return NoError;
}
qCWarning(d->logCat).noquote().nospace() << this << urlString;
diff --git a/lib/jobs/sendeventjob.cpp b/lib/jobs/sendeventjob.cpp
index f5190d4b..e5852c65 100644
--- a/lib/jobs/sendeventjob.cpp
+++ b/lib/jobs/sendeventjob.cpp
@@ -35,7 +35,7 @@ void SendEventJob::beforeStart(const ConnectionData* connData)
BaseJob::Status SendEventJob::parseJson(const QJsonDocument& data)
{
- _eventId = data.object().value("event_id").toString();
+ _eventId = data.object().value("event_id"_ls).toString();
if (!_eventId.isEmpty())
return Success;
diff --git a/lib/jobs/sendeventjob.h b/lib/jobs/sendeventjob.h
index a3e9a291..af81ae26 100644
--- a/lib/jobs/sendeventjob.h
+++ b/lib/jobs/sendeventjob.h
@@ -32,9 +32,9 @@ namespace QMatrixClient
SendEventJob(const QString& roomId, const EvT& event)
: BaseJob(HttpVerb::Put, QStringLiteral("SendEventJob"),
QStringLiteral("_matrix/client/r0/rooms/%1/send/%2/")
- .arg(roomId, EvT::typeId()), // See also beforeStart()
+ .arg(roomId, EvT::matrixTypeId()), // See also beforeStart()
Query(),
- Data(event.toJson()))
+ Data(event.contentJson()))
{ }
/**
diff --git a/lib/jobs/syncjob.cpp b/lib/jobs/syncjob.cpp
index cbdc37b4..02690e6d 100644
--- a/lib/jobs/syncjob.cpp
+++ b/lib/jobs/syncjob.cpp
@@ -18,6 +18,8 @@
#include "syncjob.h"
+#include "events/eventloader.h"
+
#include <QtCore/QElapsedTimer>
using namespace QMatrixClient;
@@ -32,13 +34,13 @@ SyncJob::SyncJob(const QString& since, const QString& filter, int timeout,
setLoggingCategory(SYNCJOB);
QUrlQuery query;
if( !filter.isEmpty() )
- query.addQueryItem("filter", filter);
+ query.addQueryItem(QStringLiteral("filter"), filter);
if( !presence.isEmpty() )
- query.addQueryItem("set_presence", presence);
+ query.addQueryItem(QStringLiteral("set_presence"), presence);
if( timeout >= 0 )
- query.addQueryItem("timeout", QString::number(timeout));
+ query.addQueryItem(QStringLiteral("timeout"), QString::number(timeout));
if( !since.isEmpty() )
- query.addQueryItem("since", since);
+ query.addQueryItem(QStringLiteral("since"), since);
setRequestQuery(query);
setMaxRetries(std::numeric_limits<int>::max());
@@ -72,7 +74,7 @@ Events&&SyncData::takeToDeviceEvents()
template <typename EventsArrayT, typename StrT>
inline EventsArrayT load(const QJsonObject& batches, StrT keyName)
{
- return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"));
+ return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"_ls));
}
BaseJob::Status SyncJob::parseJson(const QJsonDocument& data)
@@ -85,12 +87,12 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data)
QElapsedTimer et; et.start();
auto json = data.object();
- nextBatch_ = json.value("next_batch").toString();
- presenceData = load<Events>(json, "presence");
- accountData = load<Events>(json, "account_data");
- toDeviceEvents = load<Events>(json, "to_device");
+ nextBatch_ = json.value("next_batch"_ls).toString();
+ presenceData = load<Events>(json, "presence"_ls);
+ accountData = load<Events>(json, "account_data"_ls);
+ toDeviceEvents = load<Events>(json, "to_device"_ls);
- QJsonObject rooms = json.value("rooms").toObject();
+ auto rooms = json.value("rooms"_ls).toObject();
JoinStates::Int ii = 1; // ii is used to make a JoinState value
auto totalRooms = 0;
auto totalEvents = 0;
@@ -123,30 +125,31 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
: roomId(roomId_)
, joinState(joinState_)
, state(load<StateEvents>(room_,
- joinState == JoinState::Invite ? "invite_state" : "state"))
+ joinState == JoinState::Invite ? "invite_state"_ls : "state"_ls))
{
switch (joinState) {
case JoinState::Join:
- ephemeral = load<Events>(room_, "ephemeral");
- accountData = load<Events>(room_, "account_data");
+ ephemeral = load<Events>(room_, "ephemeral"_ls);
+ accountData = load<Events>(room_, "account_data"_ls);
FALLTHROUGH;
case JoinState::Leave:
{
- timeline = load<RoomEvents>(room_, "timeline");
- auto timelineJson = room_.value("timeline").toObject();
- timelineLimited = timelineJson.value("limited").toBool();
- timelinePrevBatch = timelineJson.value("prev_batch").toString();
+ timeline = load<RoomEvents>(room_, "timeline"_ls);
+ const auto timelineJson = room_.value("timeline"_ls).toObject();
+ timelineLimited = timelineJson.value("limited"_ls).toBool();
+ timelinePrevBatch = timelineJson.value("prev_batch"_ls).toString();
break;
}
default: /* nothing on top of state */;
}
- auto unreadJson = room_.value("unread_notifications").toObject();
+ const auto unreadJson = room_.value("unread_notifications"_ls).toObject();
unreadCount = unreadJson.value(UnreadCountKey).toInt(-2);
- highlightCount = unreadJson.value("highlight_count").toInt();
- notificationCount = unreadJson.value("notification_count").toInt();
+ highlightCount = unreadJson.value("highlight_count"_ls).toInt();
+ notificationCount = unreadJson.value("notification_count"_ls).toInt();
if (highlightCount > 0 || notificationCount > 0)
- qCDebug(SYNCJOB) << "Highlights: " << highlightCount
- << " Notifications:" << notificationCount;
+ qCDebug(SYNCJOB) << "Room" << roomId_
+ << "has highlights:" << highlightCount
+ << "and notifications:" << notificationCount;
}
diff --git a/lib/jobs/syncjob.h b/lib/jobs/syncjob.h
index ca30848e..6b9bedfa 100644
--- a/lib/jobs/syncjob.h
+++ b/lib/jobs/syncjob.h
@@ -21,7 +21,7 @@
#include "basejob.h"
#include "joinstate.h"
-#include "events/event.h"
+#include "events/stateevent.h"
#include "util.h"
namespace QMatrixClient