aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/presence.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/presence.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/presence.cpp')
-rw-r--r--lib/csapi/presence.cpp54
1 files changed, 8 insertions, 46 deletions
diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp
index 932ccc6e..58d0d157 100644
--- a/lib/csapi/presence.cpp
+++ b/lib/csapi/presence.cpp
@@ -4,71 +4,33 @@
#include "presence.h"
-#include "converters.h"
-
#include <QtCore/QStringBuilder>
using namespace Quotient;
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence,
const QString& statusMsg)
: BaseJob(HttpVerb::Put, QStringLiteral("SetPresenceJob"),
- basePath % "/presence/" % userId % "/status")
+ QStringLiteral("/_matrix/client/r0") % "/presence/" % userId
+ % "/status")
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("presence"), presence);
addParam<IfNotEmpty>(_data, QStringLiteral("status_msg"), statusMsg);
- setRequestData(_data);
+ setRequestData(std::move(_data));
}
-class GetPresenceJob::Private {
-public:
- QString presence;
- Omittable<int> lastActiveAgo;
- QString statusMsg;
- Omittable<bool> currentlyActive;
-};
-
QUrl GetPresenceJob::makeRequestUrl(QUrl baseUrl, const QString& userId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/presence/" % userId % "/status");
+ QStringLiteral("/_matrix/client/r0")
+ % "/presence/" % userId % "/status");
}
GetPresenceJob::GetPresenceJob(const QString& userId)
: BaseJob(HttpVerb::Get, QStringLiteral("GetPresenceJob"),
- basePath % "/presence/" % userId % "/status")
- , d(new Private)
-{}
-
-GetPresenceJob::~GetPresenceJob() = default;
-
-const QString& GetPresenceJob::presence() const { return d->presence; }
-
-Omittable<int> GetPresenceJob::lastActiveAgo() const
-{
- return d->lastActiveAgo;
-}
-
-const QString& GetPresenceJob::statusMsg() const { return d->statusMsg; }
-
-Omittable<bool> GetPresenceJob::currentlyActive() const
+ QStringLiteral("/_matrix/client/r0") % "/presence/" % userId
+ % "/status")
{
- return d->currentlyActive;
-}
-
-BaseJob::Status GetPresenceJob::parseJson(const QJsonDocument& data)
-{
- auto json = data.object();
- if (!json.contains("presence"_ls))
- return { IncorrectResponse,
- "The key 'presence' not found in the response" };
- fromJson(json.value("presence"_ls), d->presence);
- fromJson(json.value("last_active_ago"_ls), d->lastActiveAgo);
- fromJson(json.value("status_msg"_ls), d->statusMsg);
- fromJson(json.value("currently_active"_ls), d->currentlyActive);
-
- return Success;
+ addExpectedKey("presence");
}