diff options
Diffstat (limited to 'lib/csapi/directory.cpp')
-rw-r--r-- | lib/csapi/directory.cpp | 80 |
1 files changed, 27 insertions, 53 deletions
diff --git a/lib/csapi/directory.cpp b/lib/csapi/directory.cpp index 5353f3bc..c1255bb1 100644 --- a/lib/csapi/directory.cpp +++ b/lib/csapi/directory.cpp @@ -4,78 +4,52 @@ #include "directory.h" -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0/directory"); - -static const auto SetRoomAliasJobName = QStringLiteral("SetRoomAliasJob"); +using namespace Quotient; SetRoomAliasJob::SetRoomAliasJob(const QString& roomAlias, const QString& roomId) - : BaseJob(HttpVerb::Put, SetRoomAliasJobName, - basePath % "/room/" % roomAlias) + : BaseJob(HttpVerb::Put, QStringLiteral("SetRoomAliasJob"), + makePath("/_matrix/client/v3", "/directory/room/", roomAlias)) { - QJsonObject _data; - addParam<>(_data, QStringLiteral("room_id"), roomId); - setRequestData(_data); + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("room_id"), roomId); + setRequestData({ _dataJson }); } -class GetRoomIdByAliasJob::Private -{ - public: - QString roomId; - QStringList servers; -}; - QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) { return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/room/" % roomAlias); + makePath("/_matrix/client/v3", + "/directory/room/", roomAlias)); } -static const auto GetRoomIdByAliasJobName = QStringLiteral("GetRoomIdByAliasJob"); - GetRoomIdByAliasJob::GetRoomIdByAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Get, GetRoomIdByAliasJobName, - basePath % "/room/" % roomAlias, false) - , d(new Private) -{ -} - -GetRoomIdByAliasJob::~GetRoomIdByAliasJob() = default; - -const QString& GetRoomIdByAliasJob::roomId() const -{ - return d->roomId; -} + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomIdByAliasJob"), + makePath("/_matrix/client/v3", "/directory/room/", roomAlias), + false) +{} -const QStringList& GetRoomIdByAliasJob::servers() const +QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) { - return d->servers; + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/directory/room/", roomAlias)); } -BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id"_ls)); - d->servers = fromJson<QStringList>(json.value("servers"_ls)); - return Success; -} +DeleteRoomAliasJob::DeleteRoomAliasJob(const QString& roomAlias) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomAliasJob"), + makePath("/_matrix/client/v3", "/directory/room/", roomAlias)) +{} -QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) +QUrl GetLocalAliasesJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) { return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/room/" % roomAlias); + makePath("/_matrix/client/v3", "/rooms/", + roomId, "/aliases")); } -static const auto DeleteRoomAliasJobName = QStringLiteral("DeleteRoomAliasJob"); - -DeleteRoomAliasJob::DeleteRoomAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Delete, DeleteRoomAliasJobName, - basePath % "/room/" % roomAlias) +GetLocalAliasesJob::GetLocalAliasesJob(const QString& roomId) + : BaseJob(HttpVerb::Get, QStringLiteral("GetLocalAliasesJob"), + makePath("/_matrix/client/v3", "/rooms/", roomId, "/aliases")) { + addExpectedKey("aliases"); } - |