diff options
Diffstat (limited to 'lib/csapi/admin.h')
-rw-r--r-- | lib/csapi/admin.h | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/csapi/admin.h b/lib/csapi/admin.h index 75ae1eb0..6ad7d08d 100644 --- a/lib/csapi/admin.h +++ b/lib/csapi/admin.h @@ -4,17 +4,10 @@ #pragma once -#include "converters.h" - #include "jobs/basejob.h" -#include <QtCore/QHash> -#include <QtCore/QVector> - namespace Quotient { -// Operations - /*! \brief Gets information about a particular user. * * Gets information about a particular user. @@ -66,6 +59,7 @@ public: /*! \brief Gets information about a particular user. * + * * \param userId * The user to look up. */ @@ -77,22 +71,44 @@ public: * is necessary but the job itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - ~GetWhoIsJob() override; // Result properties /// The Matrix user ID of the user. - const QString& userId() const; + QString userId() const { return loadFromJson<QString>("user_id"_ls); } - /// Each key is an identitfier for one of the user's devices. - const QHash<QString, DeviceInfo>& devices() const; + /// Each key is an identifier for one of the user's devices. + QHash<QString, DeviceInfo> devices() const + { + return loadFromJson<QHash<QString, DeviceInfo>>("devices"_ls); + } +}; + +template <> +struct JsonObjectConverter<GetWhoIsJob::ConnectionInfo> { + static void fillFrom(const QJsonObject& jo, + GetWhoIsJob::ConnectionInfo& result) + { + fromJson(jo.value("ip"_ls), result.ip); + fromJson(jo.value("last_seen"_ls), result.lastSeen); + fromJson(jo.value("user_agent"_ls), result.userAgent); + } +}; -protected: - Status parseJson(const QJsonDocument& data) override; +template <> +struct JsonObjectConverter<GetWhoIsJob::SessionInfo> { + static void fillFrom(const QJsonObject& jo, GetWhoIsJob::SessionInfo& result) + { + fromJson(jo.value("connections"_ls), result.connections); + } +}; -private: - class Private; - QScopedPointer<Private> d; +template <> +struct JsonObjectConverter<GetWhoIsJob::DeviceInfo> { + static void fillFrom(const QJsonObject& jo, GetWhoIsJob::DeviceInfo& result) + { + fromJson(jo.value("sessions"_ls), result.sessions); + } }; } // namespace Quotient |