aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/presence.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/presence.cpp')
-rw-r--r--lib/csapi/presence.cpp127
1 files changed, 14 insertions, 113 deletions
diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp
index 7aba8b61..828ccfb7 100644
--- a/lib/csapi/presence.cpp
+++ b/lib/csapi/presence.cpp
@@ -4,128 +4,29 @@
#include "presence.h"
-#include "converters.h"
+using namespace Quotient;
-#include <QtCore/QStringBuilder>
-
-using namespace QMatrixClient;
-
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
-static const auto SetPresenceJobName = QStringLiteral("SetPresenceJob");
-
-SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence, const QString& statusMsg)
- : BaseJob(HttpVerb::Put, SetPresenceJobName,
- basePath % "/presence/" % userId % "/status")
+SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence,
+ const QString& statusMsg)
+ : BaseJob(HttpVerb::Put, QStringLiteral("SetPresenceJob"),
+ makePath("/_matrix/client/v3", "/presence/", userId, "/status"))
{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("presence"), presence);
- addParam<IfNotEmpty>(_data, QStringLiteral("status_msg"), statusMsg);
- setRequestData(_data);
+ QJsonObject _dataJson;
+ addParam<>(_dataJson, QStringLiteral("presence"), presence);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("status_msg"), statusMsg);
+ setRequestData({ _dataJson });
}
-class GetPresenceJob::Private
-{
- public:
- QString presence;
- Omittable<int> lastActiveAgo;
- QString statusMsg;
- bool currentlyActive;
-};
-
QUrl GetPresenceJob::makeRequestUrl(QUrl baseUrl, const QString& userId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/presence/" % userId % "/status");
+ makePath("/_matrix/client/v3", "/presence/",
+ userId, "/status"));
}
-static const auto GetPresenceJobName = QStringLiteral("GetPresenceJob");
-
GetPresenceJob::GetPresenceJob(const QString& userId)
- : BaseJob(HttpVerb::Get, GetPresenceJobName,
- 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;
-}
-
-bool GetPresenceJob::currentlyActive() const
-{
- return d->currentlyActive;
-}
-
-BaseJob::Status GetPresenceJob::parseJson(const QJsonDocument& data)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetPresenceJob"),
+ makePath("/_matrix/client/v3", "/presence/", userId, "/status"))
{
- auto json = data.object();
- if (!json.contains("presence"_ls))
- return { JsonParseError,
- "The key 'presence' not found in the response" };
- d->presence = fromJson<QString>(json.value("presence"_ls));
- d->lastActiveAgo = fromJson<int>(json.value("last_active_ago"_ls));
- d->statusMsg = fromJson<QString>(json.value("status_msg"_ls));
- d->currentlyActive = fromJson<bool>(json.value("currently_active"_ls));
- return Success;
+ addExpectedKey("presence");
}
-
-static const auto ModifyPresenceListJobName = QStringLiteral("ModifyPresenceListJob");
-
-ModifyPresenceListJob::ModifyPresenceListJob(const QString& userId, const QStringList& invite, const QStringList& drop)
- : BaseJob(HttpVerb::Post, ModifyPresenceListJobName,
- basePath % "/presence/list/" % userId)
-{
- QJsonObject _data;
- addParam<IfNotEmpty>(_data, QStringLiteral("invite"), invite);
- addParam<IfNotEmpty>(_data, QStringLiteral("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);
-}
-
-static const auto GetPresenceForListJobName = QStringLiteral("GetPresenceForListJob");
-
-GetPresenceForListJob::GetPresenceForListJob(const QString& userId)
- : BaseJob(HttpVerb::Get, GetPresenceForListJobName,
- 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)
-{
- d->data = fromJson<Events>(data);
- return Success;
-}
-