aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/rooms.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/rooms.cpp
parent8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff)
parent56c2f2e2b809b9077393eb617828f33d144f5634 (diff)
downloadlibquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz
libquotient-d911b207f49e936b3e992200796110f0749ed150.zip
New upstream version 0.7.0
Diffstat (limited to 'lib/csapi/rooms.cpp')
-rw-r--r--lib/csapi/rooms.cpp263
1 files changed, 60 insertions, 203 deletions
diff --git a/lib/csapi/rooms.cpp b/lib/csapi/rooms.cpp
index 3befeee5..563f4fa5 100644
--- a/lib/csapi/rooms.cpp
+++ b/lib/csapi/rooms.cpp
@@ -4,236 +4,93 @@
#include "rooms.h"
-#include "converters.h"
+using namespace Quotient;
-#include <QtCore/QStringBuilder>
-
-using namespace QMatrixClient;
-
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
-class GetOneRoomEventJob::Private
-{
- public:
- EventPtr data;
-};
-
-QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId)
-{
- return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/event/" % eventId);
-}
-
-static const auto GetOneRoomEventJobName = QStringLiteral("GetOneRoomEventJob");
-
-GetOneRoomEventJob::GetOneRoomEventJob(const QString& roomId, const QString& eventId)
- : BaseJob(HttpVerb::Get, GetOneRoomEventJobName,
- basePath % "/rooms/" % roomId % "/event/" % eventId)
- , d(new Private)
-{
-}
-
-GetOneRoomEventJob::~GetOneRoomEventJob() = default;
-
-EventPtr&& GetOneRoomEventJob::data()
-{
- return std::move(d->data);
-}
-
-BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<EventPtr>(data);
- return Success;
-}
-
-class GetRoomStateWithKeyJob::Private
-{
- public:
- StateEventPtr data;
-};
-
-QUrl GetRoomStateWithKeyJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType, const QString& stateKey)
+QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& eventId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey);
-}
-
-static const auto GetRoomStateWithKeyJobName = QStringLiteral("GetRoomStateWithKeyJob");
-
-GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey)
- : BaseJob(HttpVerb::Get, GetRoomStateWithKeyJobName,
- basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey)
- , d(new Private)
-{
+ makePath("/_matrix/client/v3", "/rooms/",
+ roomId, "/event/", eventId));
}
-GetRoomStateWithKeyJob::~GetRoomStateWithKeyJob() = default;
-
-StateEventPtr&& GetRoomStateWithKeyJob::data()
-{
- return std::move(d->data);
-}
-
-BaseJob::Status GetRoomStateWithKeyJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<StateEventPtr>(data);
- return Success;
-}
+GetOneRoomEventJob::GetOneRoomEventJob(const QString& roomId,
+ const QString& eventId)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetOneRoomEventJob"),
+ makePath("/_matrix/client/v3", "/rooms/", roomId, "/event/",
+ eventId))
+{}
-class GetRoomStateByTypeJob::Private
-{
- public:
- StateEventPtr data;
-};
-
-QUrl GetRoomStateByTypeJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType)
+QUrl GetRoomStateWithKeyJob::makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& eventType,
+ const QString& stateKey)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/state/" % eventType);
-}
-
-static const auto GetRoomStateByTypeJobName = QStringLiteral("GetRoomStateByTypeJob");
-
-GetRoomStateByTypeJob::GetRoomStateByTypeJob(const QString& roomId, const QString& eventType)
- : BaseJob(HttpVerb::Get, GetRoomStateByTypeJobName,
- basePath % "/rooms/" % roomId % "/state/" % eventType)
- , d(new Private)
-{
+ makePath("/_matrix/client/v3", "/rooms/",
+ roomId, "/state/", eventType, "/",
+ stateKey));
}
-GetRoomStateByTypeJob::~GetRoomStateByTypeJob() = default;
-
-StateEventPtr&& GetRoomStateByTypeJob::data()
-{
- return std::move(d->data);
-}
-
-BaseJob::Status GetRoomStateByTypeJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<StateEventPtr>(data);
- return Success;
-}
-
-class GetRoomStateJob::Private
-{
- public:
- StateEvents data;
-};
+GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId,
+ const QString& eventType,
+ const QString& stateKey)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomStateWithKeyJob"),
+ makePath("/_matrix/client/v3", "/rooms/", roomId, "/state/",
+ eventType, "/", stateKey))
+{}
QUrl GetRoomStateJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/state");
+ makePath("/_matrix/client/v3", "/rooms/",
+ roomId, "/state"));
}
-static const auto GetRoomStateJobName = QStringLiteral("GetRoomStateJob");
-
GetRoomStateJob::GetRoomStateJob(const QString& roomId)
- : BaseJob(HttpVerb::Get, GetRoomStateJobName,
- basePath % "/rooms/" % roomId % "/state")
- , d(new Private)
-{
-}
-
-GetRoomStateJob::~GetRoomStateJob() = default;
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomStateJob"),
+ makePath("/_matrix/client/v3", "/rooms/", roomId, "/state"))
+{}
-StateEvents&& GetRoomStateJob::data()
+auto queryToGetMembersByRoom(const QString& at, const QString& membership,
+ const QString& notMembership)
{
- return std::move(d->data);
+ QUrlQuery _q;
+ addParam<IfNotEmpty>(_q, QStringLiteral("at"), at);
+ addParam<IfNotEmpty>(_q, QStringLiteral("membership"), membership);
+ addParam<IfNotEmpty>(_q, QStringLiteral("not_membership"), notMembership);
+ return _q;
}
-BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data)
+QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& at,
+ const QString& membership,
+ const QString& notMembership)
{
- d->data = fromJson<StateEvents>(data);
- return Success;
+ return BaseJob::makeRequestUrl(
+ std::move(baseUrl),
+ makePath("/_matrix/client/v3", "/rooms/", roomId, "/members"),
+ queryToGetMembersByRoom(at, membership, notMembership));
}
-class GetMembersByRoomJob::Private
-{
- public:
- EventsArray<RoomMemberEvent> chunk;
-};
+GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId,
+ const QString& at,
+ const QString& membership,
+ const QString& notMembership)
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetMembersByRoomJob"),
+ makePath("/_matrix/client/v3", "/rooms/", roomId, "/members"),
+ queryToGetMembersByRoom(at, membership, notMembership))
+{}
-QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
+QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl,
+ const QString& roomId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/members");
+ makePath("/_matrix/client/v3", "/rooms/",
+ roomId, "/joined_members"));
}
-static const auto GetMembersByRoomJobName = QStringLiteral("GetMembersByRoomJob");
-
-GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId)
- : BaseJob(HttpVerb::Get, GetMembersByRoomJobName,
- basePath % "/rooms/" % roomId % "/members")
- , d(new Private)
-{
-}
-
-GetMembersByRoomJob::~GetMembersByRoomJob() = default;
-
-EventsArray<RoomMemberEvent>&& GetMembersByRoomJob::chunk()
-{
- return std::move(d->chunk);
-}
-
-BaseJob::Status GetMembersByRoomJob::parseJson(const QJsonDocument& data)
-{
- auto json = data.object();
- d->chunk = fromJson<EventsArray<RoomMemberEvent>>(json.value("chunk"_ls));
- return Success;
-}
-
-namespace QMatrixClient
-{
- // Converters
-
- template <> struct FromJsonObject<GetJoinedMembersByRoomJob::RoomMember>
- {
- GetJoinedMembersByRoomJob::RoomMember operator()(const QJsonObject& jo) const
- {
- GetJoinedMembersByRoomJob::RoomMember result;
- result.displayName =
- fromJson<QString>(jo.value("display_name"_ls));
- result.avatarUrl =
- fromJson<QString>(jo.value("avatar_url"_ls));
-
- return result;
- }
- };
-} // namespace QMatrixClient
-
-class GetJoinedMembersByRoomJob::Private
-{
- public:
- QHash<QString, RoomMember> joined;
-};
-
-QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
-{
- return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/rooms/" % roomId % "/joined_members");
-}
-
-static const auto GetJoinedMembersByRoomJobName = QStringLiteral("GetJoinedMembersByRoomJob");
-
GetJoinedMembersByRoomJob::GetJoinedMembersByRoomJob(const QString& roomId)
- : BaseJob(HttpVerb::Get, GetJoinedMembersByRoomJobName,
- basePath % "/rooms/" % roomId % "/joined_members")
- , d(new Private)
-{
-}
-
-GetJoinedMembersByRoomJob::~GetJoinedMembersByRoomJob() = default;
-
-const QHash<QString, GetJoinedMembersByRoomJob::RoomMember>& GetJoinedMembersByRoomJob::joined() const
-{
- return d->joined;
-}
-
-BaseJob::Status GetJoinedMembersByRoomJob::parseJson(const QJsonDocument& data)
-{
- auto json = data.object();
- d->joined = fromJson<QHash<QString, RoomMember>>(json.value("joined"_ls));
- return Success;
-}
-
+ : BaseJob(HttpVerb::Get, QStringLiteral("GetJoinedMembersByRoomJob"),
+ makePath("/_matrix/client/v3", "/rooms/", roomId,
+ "/joined_members"))
+{}