1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/
#include "keys.h"
#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
class UploadKeysJob::Private
{
public:
QHash<QString, int> oneTimeKeyCounts;
};
UploadKeysJob::UploadKeysJob(const Omittable<DeviceKeys>& deviceKeys, const QHash<QString, QVariant>& oneTimeKeys)
: BaseJob(HttpVerb::Post, "UploadKeysJob",
basePath % "/keys/upload")
, d(new Private)
{
QJsonObject _data;
addParam<IfNotEmpty>(_data, "device_keys", deviceKeys);
addParam<IfNotEmpty>(_data, "one_time_keys", oneTimeKeys);
setRequestData(_data);
}
UploadKeysJob::~UploadKeysJob() = default;
const QHash<QString, int>& UploadKeysJob::oneTimeKeyCounts() const
{
return d->oneTimeKeyCounts;
}
BaseJob::Status UploadKeysJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
if (!json.contains("one_time_key_counts"))
return { JsonParseError,
"The key 'one_time_key_counts' not found in the response" };
d->oneTimeKeyCounts = fromJson<QHash<QString, int>>(json.value("one_time_key_counts"));
return Success;
}
namespace QMatrixClient
{
// Converters
template <> struct FromJson<QueryKeysJob::UnsignedDeviceInfo>
{
QueryKeysJob::UnsignedDeviceInfo operator()(const QJsonValue& jv)
{
const auto& _json = jv.toObject();
QueryKeysJob::UnsignedDeviceInfo result;
result.deviceDisplayName =
fromJson<QString>(_json.value("device_display_name"));
return result;
}
};
template <> struct FromJson<QueryKeysJob::DeviceInformation>
{
QueryKeysJob::DeviceInformation operator()(const QJsonValue& jv)
{
const auto& _json = jv.toObject();
QueryKeysJob::DeviceInformation result;
result.unsignedData =
fromJson<QueryKeysJob::UnsignedDeviceInfo>(_json.value("unsigned"));
return result;
}
};
} // namespace QMatrixClient
class QueryKeysJob::Private
{
public:
QHash<QString, QJsonObject> failures;
QHash<QString, QHash<QString, DeviceInformation>> deviceKeys;
};
QueryKeysJob::QueryKeysJob(const QHash<QString, QStringList>& deviceKeys, Omittable<int> timeout, const QString& token)
: BaseJob(HttpVerb::Post, "QueryKeysJob",
basePath % "/keys/query")
, d(new Private)
{
QJsonObject _data;
addParam<IfNotEmpty>(_data, "timeout", timeout);
addParam<>(_data, "device_keys", deviceKeys);
addParam<IfNotEmpty>(_data, "token", token);
setRequestData(_data);
}
QueryKeysJob::~QueryKeysJob() = default;
const QHash<QString, QJsonObject>& QueryKeysJob::failures() const
{
return d->failures;
}
const QHash<QString, QHash<QString, QueryKeysJob::DeviceInformation>>& QueryKeysJob::deviceKeys() const
{
return d->deviceKeys;
}
BaseJob::Status QueryKeysJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures"));
d->deviceKeys = fromJson<QHash<QString, QHash<QString, DeviceInformation>>>(json.value("device_keys"));
return Success;
}
class ClaimKeysJob::Private
{
public:
QHash<QString, QJsonObject> failures;
QHash<QString, QHash<QString, QVariant>> oneTimeKeys;
};
ClaimKeysJob::ClaimKeysJob(const QHash<QString, QHash<QString, QString>>& oneTimeKeys, Omittable<int> timeout)
: BaseJob(HttpVerb::Post, "ClaimKeysJob",
basePath % "/keys/claim")
, d(new Private)
{
QJsonObject _data;
addParam<IfNotEmpty>(_data, "timeout", timeout);
addParam<>(_data, "one_time_keys", oneTimeKeys);
setRequestData(_data);
}
ClaimKeysJob::~ClaimKeysJob() = default;
const QHash<QString, QJsonObject>& ClaimKeysJob::failures() const
{
return d->failures;
}
const QHash<QString, QHash<QString, QVariant>>& ClaimKeysJob::oneTimeKeys() const
{
return d->oneTimeKeys;
}
BaseJob::Status ClaimKeysJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures"));
d->oneTimeKeys = fromJson<QHash<QString, QHash<QString, QVariant>>>(json.value("one_time_keys"));
return Success;
}
class GetKeysChangesJob::Private
{
public:
QStringList changed;
QStringList left;
};
BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to)
{
BaseJob::Query _q;
addParam<>(_q, "from", from);
addParam<>(_q, "to", to);
return _q;
}
QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from, const QString& to)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
basePath % "/keys/changes",
queryToGetKeysChanges(from, to));
}
GetKeysChangesJob::GetKeysChangesJob(const QString& from, const QString& to)
: BaseJob(HttpVerb::Get, "GetKeysChangesJob",
basePath % "/keys/changes",
queryToGetKeysChanges(from, to))
, d(new Private)
{
}
GetKeysChangesJob::~GetKeysChangesJob() = default;
const QStringList& GetKeysChangesJob::changed() const
{
return d->changed;
}
const QStringList& GetKeysChangesJob::left() const
{
return d->left;
}
BaseJob::Status GetKeysChangesJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
d->changed = fromJson<QStringList>(json.value("changed"));
d->left = fromJson<QStringList>(json.value("left"));
return Success;
}
|