diff options
Diffstat (limited to 'lib/csapi/rooms.cpp')
-rw-r--r-- | lib/csapi/rooms.cpp | 158 |
1 files changed, 88 insertions, 70 deletions
diff --git a/lib/csapi/rooms.cpp b/lib/csapi/rooms.cpp index 0b08ccec..280e8d59 100644 --- a/lib/csapi/rooms.cpp +++ b/lib/csapi/rooms.cpp @@ -14,31 +14,30 @@ static const auto basePath = QStringLiteral("/_matrix/client/r0"); class GetOneRoomEventJob::Private { - public: - EventPtr data; +public: + EventPtr data; }; -QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId) +QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& eventId) { - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/event/" % 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) +GetOneRoomEventJob::GetOneRoomEventJob(const QString& roomId, + const QString& eventId) : BaseJob(HttpVerb::Get, GetOneRoomEventJobName, - basePath % "/rooms/" % roomId % "/event/" % eventId) + basePath % "/rooms/" % roomId % "/event/" % eventId) , d(new Private) -{ -} +{} GetOneRoomEventJob::~GetOneRoomEventJob() = default; -EventPtr&& GetOneRoomEventJob::data() -{ - return std::move(d->data); -} +EventPtr&& GetOneRoomEventJob::data() { return std::move(d->data); } BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data) { @@ -46,61 +45,66 @@ BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data) return Success; } -QUrl GetRoomStateWithKeyJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType, const QString& stateKey) +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 % "/" % stateKey); + basePath % "/rooms/" % roomId % "/state/" + % eventType % "/" % stateKey); } -static const auto GetRoomStateWithKeyJobName = QStringLiteral("GetRoomStateWithKeyJob"); +static const auto GetRoomStateWithKeyJobName = + QStringLiteral("GetRoomStateWithKeyJob"); -GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey) +GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId, + const QString& eventType, + const QString& stateKey) : BaseJob(HttpVerb::Get, GetRoomStateWithKeyJobName, - basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey) -{ -} + basePath % "/rooms/" % roomId % "/state/" % eventType % "/" + % stateKey) +{} -QUrl GetRoomStateByTypeJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType) +QUrl GetRoomStateByTypeJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& eventType) { - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/state/" % eventType); + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/rooms/" + % roomId % "/state/" + % eventType); } -static const auto GetRoomStateByTypeJobName = QStringLiteral("GetRoomStateByTypeJob"); +static const auto GetRoomStateByTypeJobName = + QStringLiteral("GetRoomStateByTypeJob"); -GetRoomStateByTypeJob::GetRoomStateByTypeJob(const QString& roomId, const QString& eventType) +GetRoomStateByTypeJob::GetRoomStateByTypeJob(const QString& roomId, + const QString& eventType) : BaseJob(HttpVerb::Get, GetRoomStateByTypeJobName, - basePath % "/rooms/" % roomId % "/state/" % eventType) -{ -} + basePath % "/rooms/" % roomId % "/state/" % eventType) +{} class GetRoomStateJob::Private { - public: - StateEvents data; +public: + StateEvents data; }; QUrl GetRoomStateJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) { return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/state"); + basePath % "/rooms/" % roomId % "/state"); } static const auto GetRoomStateJobName = QStringLiteral("GetRoomStateJob"); GetRoomStateJob::GetRoomStateJob(const QString& roomId) : BaseJob(HttpVerb::Get, GetRoomStateJobName, - basePath % "/rooms/" % roomId % "/state") + basePath % "/rooms/" % roomId % "/state") , d(new Private) -{ -} +{} GetRoomStateJob::~GetRoomStateJob() = default; -StateEvents&& GetRoomStateJob::data() -{ - return std::move(d->data); -} +StateEvents&& GetRoomStateJob::data() { return std::move(d->data); } BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data) { @@ -110,11 +114,13 @@ BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data) class GetMembersByRoomJob::Private { - public: - EventsArray<RoomMemberEvent> chunk; +public: + EventsArray<RoomMemberEvent> chunk; }; -BaseJob::Query queryToGetMembersByRoom(const QString& at, const QString& membership, const QString& notMembership) +BaseJob::Query queryToGetMembersByRoom(const QString& at, + const QString& membership, + const QString& notMembership) { BaseJob::Query _q; addParam<IfNotEmpty>(_q, QStringLiteral("at"), at); @@ -123,22 +129,28 @@ BaseJob::Query queryToGetMembersByRoom(const QString& at, const QString& members return _q; } -QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& at, const QString& membership, const QString& notMembership) +QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& at, + const QString& membership, + const QString& notMembership) { - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/members", - queryToGetMembersByRoom(at, membership, notMembership)); + return BaseJob::makeRequestUrl( + std::move(baseUrl), basePath % "/rooms/" % roomId % "/members", + queryToGetMembersByRoom(at, membership, notMembership)); } -static const auto GetMembersByRoomJobName = QStringLiteral("GetMembersByRoomJob"); +static const auto GetMembersByRoomJobName = + QStringLiteral("GetMembersByRoomJob"); -GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId, const QString& at, const QString& membership, const QString& notMembership) +GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId, + const QString& at, + const QString& membership, + const QString& notMembership) : BaseJob(HttpVerb::Get, GetMembersByRoomJobName, - basePath % "/rooms/" % roomId % "/members", - queryToGetMembersByRoom(at, membership, notMembership)) + basePath % "/rooms/" % roomId % "/members", + queryToGetMembersByRoom(at, membership, notMembership)) , d(new Private) -{ -} +{} GetMembersByRoomJob::~GetMembersByRoomJob() = default; @@ -151,47 +163,53 @@ BaseJob::Status GetMembersByRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); fromJson(json.value("chunk"_ls), d->chunk); + return Success; } +// Converters namespace QMatrixClient { - // Converters - template <> struct JsonObjectConverter<GetJoinedMembersByRoomJob::RoomMember> +template <> +struct JsonObjectConverter<GetJoinedMembersByRoomJob::RoomMember> +{ + static void fillFrom(const QJsonObject& jo, + GetJoinedMembersByRoomJob::RoomMember& result) { - static void fillFrom(const QJsonObject& jo, GetJoinedMembersByRoomJob::RoomMember& result) - { - fromJson(jo.value("display_name"_ls), result.displayName); - fromJson(jo.value("avatar_url"_ls), result.avatarUrl); - } - }; + fromJson(jo.value("display_name"_ls), result.displayName); + fromJson(jo.value("avatar_url"_ls), result.avatarUrl); + } +}; + } // namespace QMatrixClient class GetJoinedMembersByRoomJob::Private { - public: - QHash<QString, RoomMember> joined; +public: + QHash<QString, RoomMember> joined; }; -QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId) { - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/joined_members"); + return BaseJob::makeRequestUrl( + std::move(baseUrl), basePath % "/rooms/" % roomId % "/joined_members"); } -static const auto GetJoinedMembersByRoomJobName = QStringLiteral("GetJoinedMembersByRoomJob"); +static const auto GetJoinedMembersByRoomJobName = + QStringLiteral("GetJoinedMembersByRoomJob"); GetJoinedMembersByRoomJob::GetJoinedMembersByRoomJob(const QString& roomId) : BaseJob(HttpVerb::Get, GetJoinedMembersByRoomJobName, - basePath % "/rooms/" % roomId % "/joined_members") + basePath % "/rooms/" % roomId % "/joined_members") , d(new Private) -{ -} +{} GetJoinedMembersByRoomJob::~GetJoinedMembersByRoomJob() = default; -const QHash<QString, GetJoinedMembersByRoomJob::RoomMember>& GetJoinedMembersByRoomJob::joined() const +const QHash<QString, GetJoinedMembersByRoomJob::RoomMember>& +GetJoinedMembersByRoomJob::joined() const { return d->joined; } @@ -200,6 +218,6 @@ BaseJob::Status GetJoinedMembersByRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); fromJson(json.value("joined"_ls), d->joined); + return Success; } - |