aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/presence.cpp
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
committern-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
commitd911b207f49e936b3e992200796110f0749ed150 (patch)
tree96d20ebb4d074a4c1755e21cb316a52d584daee3 /lib/csapi/presence.cpp
parent8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff)
parent56c2f2e2b809b9077393eb617828f33d144f5634 (diff)
downloadlibquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz
libquotient-d911b207f49e936b3e992200796110f0749ed150.zip
New upstream version 0.7.0
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;
-}
-