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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/
#include "list_public_rooms.h"
#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
class GetRoomVisibilityOnDirectoryJob::Private
{
public:
QString visibility;
};
QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString& roomId)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
basePath % "/directory/list/room/" % roomId);
}
GetRoomVisibilityOnDirectoryJob::GetRoomVisibilityOnDirectoryJob(const QString& roomId)
: BaseJob(HttpVerb::Get, "GetRoomVisibilityOnDirectoryJob",
basePath % "/directory/list/room/" % roomId, false)
, d(new Private)
{
}
GetRoomVisibilityOnDirectoryJob::~GetRoomVisibilityOnDirectoryJob() = default;
const QString& GetRoomVisibilityOnDirectoryJob::visibility() const
{
return d->visibility;
}
BaseJob::Status GetRoomVisibilityOnDirectoryJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
d->visibility = fromJson<QString>(json.value("visibility"));
return Success;
}
SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility)
: BaseJob(HttpVerb::Put, "SetRoomVisibilityOnDirectoryJob",
basePath % "/directory/list/room/" % roomId)
{
QJsonObject _data;
addToJson<IfNotEmpty>(_data, "visibility", visibility);
setRequestData(_data);
}
namespace QMatrixClient
{
// Converters
template <> struct FromJson<GetPublicRoomsJob::PublicRoomsChunk>
{
GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv)
{
const auto& _json = jv.toObject();
GetPublicRoomsJob::PublicRoomsChunk result;
result.aliases =
fromJson<QStringList>(_json.value("aliases"));
result.canonicalAlias =
fromJson<QString>(_json.value("canonical_alias"));
result.name =
fromJson<QString>(_json.value("name"));
result.numJoinedMembers =
fromJson<qint64>(_json.value("num_joined_members"));
result.roomId =
fromJson<QString>(_json.value("room_id"));
result.topic =
fromJson<QString>(_json.value("topic"));
result.worldReadable =
fromJson<bool>(_json.value("world_readable"));
result.guestCanJoin =
fromJson<bool>(_json.value("guest_can_join"));
result.avatarUrl =
fromJson<QString>(_json.value("avatar_url"));
return result;
}
};
} // namespace QMatrixClient
class GetPublicRoomsJob::Private
{
public:
QVector<PublicRoomsChunk> chunk;
QString nextBatch;
QString prevBatch;
qint64 totalRoomCountEstimate;
};
BaseJob::Query queryToGetPublicRooms(int limit, const QString& since, const QString& server)
{
BaseJob::Query _q;
_q.addQueryItem("limit", QString("%1").arg(limit));
if (!since.isEmpty())
_q.addQueryItem("since", since);
if (!server.isEmpty())
_q.addQueryItem("server", server);
return _q;
}
QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, int limit, const QString& since, const QString& server)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
basePath % "/publicRooms",
queryToGetPublicRooms(limit, since, server));
}
GetPublicRoomsJob::GetPublicRoomsJob(int limit, const QString& since, const QString& server)
: BaseJob(HttpVerb::Get, "GetPublicRoomsJob",
basePath % "/publicRooms",
queryToGetPublicRooms(limit, since, server),
{}, false)
, d(new Private)
{
}
GetPublicRoomsJob::~GetPublicRoomsJob() = default;
const QVector<GetPublicRoomsJob::PublicRoomsChunk>& GetPublicRoomsJob::chunk() const
{
return d->chunk;
}
const QString& GetPublicRoomsJob::nextBatch() const
{
return d->nextBatch;
}
const QString& GetPublicRoomsJob::prevBatch() const
{
return d->prevBatch;
}
qint64 GetPublicRoomsJob::totalRoomCountEstimate() const
{
return d->totalRoomCountEstimate;
}
BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
if (!json.contains("chunk"))
return { JsonParseError,
"The key 'chunk' not found in the response" };
d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk"));
d->nextBatch = fromJson<QString>(json.value("next_batch"));
d->prevBatch = fromJson<QString>(json.value("prev_batch"));
d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate"));
return Success;
}
namespace QMatrixClient
{
// Converters
QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod)
{
QJsonObject _json;
if (pod.omitted)
return _json;
addToJson<IfNotEmpty>(_json, "generic_search_term", pod.genericSearchTerm);
return _json;
}
template <> struct FromJson<QueryPublicRoomsJob::PublicRoomsChunk>
{
QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv)
{
const auto& _json = jv.toObject();
QueryPublicRoomsJob::PublicRoomsChunk result;
result.aliases =
fromJson<QStringList>(_json.value("aliases"));
result.canonicalAlias =
fromJson<QString>(_json.value("canonical_alias"));
result.name =
fromJson<QString>(_json.value("name"));
result.numJoinedMembers =
fromJson<qint64>(_json.value("num_joined_members"));
result.roomId =
fromJson<QString>(_json.value("room_id"));
result.topic =
fromJson<QString>(_json.value("topic"));
result.worldReadable =
fromJson<bool>(_json.value("world_readable"));
result.guestCanJoin =
fromJson<bool>(_json.value("guest_can_join"));
result.avatarUrl =
fromJson<QString>(_json.value("avatar_url"));
return result;
}
};
} // namespace QMatrixClient
class QueryPublicRoomsJob::Private
{
public:
QVector<PublicRoomsChunk> chunk;
QString nextBatch;
QString prevBatch;
qint64 totalRoomCountEstimate;
};
BaseJob::Query queryToQueryPublicRooms(const QString& server)
{
BaseJob::Query _q;
if (!server.isEmpty())
_q.addQueryItem("server", server);
return _q;
}
QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, int limit, const QString& since, const Filter& filter)
: BaseJob(HttpVerb::Post, "QueryPublicRoomsJob",
basePath % "/publicRooms",
queryToQueryPublicRooms(server))
, d(new Private)
{
QJsonObject _data;
addToJson<IfNotEmpty>(_data, "limit", limit);
addToJson<IfNotEmpty>(_data, "since", since);
addToJson<IfNotEmpty>(_data, "filter", filter);
setRequestData(_data);
}
QueryPublicRoomsJob::~QueryPublicRoomsJob() = default;
const QVector<QueryPublicRoomsJob::PublicRoomsChunk>& QueryPublicRoomsJob::chunk() const
{
return d->chunk;
}
const QString& QueryPublicRoomsJob::nextBatch() const
{
return d->nextBatch;
}
const QString& QueryPublicRoomsJob::prevBatch() const
{
return d->prevBatch;
}
qint64 QueryPublicRoomsJob::totalRoomCountEstimate() const
{
return d->totalRoomCountEstimate;
}
BaseJob::Status QueryPublicRoomsJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
if (!json.contains("chunk"))
return { JsonParseError,
"The key 'chunk' not found in the response" };
d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk"));
d->nextBatch = fromJson<QString>(json.value("next_batch"));
d->prevBatch = fromJson<QString>(json.value("prev_batch"));
d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate"));
return Success;
}
|