aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/notifications.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-09 08:52:25 +0200
committerGitHub <noreply@github.com>2020-06-09 08:52:25 +0200
commit370d9b3e46332d38df8798cda208c534c58be808 (patch)
treef3db0cd7463468ff52c74446acd608356f8b8ab6 /lib/csapi/notifications.cpp
parente1f5d0aa2c33e6da6c3a609c8bc7e0b5867e748d (diff)
parent10d9ac4673e374a9ac17ff492591136520337c4c (diff)
downloadlibquotient-370d9b3e46332d38df8798cda208c534c58be808.tar.gz
libquotient-370d9b3e46332d38df8798cda208c534c58be808.zip
Merge pull request #405 from quotient-im/kitsune-basejob-store-json-response
Store JSON response in BaseJob + tweaks to the generated code
Diffstat (limited to 'lib/csapi/notifications.cpp')
-rw-r--r--lib/csapi/notifications.cpp61
1 files changed, 6 insertions, 55 deletions
diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp
index d00d5425..a479d500 100644
--- a/lib/csapi/notifications.cpp
+++ b/lib/csapi/notifications.cpp
@@ -4,41 +4,12 @@
#include "notifications.h"
-#include "converters.h"
-
#include <QtCore/QStringBuilder>
using namespace Quotient;
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
-// Converters
-namespace Quotient {
-
-template <>
-struct JsonObjectConverter<GetNotificationsJob::Notification> {
- static void fillFrom(const QJsonObject& jo,
- GetNotificationsJob::Notification& result)
- {
- fromJson(jo.value("actions"_ls), result.actions);
- fromJson(jo.value("event"_ls), result.event);
- fromJson(jo.value("profile_tag"_ls), result.profileTag);
- fromJson(jo.value("read"_ls), result.read);
- fromJson(jo.value("room_id"_ls), result.roomId);
- fromJson(jo.value("ts"_ls), result.ts);
- }
-};
-
-} // namespace Quotient
-
-class GetNotificationsJob::Private {
-public:
- QString nextToken;
- std::vector<Notification> notifications;
-};
-
-BaseJob::Query queryToGetNotifications(const QString& from,
- Omittable<int> limit, const QString& only)
+auto queryToGetNotifications(const QString& from, Omittable<int> limit,
+ const QString& only)
{
BaseJob::Query _q;
addParam<IfNotEmpty>(_q, QStringLiteral("from"), from);
@@ -52,7 +23,8 @@ QUrl GetNotificationsJob::makeRequestUrl(QUrl baseUrl, const QString& from,
const QString& only)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/notifications",
+ QStringLiteral("/_matrix/client/r0")
+ % "/notifications",
queryToGetNotifications(from, limit, only));
}
@@ -60,29 +32,8 @@ GetNotificationsJob::GetNotificationsJob(const QString& from,
Omittable<int> limit,
const QString& only)
: BaseJob(HttpVerb::Get, QStringLiteral("GetNotificationsJob"),
- basePath % "/notifications",
+ QStringLiteral("/_matrix/client/r0") % "/notifications",
queryToGetNotifications(from, limit, only))
- , d(new Private)
-{}
-
-GetNotificationsJob::~GetNotificationsJob() = default;
-
-const QString& GetNotificationsJob::nextToken() const { return d->nextToken; }
-
-std::vector<GetNotificationsJob::Notification>&&
-GetNotificationsJob::notifications()
-{
- return std::move(d->notifications);
-}
-
-BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data)
{
- auto json = data.object();
- fromJson(json.value("next_token"_ls), d->nextToken);
- if (!json.contains("notifications"_ls))
- return { IncorrectResponse,
- "The key 'notifications' not found in the response" };
- fromJson(json.value("notifications"_ls), d->notifications);
-
- return Success;
+ addExpectedKey("notifications");
}