libQuotient
A Qt library for building matrix clients
capabilities.h
Go to the documentation of this file.
1 // THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2 
3 #pragma once
4 
5 #include <Quotient/jobs/basejob.h>
6 
7 namespace Quotient {
8 
9 struct QUOTIENT_API BooleanCapability {
10  //! True if the user can perform the action, false otherwise.
11  bool enabled;
12 };
13 
14 template <>
15 struct JsonObjectConverter<BooleanCapability> {
16  static void dumpTo(QJsonObject& jo, const BooleanCapability& pod)
17  {
18  addParam<>(jo, "enabled"_L1, pod.enabled);
19  }
20  static void fillFrom(const QJsonObject& jo, BooleanCapability& pod)
21  {
22  fillFromJson(jo.value("enabled"_L1), pod.enabled);
23  }
24 };
25 
26 //! \brief Gets information about the server's capabilities.
27 //!
28 //! Gets information about the server's supported feature set
29 //! and other relevant capabilities.
30 class QUOTIENT_API GetCapabilitiesJob : public BaseJob {
31 public:
32  // Inner data structures
33 
34  //! The room versions the server supports.
35  struct QUOTIENT_API RoomVersionsCapability {
36  //! The default room version the server is using for new rooms.
37  QString defaultVersion;
38 
39  //! A detailed description of the room versions the server supports.
40  QHash<QString, QString> available;
41  };
42 
43  //! The custom capabilities the server supports, using the
44  //! Java package naming convention.
45  struct QUOTIENT_API Capabilities {
46  //! Capability to indicate if the user can change their password.
47  std::optional<BooleanCapability> changePassword{};
48 
49  //! The room versions the server supports.
50  std::optional<RoomVersionsCapability> roomVersions{};
51 
52  //! Capability to indicate if the user can change their display name.
53  std::optional<BooleanCapability> setDisplayname{};
54 
55  //! Capability to indicate if the user can change their avatar.
56  std::optional<BooleanCapability> setAvatarUrl{};
57 
58  //! Capability to indicate if the user can change 3PID associations on their account.
59  std::optional<BooleanCapability> thirdPartyIdChanges{};
60 
61  //! Capability to indicate if the user can generate tokens to log further clients into their
62  //! account.
63  std::optional<BooleanCapability> getLoginToken{};
64 
65  //! Application-dependent keys using the
66  //! [Common Namespaced Identifier
67  //! Grammar](/appendices/#common-namespaced-identifier-grammar).
68  QVariantHash additionalProperties{};
69  };
70 
71  // Construction/destruction
72 
73  explicit GetCapabilitiesJob();
74 
75  //! \brief Construct a URL without creating a full-fledged job object
76  //!
77  //! This function can be used when a URL for GetCapabilitiesJob
78  //! is necessary but the job itself isn't.
79  static QUrl makeRequestUrl(const HomeserverData& hsData);
80 
81  // Result properties
82 
83  //! The custom capabilities the server supports, using the
84  //! Java package naming convention.
85  Capabilities capabilities() const { return loadFromJson<Capabilities>("capabilities"_L1); }
86 };
87 
88 inline auto collectResponse(const GetCapabilitiesJob* job) { return job->capabilities(); }
89 
90 template <>
91 struct QUOTIENT_API JsonObjectConverter<GetCapabilitiesJob::RoomVersionsCapability> {
92  static void fillFrom(const QJsonObject& jo, GetCapabilitiesJob::RoomVersionsCapability& result)
93  {
94  fillFromJson(jo.value("default"_L1), result.defaultVersion);
95  fillFromJson(jo.value("available"_L1), result.available);
96  }
97 };
98 
99 template <>
100 struct QUOTIENT_API JsonObjectConverter<GetCapabilitiesJob::Capabilities> {
101  static void fillFrom(QJsonObject jo, GetCapabilitiesJob::Capabilities& result)
102  {
103  fillFromJson(jo.take("m.change_password"_L1), result.changePassword);
104  fillFromJson(jo.take("m.room_versions"_L1), result.roomVersions);
105  fillFromJson(jo.take("m.set_displayname"_L1), result.setDisplayname);
106  fillFromJson(jo.take("m.set_avatar_url"_L1), result.setAvatarUrl);
107  fillFromJson(jo.take("m.3pid_changes"_L1), result.thirdPartyIdChanges);
108  fillFromJson(jo.take("m.get_login_token"_L1), result.getLoginToken);
109  fromJson(jo, result.additionalProperties);
110  }
111 };
112 
113 } // namespace Quotient