| 1 | /****************************************************************************** |
| 2 | * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN |
| 3 | */ |
| 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | #include <Quotient/jobs/basejob.h> |
| 8 | |
| 9 | namespace Quotient { |
| 10 | |
| 11 | /*! \brief Gets information about a particular user. |
| 12 | * |
| 13 | * Gets information about a particular user. |
| 14 | * |
| 15 | * This API may be restricted to only be called by the user being looked |
| 16 | * up, or by a server admin. Server-local administrator privileges are not |
| 17 | * specified in this document. |
| 18 | */ |
| 19 | class QUOTIENT_API GetWhoIsJob : public BaseJob { |
| 20 | public: |
| 21 | // Inner data structures |
| 22 | |
| 23 | /// Gets information about a particular user. |
| 24 | /// |
| 25 | /// This API may be restricted to only be called by the user being looked |
| 26 | /// up, or by a server admin. Server-local administrator privileges are not |
| 27 | /// specified in this document. |
| 28 | struct ConnectionInfo { |
| 29 | /// Most recently seen IP address of the session. |
| 30 | QString ip{}; |
| 31 | /// Unix timestamp that the session was last active. |
| 32 | Omittable<qint64> lastSeen{}; |
| 33 | /// User agent string last seen in the session. |
| 34 | QString userAgent{}; |
| 35 | }; |
| 36 | |
| 37 | /// Gets information about a particular user. |
| 38 | /// |
| 39 | /// This API may be restricted to only be called by the user being looked |
| 40 | /// up, or by a server admin. Server-local administrator privileges are not |
| 41 | /// specified in this document. |
| 42 | struct SessionInfo { |
| 43 | /// Information particular connections in the session. |
| 44 | QVector<ConnectionInfo> connections{}; |
| 45 | }; |
| 46 | |
| 47 | /// Gets information about a particular user. |
| 48 | /// |
| 49 | /// This API may be restricted to only be called by the user being looked |
| 50 | /// up, or by a server admin. Server-local administrator privileges are not |
| 51 | /// specified in this document. |
| 52 | struct DeviceInfo { |
| 53 | /// A user's sessions (i.e. what they did with an access token from one |
| 54 | /// login). |
| 55 | QVector<SessionInfo> sessions{}; |
| 56 | }; |
| 57 | |
| 58 | // Construction/destruction |
| 59 | |
| 60 | /*! \brief Gets information about a particular user. |
| 61 | * |
| 62 | * \param userId |
| 63 | * The user to look up. |
| 64 | */ |
| 65 | explicit GetWhoIsJob(const QString& userId); |
| 66 | |
| 67 | /*! \brief Construct a URL without creating a full-fledged job object |
| 68 | * |
| 69 | * This function can be used when a URL for GetWhoIsJob |
| 70 | * is necessary but the job itself isn't. |
| 71 | */ |
| 72 | static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); |
| 73 | |
| 74 | // Result properties |
| 75 | |
| 76 | /// The Matrix user ID of the user. |
| 77 | QString userId() const { return loadFromJson<QString>(keyName: "user_id"_ls ); } |
| 78 | |
| 79 | /// Each key is an identifier for one of the user's devices. |
| 80 | QHash<QString, DeviceInfo> devices() const |
| 81 | { |
| 82 | return loadFromJson<QHash<QString, DeviceInfo>>(keyName: "devices"_ls ); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | template <> |
| 87 | struct JsonObjectConverter<GetWhoIsJob::ConnectionInfo> { |
| 88 | static void fillFrom(const QJsonObject& jo, |
| 89 | GetWhoIsJob::ConnectionInfo& result) |
| 90 | { |
| 91 | fillFromJson(jv: jo.value(key: "ip"_ls ), pod&: result.ip); |
| 92 | fillFromJson(jv: jo.value(key: "last_seen"_ls ), pod&: result.lastSeen); |
| 93 | fillFromJson(jv: jo.value(key: "user_agent"_ls ), pod&: result.userAgent); |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | template <> |
| 98 | struct JsonObjectConverter<GetWhoIsJob::SessionInfo> { |
| 99 | static void fillFrom(const QJsonObject& jo, GetWhoIsJob::SessionInfo& result) |
| 100 | { |
| 101 | fillFromJson(jv: jo.value(key: "connections"_ls ), pod&: result.connections); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | template <> |
| 106 | struct JsonObjectConverter<GetWhoIsJob::DeviceInfo> { |
| 107 | static void fillFrom(const QJsonObject& jo, GetWhoIsJob::DeviceInfo& result) |
| 108 | { |
| 109 | fillFromJson(jv: jo.value(key: "sessions"_ls ), pod&: result.sessions); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | } // namespace Quotient |
| 114 | |