From 826b8fb5afc80dd6adcc7ecee22997365a59f9d0 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 3 Jun 2018 19:50:08 +0900 Subject: csapi: PeekEventsJob, ReportContentJob, presence jobs --- lib/csapi/presence.cpp | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 lib/csapi/presence.cpp (limited to 'lib/csapi/presence.cpp') diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp new file mode 100644 index 00000000..707d48d0 --- /dev/null +++ b/lib/csapi/presence.cpp @@ -0,0 +1,127 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "presence.h" + +#include "converters.h" + +#include + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence, const QString& statusMsg) + : BaseJob(HttpVerb::Put, "SetPresenceJob", + basePath % "/presence/" % userId % "/status") +{ + QJsonObject _data; + addToJson<>(_data, "presence", presence); + addToJson(_data, "status_msg", statusMsg); + setRequestData(_data); +} + +class GetPresenceJob::Private +{ + public: + QString presence; + Omittable lastActiveAgo; + QString statusMsg; + bool currentlyActive; +}; + +QUrl GetPresenceJob::makeRequestUrl(QUrl baseUrl, const QString& userId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/presence/" % userId % "/status"); +} + +GetPresenceJob::GetPresenceJob(const QString& userId) + : BaseJob(HttpVerb::Get, "GetPresenceJob", + basePath % "/presence/" % userId % "/status", false) + , d(new Private) +{ +} + +GetPresenceJob::~GetPresenceJob() = default; + +const QString& GetPresenceJob::presence() const +{ + return d->presence; +} + +Omittable GetPresenceJob::lastActiveAgo() const +{ + return d->lastActiveAgo; +} + +const QString& GetPresenceJob::statusMsg() const +{ + return d->statusMsg; +} + +bool GetPresenceJob::currentlyActive() const +{ + return d->currentlyActive; +} + +BaseJob::Status GetPresenceJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("presence")) + return { JsonParseError, + "The key 'presence' not found in the response" }; + d->presence = fromJson(json.value("presence")); + d->lastActiveAgo = fromJson(json.value("last_active_ago")); + d->statusMsg = fromJson(json.value("status_msg")); + d->currentlyActive = fromJson(json.value("currently_active")); + return Success; +} + +ModifyPresenceListJob::ModifyPresenceListJob(const QString& userId, const QStringList& invite, const QStringList& drop) + : BaseJob(HttpVerb::Post, "ModifyPresenceListJob", + basePath % "/presence/list/" % userId) +{ + QJsonObject _data; + addToJson(_data, "invite", invite); + addToJson(_data, "drop", drop); + setRequestData(_data); +} + +class GetPresenceForListJob::Private +{ + public: + Events data; +}; + +QUrl GetPresenceForListJob::makeRequestUrl(QUrl baseUrl, const QString& userId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/presence/list/" % userId); +} + +GetPresenceForListJob::GetPresenceForListJob(const QString& userId) + : BaseJob(HttpVerb::Get, "GetPresenceForListJob", + basePath % "/presence/list/" % userId, false) + , d(new Private) +{ +} + +GetPresenceForListJob::~GetPresenceForListJob() = default; + +Events&& GetPresenceForListJob::data() +{ + return std::move(d->data); +} + +BaseJob::Status GetPresenceForListJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson(json.value("data")); + return Success; +} + -- cgit v1.2.3