aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/search.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/search.cpp')
-rw-r--r--lib/csapi/search.cpp93
1 files changed, 47 insertions, 46 deletions
diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp
index a5f83c79..22aaf616 100644
--- a/lib/csapi/search.cpp
+++ b/lib/csapi/search.cpp
@@ -12,70 +12,73 @@ using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
-namespace QMatrixClient
-{
+namespace QMatrixClient {
// Converters
- template <> struct JsonObjectConverter<SearchJob::IncludeEventContext>
- {
- static void dumpTo(QJsonObject& jo, const SearchJob::IncludeEventContext& pod)
+ template <> struct JsonObjectConverter<SearchJob::IncludeEventContext> {
+ static void dumpTo(QJsonObject& jo,
+ const SearchJob::IncludeEventContext& pod)
{
- addParam<IfNotEmpty>(jo, QStringLiteral("before_limit"), pod.beforeLimit);
- addParam<IfNotEmpty>(jo, QStringLiteral("after_limit"), pod.afterLimit);
- addParam<IfNotEmpty>(jo, QStringLiteral("include_profile"), pod.includeProfile);
+ addParam<IfNotEmpty>(jo, QStringLiteral("before_limit"),
+ pod.beforeLimit);
+ addParam<IfNotEmpty>(jo, QStringLiteral("after_limit"),
+ pod.afterLimit);
+ addParam<IfNotEmpty>(jo, QStringLiteral("include_profile"),
+ pod.includeProfile);
}
};
- template <> struct JsonObjectConverter<SearchJob::Group>
- {
+ template <> struct JsonObjectConverter<SearchJob::Group> {
static void dumpTo(QJsonObject& jo, const SearchJob::Group& pod)
{
addParam<IfNotEmpty>(jo, QStringLiteral("key"), pod.key);
}
};
- template <> struct JsonObjectConverter<SearchJob::Groupings>
- {
+ template <> struct JsonObjectConverter<SearchJob::Groupings> {
static void dumpTo(QJsonObject& jo, const SearchJob::Groupings& pod)
{
addParam<IfNotEmpty>(jo, QStringLiteral("group_by"), pod.groupBy);
}
};
- template <> struct JsonObjectConverter<SearchJob::RoomEventsCriteria>
- {
- static void dumpTo(QJsonObject& jo, const SearchJob::RoomEventsCriteria& pod)
+ template <> struct JsonObjectConverter<SearchJob::RoomEventsCriteria> {
+ static void dumpTo(QJsonObject& jo,
+ const SearchJob::RoomEventsCriteria& pod)
{
addParam<>(jo, QStringLiteral("search_term"), pod.searchTerm);
addParam<IfNotEmpty>(jo, QStringLiteral("keys"), pod.keys);
addParam<IfNotEmpty>(jo, QStringLiteral("filter"), pod.filter);
addParam<IfNotEmpty>(jo, QStringLiteral("order_by"), pod.orderBy);
- addParam<IfNotEmpty>(jo, QStringLiteral("event_context"), pod.eventContext);
- addParam<IfNotEmpty>(jo, QStringLiteral("include_state"), pod.includeState);
- addParam<IfNotEmpty>(jo, QStringLiteral("groupings"), pod.groupings);
+ addParam<IfNotEmpty>(jo, QStringLiteral("event_context"),
+ pod.eventContext);
+ addParam<IfNotEmpty>(jo, QStringLiteral("include_state"),
+ pod.includeState);
+ addParam<IfNotEmpty>(jo, QStringLiteral("groupings"),
+ pod.groupings);
}
};
- template <> struct JsonObjectConverter<SearchJob::Categories>
- {
+ template <> struct JsonObjectConverter<SearchJob::Categories> {
static void dumpTo(QJsonObject& jo, const SearchJob::Categories& pod)
{
- addParam<IfNotEmpty>(jo, QStringLiteral("room_events"), pod.roomEvents);
+ addParam<IfNotEmpty>(jo, QStringLiteral("room_events"),
+ pod.roomEvents);
}
};
- template <> struct JsonObjectConverter<SearchJob::UserProfile>
- {
- static void fillFrom(const QJsonObject& jo, SearchJob::UserProfile& result)
+ template <> struct JsonObjectConverter<SearchJob::UserProfile> {
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::UserProfile& result)
{
fromJson(jo.value("displayname"_ls), result.displayname);
fromJson(jo.value("avatar_url"_ls), result.avatarUrl);
}
};
- template <> struct JsonObjectConverter<SearchJob::EventContext>
- {
- static void fillFrom(const QJsonObject& jo, SearchJob::EventContext& result)
+ template <> struct JsonObjectConverter<SearchJob::EventContext> {
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::EventContext& result)
{
fromJson(jo.value("start"_ls), result.begin);
fromJson(jo.value("end"_ls), result.end);
@@ -85,8 +88,7 @@ namespace QMatrixClient
}
};
- template <> struct JsonObjectConverter<SearchJob::Result>
- {
+ template <> struct JsonObjectConverter<SearchJob::Result> {
static void fillFrom(const QJsonObject& jo, SearchJob::Result& result)
{
fromJson(jo.value("rank"_ls), result.rank);
@@ -95,9 +97,9 @@ namespace QMatrixClient
}
};
- template <> struct JsonObjectConverter<SearchJob::GroupValue>
- {
- static void fillFrom(const QJsonObject& jo, SearchJob::GroupValue& result)
+ template <> struct JsonObjectConverter<SearchJob::GroupValue> {
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::GroupValue& result)
{
fromJson(jo.value("next_batch"_ls), result.nextBatch);
fromJson(jo.value("order"_ls), result.order);
@@ -105,9 +107,9 @@ namespace QMatrixClient
}
};
- template <> struct JsonObjectConverter<SearchJob::ResultRoomEvents>
- {
- static void fillFrom(const QJsonObject& jo, SearchJob::ResultRoomEvents& result)
+ template <> struct JsonObjectConverter<SearchJob::ResultRoomEvents> {
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::ResultRoomEvents& result)
{
fromJson(jo.value("count"_ls), result.count);
fromJson(jo.value("highlights"_ls), result.highlights);
@@ -118,9 +120,9 @@ namespace QMatrixClient
}
};
- template <> struct JsonObjectConverter<SearchJob::ResultCategories>
- {
- static void fillFrom(const QJsonObject& jo, SearchJob::ResultCategories& result)
+ template <> struct JsonObjectConverter<SearchJob::ResultCategories> {
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::ResultCategories& result)
{
fromJson(jo.value("room_events"_ls), result.roomEvents);
}
@@ -130,7 +132,7 @@ namespace QMatrixClient
class SearchJob::Private
{
public:
- ResultCategories searchCategories;
+ ResultCategories searchCategories;
};
BaseJob::Query queryToSearch(const QString& nextBatch)
@@ -142,11 +144,11 @@ BaseJob::Query queryToSearch(const QString& nextBatch)
static const auto SearchJobName = QStringLiteral("SearchJob");
-SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatch)
- : BaseJob(HttpVerb::Post, SearchJobName,
- basePath % "/search",
- queryToSearch(nextBatch))
- , d(new Private)
+SearchJob::SearchJob(const Categories& searchCategories,
+ const QString& nextBatch)
+ : BaseJob(HttpVerb::Post, SearchJobName, basePath % "/search",
+ queryToSearch(nextBatch)),
+ d(new Private)
{
QJsonObject _data;
addParam<>(_data, QStringLiteral("search_categories"), searchCategories);
@@ -165,8 +167,7 @@ BaseJob::Status SearchJob::parseJson(const QJsonDocument& data)
auto json = data.object();
if (!json.contains("search_categories"_ls))
return { JsonParseError,
- "The key 'search_categories' not found in the response" };
+ "The key 'search_categories' not found in the response" };
fromJson(json.value("search_categories"_ls), d->searchCategories);
return Success;
}
-