libQuotient
A Qt library for building matrix clients
protocol.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/converters.h>
6 
7 namespace Quotient {
8 //! Definition of valid values for a field.
9 struct QUOTIENT_API FieldType {
10  //! A regular expression for validation of a field's value. This may be relatively
11  //! coarse to verify the value as the application service providing this protocol
12  //! may apply additional validation or filtering.
13  QString regexp;
14 
15  //! A placeholder serving as a valid example of the field value.
16  QString placeholder;
17 };
18 
19 template <>
20 struct JsonObjectConverter<FieldType> {
21  static void dumpTo(QJsonObject& jo, const FieldType& pod)
22  {
23  addParam<>(jo, "regexp"_L1, pod.regexp);
24  addParam<>(jo, "placeholder"_L1, pod.placeholder);
25  }
26  static void fillFrom(const QJsonObject& jo, FieldType& pod)
27  {
28  fillFromJson(jo.value("regexp"_L1), pod.regexp);
29  fillFromJson(jo.value("placeholder"_L1), pod.placeholder);
30  }
31 };
32 
33 struct QUOTIENT_API ProtocolInstance {
34  //! A human-readable description for the protocol, such as the name.
35  QString desc;
36 
37  //! Preset values for `fields` the client may use to search by.
38  QJsonObject fields;
39 
40  //! A unique identifier across all instances.
41  QString networkId;
42 
43  //! An optional content URI representing the protocol. Overrides the one provided
44  //! at the higher level Protocol object.
45  QString icon{};
46 };
47 
48 template <>
49 struct JsonObjectConverter<ProtocolInstance> {
50  static void dumpTo(QJsonObject& jo, const ProtocolInstance& pod)
51  {
52  addParam<>(jo, "desc"_L1, pod.desc);
53  addParam<>(jo, "fields"_L1, pod.fields);
54  addParam<>(jo, "network_id"_L1, pod.networkId);
55  addParam<IfNotEmpty>(jo, "icon"_L1, pod.icon);
56  }
57  static void fillFrom(const QJsonObject& jo, ProtocolInstance& pod)
58  {
59  fillFromJson(jo.value("desc"_L1), pod.desc);
60  fillFromJson(jo.value("fields"_L1), pod.fields);
61  fillFromJson(jo.value("network_id"_L1), pod.networkId);
62  fillFromJson(jo.value("icon"_L1), pod.icon);
63  }
64 };
65 
66 struct QUOTIENT_API ThirdPartyProtocol {
67  //! Fields which may be used to identify a third-party user. These should be
68  //! ordered to suggest the way that entities may be grouped, where higher
69  //! groupings are ordered first. For example, the name of a network should be
70  //! searched before the nickname of a user.
71  QStringList userFields;
72 
73  //! Fields which may be used to identify a third-party location. These should be
74  //! ordered to suggest the way that entities may be grouped, where higher
75  //! groupings are ordered first. For example, the name of a network should be
76  //! searched before the name of a channel.
77  QStringList locationFields;
78 
79  //! A content URI representing an icon for the third-party protocol.
80  QString icon;
81 
82  //! The type definitions for the fields defined in `user_fields` and
83  //! `location_fields`. Each entry in those arrays MUST have an entry here.
84  //! The `string` key for this object is the field name itself.
85  //!
86  //! May be an empty object if no fields are defined.
87  QHash<QString, FieldType> fieldTypes;
88 
89  //! A list of objects representing independent instances of configuration.
90  //! For example, multiple networks on IRC if multiple are provided by the
91  //! same application service.
92  QVector<ProtocolInstance> instances;
93 };
94 
95 template <>
96 struct JsonObjectConverter<ThirdPartyProtocol> {
97  static void dumpTo(QJsonObject& jo, const ThirdPartyProtocol& pod)
98  {
99  addParam<>(jo, "user_fields"_L1, pod.userFields);
100  addParam<>(jo, "location_fields"_L1, pod.locationFields);
101  addParam<>(jo, "icon"_L1, pod.icon);
102  addParam<>(jo, "field_types"_L1, pod.fieldTypes);
103  addParam<>(jo, "instances"_L1, pod.instances);
104  }
105  static void fillFrom(const QJsonObject& jo, ThirdPartyProtocol& pod)
106  {
107  fillFromJson(jo.value("user_fields"_L1), pod.userFields);
108  fillFromJson(jo.value("location_fields"_L1), pod.locationFields);
109  fillFromJson(jo.value("icon"_L1), pod.icon);
110  fillFromJson(jo.value("field_types"_L1), pod.fieldTypes);
111  fillFromJson(jo.value("instances"_L1), pod.instances);
112  }
113 };
114 
115 } // namespace Quotient