5 #include <Quotient/csapi/definitions/room_event_filter.h>
7 #include <Quotient/events/roomevent.h>
8 #include <Quotient/events/stateevent.h>
9 #include <Quotient/jobs/basejob.h>
25 std::optional<
int> beforeLimit{};
29 std::optional<
int> afterLimit{};
35 std::optional<
bool> includeProfile{};
48 QVector<Group> groupBy{};
60 RoomEventFilter filter{};
68 std::optional<IncludeEventContext> eventContext{};
72 std::optional<
bool> includeState{};
76 std::optional<Groupings> groupings{};
82 std::optional<RoomEventsCriteria> roomEvents{};
86 QString displayname{};
104 QHash<UserId, UserProfile> profileInfo{};
107 RoomEvents eventsBefore{};
110 RoomEvents eventsAfter{};
116 std::optional<
double> rank{};
119 RoomEventPtr result{};
122 std::optional<EventContext> context{};
136 std::optional<
int> order{};
139 QStringList results{};
145 std::optional<
int> count{};
149 QStringList highlights{};
152 std::vector<Result> results{};
160 std::unordered_map<RoomId, StateEvents> state{};
167 QHash<QString, QHash<QString, GroupValue>> groups{};
179 std::optional<ResultRoomEvents> roomEvents{};
190 explicit SearchJob(
const Categories& searchCategories,
const QString& nextBatch = {});
195 ResultCategories searchCategories()
const
197 return loadFromJson<ResultCategories>(
"search_categories"_L1);
201 inline auto collectResponse(
const SearchJob* job) {
return job->searchCategories(); }
204 struct QUOTIENT_API JsonObjectConverter<SearchJob::IncludeEventContext> {
205 static void dumpTo(QJsonObject& jo,
const SearchJob::IncludeEventContext& pod)
207 addParam<IfNotEmpty>(jo,
"before_limit"_L1, pod.beforeLimit);
208 addParam<IfNotEmpty>(jo,
"after_limit"_L1, pod.afterLimit);
209 addParam<IfNotEmpty>(jo,
"include_profile"_L1, pod.includeProfile);
214 struct QUOTIENT_API JsonObjectConverter<SearchJob::Group> {
215 static void dumpTo(QJsonObject& jo,
const SearchJob::Group& pod)
217 addParam<IfNotEmpty>(jo,
"key"_L1, pod.key);
222 struct QUOTIENT_API JsonObjectConverter<SearchJob::Groupings> {
223 static void dumpTo(QJsonObject& jo,
const SearchJob::Groupings& pod)
225 addParam<IfNotEmpty>(jo,
"group_by"_L1, pod.groupBy);
230 struct QUOTIENT_API JsonObjectConverter<SearchJob::RoomEventsCriteria> {
231 static void dumpTo(QJsonObject& jo,
const SearchJob::RoomEventsCriteria& pod)
233 addParam<>(jo,
"search_term"_L1, pod.searchTerm);
234 addParam<IfNotEmpty>(jo,
"keys"_L1, pod.keys);
235 addParam<IfNotEmpty>(jo,
"filter"_L1, pod.filter);
236 addParam<IfNotEmpty>(jo,
"order_by"_L1, pod.orderBy);
237 addParam<IfNotEmpty>(jo,
"event_context"_L1, pod.eventContext);
238 addParam<IfNotEmpty>(jo,
"include_state"_L1, pod.includeState);
239 addParam<IfNotEmpty>(jo,
"groupings"_L1, pod.groupings);
244 struct QUOTIENT_API JsonObjectConverter<SearchJob::Categories> {
245 static void dumpTo(QJsonObject& jo,
const SearchJob::Categories& pod)
247 addParam<IfNotEmpty>(jo,
"room_events"_L1, pod.roomEvents);
252 struct QUOTIENT_API JsonObjectConverter<SearchJob::UserProfile> {
253 static void fillFrom(
const QJsonObject& jo, SearchJob::UserProfile& result)
255 fillFromJson(jo.value(
"displayname"_L1), result.displayname);
256 fillFromJson(jo.value(
"avatar_url"_L1), result.avatarUrl);
261 struct QUOTIENT_API JsonObjectConverter<SearchJob::EventContext> {
262 static void fillFrom(
const QJsonObject& jo, SearchJob::EventContext& result)
264 fillFromJson(jo.value(
"start"_L1), result.begin);
265 fillFromJson(jo.value(
"end"_L1), result.end);
266 fillFromJson(jo.value(
"profile_info"_L1), result.profileInfo);
267 fillFromJson(jo.value(
"events_before"_L1), result.eventsBefore);
268 fillFromJson(jo.value(
"events_after"_L1), result.eventsAfter);
273 struct QUOTIENT_API JsonObjectConverter<SearchJob::Result> {
274 static void fillFrom(
const QJsonObject& jo, SearchJob::Result& result)
276 fillFromJson(jo.value(
"rank"_L1), result.rank);
277 fillFromJson(jo.value(
"result"_L1), result.result);
278 fillFromJson(jo.value(
"context"_L1), result.context);
283 struct QUOTIENT_API JsonObjectConverter<SearchJob::GroupValue> {
284 static void fillFrom(
const QJsonObject& jo, SearchJob::GroupValue& result)
286 fillFromJson(jo.value(
"next_batch"_L1), result.nextBatch);
287 fillFromJson(jo.value(
"order"_L1), result.order);
288 fillFromJson(jo.value(
"results"_L1), result.results);
293 struct QUOTIENT_API JsonObjectConverter<SearchJob::ResultRoomEvents> {
294 static void fillFrom(
const QJsonObject& jo, SearchJob::ResultRoomEvents& result)
296 fillFromJson(jo.value(
"count"_L1), result.count);
297 fillFromJson(jo.value(
"highlights"_L1), result.highlights);
298 fillFromJson(jo.value(
"results"_L1), result.results);
299 fillFromJson(jo.value(
"state"_L1), result.state);
300 fillFromJson(jo.value(
"groups"_L1), result.groups);
301 fillFromJson(jo.value(
"next_batch"_L1), result.nextBatch);
306 struct QUOTIENT_API JsonObjectConverter<SearchJob::ResultCategories> {
307 static void fillFrom(
const QJsonObject& jo, SearchJob::ResultCategories& result)
309 fillFromJson(jo.value(
"room_events"_L1), result.roomEvents);