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.cpp227
1 files changed, 123 insertions, 104 deletions
diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp
index ad2c34a3..ee1fa70c 100644
--- a/lib/csapi/search.cpp
+++ b/lib/csapi/search.cpp
@@ -12,125 +12,144 @@ using namespace QMatrixClient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
+// Converters
namespace QMatrixClient
{
- // Converters
- template <> struct JsonObjectConverter<SearchJob::IncludeEventContext>
+template <>
+struct JsonObjectConverter<SearchJob::IncludeEventContext>
+{
+ static void dumpTo(QJsonObject& jo,
+ const SearchJob::IncludeEventContext& pod)
{
- 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);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::Group>
+ 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>
+{
+ static void dumpTo(QJsonObject& jo, const SearchJob::Group& pod)
{
- static void dumpTo(QJsonObject& jo, const SearchJob::Group& pod)
- {
- addParam<IfNotEmpty>(jo, QStringLiteral("key"), pod.key);
- }
- };
+ 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)
{
- static void dumpTo(QJsonObject& jo, const SearchJob::Groupings& pod)
- {
- addParam<IfNotEmpty>(jo, QStringLiteral("group_by"), pod.groupBy);
- }
- };
+ addParam<IfNotEmpty>(jo, QStringLiteral("group_by"), pod.groupBy);
+ }
+};
- template <> struct JsonObjectConverter<SearchJob::RoomEventsCriteria>
+template <>
+struct JsonObjectConverter<SearchJob::RoomEventsCriteria>
+{
+ static void dumpTo(QJsonObject& jo, const SearchJob::RoomEventsCriteria& pod)
{
- 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);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::Categories>
+ 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);
+ }
+};
+
+template <>
+struct JsonObjectConverter<SearchJob::Categories>
+{
+ static void dumpTo(QJsonObject& jo, const SearchJob::Categories& pod)
{
- 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>
+template <>
+struct JsonObjectConverter<SearchJob::UserProfile>
+{
+ static void fillFrom(const QJsonObject& jo, SearchJob::UserProfile& result)
{
- 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>
+ 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)
{
- static void fillFrom(const QJsonObject& jo, SearchJob::EventContext& result)
- {
- fromJson(jo.value("start"_ls), result.begin);
- fromJson(jo.value("end"_ls), result.end);
- fromJson(jo.value("profile_info"_ls), result.profileInfo);
- fromJson(jo.value("events_before"_ls), result.eventsBefore);
- fromJson(jo.value("events_after"_ls), result.eventsAfter);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::Result>
+ fromJson(jo.value("start"_ls), result.begin);
+ fromJson(jo.value("end"_ls), result.end);
+ fromJson(jo.value("profile_info"_ls), result.profileInfo);
+ fromJson(jo.value("events_before"_ls), result.eventsBefore);
+ fromJson(jo.value("events_after"_ls), result.eventsAfter);
+ }
+};
+
+template <>
+struct JsonObjectConverter<SearchJob::Result>
+{
+ static void fillFrom(const QJsonObject& jo, SearchJob::Result& result)
{
- static void fillFrom(const QJsonObject& jo, SearchJob::Result& result)
- {
- fromJson(jo.value("rank"_ls), result.rank);
- fromJson(jo.value("result"_ls), result.result);
- fromJson(jo.value("context"_ls), result.context);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::GroupValue>
+ fromJson(jo.value("rank"_ls), result.rank);
+ fromJson(jo.value("result"_ls), result.result);
+ fromJson(jo.value("context"_ls), result.context);
+ }
+};
+
+template <>
+struct JsonObjectConverter<SearchJob::GroupValue>
+{
+ static void fillFrom(const QJsonObject& jo, SearchJob::GroupValue& result)
{
- static void fillFrom(const QJsonObject& jo, SearchJob::GroupValue& result)
- {
- fromJson(jo.value("next_batch"_ls), result.nextBatch);
- fromJson(jo.value("order"_ls), result.order);
- fromJson(jo.value("results"_ls), result.results);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::ResultRoomEvents>
+ fromJson(jo.value("next_batch"_ls), result.nextBatch);
+ fromJson(jo.value("order"_ls), result.order);
+ fromJson(jo.value("results"_ls), result.results);
+ }
+};
+
+template <>
+struct JsonObjectConverter<SearchJob::ResultRoomEvents>
+{
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::ResultRoomEvents& result)
{
- static void fillFrom(const QJsonObject& jo, SearchJob::ResultRoomEvents& result)
- {
- fromJson(jo.value("count"_ls), result.count);
- fromJson(jo.value("highlights"_ls), result.highlights);
- fromJson(jo.value("results"_ls), result.results);
- fromJson(jo.value("state"_ls), result.state);
- fromJson(jo.value("groups"_ls), result.groups);
- fromJson(jo.value("next_batch"_ls), result.nextBatch);
- }
- };
-
- template <> struct JsonObjectConverter<SearchJob::ResultCategories>
+ fromJson(jo.value("count"_ls), result.count);
+ fromJson(jo.value("highlights"_ls), result.highlights);
+ fromJson(jo.value("results"_ls), result.results);
+ fromJson(jo.value("state"_ls), result.state);
+ fromJson(jo.value("groups"_ls), result.groups);
+ fromJson(jo.value("next_batch"_ls), result.nextBatch);
+ }
+};
+
+template <>
+struct JsonObjectConverter<SearchJob::ResultCategories>
+{
+ static void fillFrom(const QJsonObject& jo,
+ SearchJob::ResultCategories& result)
{
- static void fillFrom(const QJsonObject& jo, SearchJob::ResultCategories& result)
- {
- fromJson(jo.value("room_events"_ls), result.roomEvents);
- }
- };
+ fromJson(jo.value("room_events"_ls), result.roomEvents);
+ }
+};
+
} // namespace QMatrixClient
class SearchJob::Private
{
- public:
- ResultCategories searchCategories;
+public:
+ ResultCategories searchCategories;
};
BaseJob::Query queryToSearch(const QString& nextBatch)
@@ -142,10 +161,10 @@ 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))
+SearchJob::SearchJob(const Categories& searchCategories,
+ const QString& nextBatch)
+ : BaseJob(HttpVerb::Post, SearchJobName, basePath % "/search",
+ queryToSearch(nextBatch))
, d(new Private)
{
QJsonObject _data;
@@ -165,8 +184,8 @@ BaseJob::Status SearchJob::parseJson(const QJsonDocument& data)
auto json = data.object();
if (!json.contains("search_categories"_ls))
return { IncorrectResponse,
- "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;
}
-