aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/search.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-02 17:58:34 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 20:13:43 +0900
commit3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee (patch)
treea647fa5328e04b20a84e46d29d420555d9c56cde /lib/csapi/search.cpp
parented467d27b07781fdd2f7ddef043568954ce50b69 (diff)
downloadlibquotient-3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee.tar.gz
libquotient-3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee.zip
Use QStringLiteral() and operator"" _ls() in network jobs
Diffstat (limited to 'lib/csapi/search.cpp')
-rw-r--r--lib/csapi/search.cpp76
1 files changed, 39 insertions, 37 deletions
diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp
index 75748b38..f3adb315 100644
--- a/lib/csapi/search.cpp
+++ b/lib/csapi/search.cpp
@@ -19,43 +19,43 @@ namespace QMatrixClient
QJsonObject toJson(const SearchJob::IncludeEventContext& pod)
{
QJsonObject _json;
- addParam<IfNotEmpty>(_json, "before_limit", pod.beforeLimit);
- addParam<IfNotEmpty>(_json, "after_limit", pod.afterLimit);
- addParam<IfNotEmpty>(_json, "include_profile", pod.includeProfile);
+ addParam<IfNotEmpty>(_json, QStringLiteral("before_limit"), pod.beforeLimit);
+ addParam<IfNotEmpty>(_json, QStringLiteral("after_limit"), pod.afterLimit);
+ addParam<IfNotEmpty>(_json, QStringLiteral("include_profile"), pod.includeProfile);
return _json;
}
QJsonObject toJson(const SearchJob::Group& pod)
{
QJsonObject _json;
- addParam<IfNotEmpty>(_json, "key", pod.key);
+ addParam<IfNotEmpty>(_json, QStringLiteral("key"), pod.key);
return _json;
}
QJsonObject toJson(const SearchJob::Groupings& pod)
{
QJsonObject _json;
- addParam<IfNotEmpty>(_json, "group_by", pod.groupBy);
+ addParam<IfNotEmpty>(_json, QStringLiteral("group_by"), pod.groupBy);
return _json;
}
QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod)
{
QJsonObject _json;
- addParam<>(_json, "search_term", pod.searchTerm);
- addParam<IfNotEmpty>(_json, "keys", pod.keys);
- addParam<IfNotEmpty>(_json, "filter", pod.filter);
- addParam<IfNotEmpty>(_json, "order_by", pod.orderBy);
- addParam<IfNotEmpty>(_json, "event_context", pod.eventContext);
- addParam<IfNotEmpty>(_json, "include_state", pod.includeState);
- addParam<IfNotEmpty>(_json, "groupings", pod.groupings);
+ addParam<>(_json, QStringLiteral("search_term"), pod.searchTerm);
+ addParam<IfNotEmpty>(_json, QStringLiteral("keys"), pod.keys);
+ addParam<IfNotEmpty>(_json, QStringLiteral("filter"), pod.filter);
+ addParam<IfNotEmpty>(_json, QStringLiteral("order_by"), pod.orderBy);
+ addParam<IfNotEmpty>(_json, QStringLiteral("event_context"), pod.eventContext);
+ addParam<IfNotEmpty>(_json, QStringLiteral("include_state"), pod.includeState);
+ addParam<IfNotEmpty>(_json, QStringLiteral("groupings"), pod.groupings);
return _json;
}
QJsonObject toJson(const SearchJob::Categories& pod)
{
QJsonObject _json;
- addParam<IfNotEmpty>(_json, "room_events", pod.roomEvents);
+ addParam<IfNotEmpty>(_json, QStringLiteral("room_events"), pod.roomEvents);
return _json;
}
@@ -66,9 +66,9 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::UserProfile result;
result.displayname =
- fromJson<QString>(_json.value("displayname"));
+ fromJson<QString>(_json.value("displayname"_ls));
result.avatarUrl =
- fromJson<QString>(_json.value("avatar_url"));
+ fromJson<QString>(_json.value("avatar_url"_ls));
return result;
}
@@ -81,15 +81,15 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::EventContext result;
result.begin =
- fromJson<QString>(_json.value("start"));
+ fromJson<QString>(_json.value("start"_ls));
result.end =
- fromJson<QString>(_json.value("end"));
+ fromJson<QString>(_json.value("end"_ls));
result.profileInfo =
- fromJson<QHash<QString, SearchJob::UserProfile>>(_json.value("profile_info"));
+ fromJson<QHash<QString, SearchJob::UserProfile>>(_json.value("profile_info"_ls));
result.eventsBefore =
- fromJson<RoomEvents>(_json.value("events_before"));
+ fromJson<RoomEvents>(_json.value("events_before"_ls));
result.eventsAfter =
- fromJson<RoomEvents>(_json.value("events_after"));
+ fromJson<RoomEvents>(_json.value("events_after"_ls));
return result;
}
@@ -102,11 +102,11 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::Result result;
result.rank =
- fromJson<double>(_json.value("rank"));
+ fromJson<double>(_json.value("rank"_ls));
result.result =
- fromJson<RoomEventPtr>(_json.value("result"));
+ fromJson<RoomEventPtr>(_json.value("result"_ls));
result.context =
- fromJson<SearchJob::EventContext>(_json.value("context"));
+ fromJson<SearchJob::EventContext>(_json.value("context"_ls));
return result;
}
@@ -119,11 +119,11 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::GroupValue result;
result.nextBatch =
- fromJson<QString>(_json.value("next_batch"));
+ fromJson<QString>(_json.value("next_batch"_ls));
result.order =
- fromJson<int>(_json.value("order"));
+ fromJson<int>(_json.value("order"_ls));
result.results =
- fromJson<QStringList>(_json.value("results"));
+ fromJson<QStringList>(_json.value("results"_ls));
return result;
}
@@ -136,15 +136,15 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::ResultRoomEvents result;
result.count =
- fromJson<qint64>(_json.value("count"));
+ fromJson<qint64>(_json.value("count"_ls));
result.results =
- fromJson<std::vector<SearchJob::Result>>(_json.value("results"));
+ fromJson<std::vector<SearchJob::Result>>(_json.value("results"_ls));
result.state =
- fromJson<std::unordered_map<QString, StateEvents>>(_json.value("state"));
+ fromJson<std::unordered_map<QString, StateEvents>>(_json.value("state"_ls));
result.groups =
- fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(_json.value("groups"));
+ fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(_json.value("groups"_ls));
result.nextBatch =
- fromJson<QString>(_json.value("next_batch"));
+ fromJson<QString>(_json.value("next_batch"_ls));
return result;
}
@@ -157,7 +157,7 @@ namespace QMatrixClient
const auto& _json = jv.toObject();
SearchJob::ResultCategories result;
result.roomEvents =
- fromJson<SearchJob::ResultRoomEvents>(_json.value("room_events"));
+ fromJson<SearchJob::ResultRoomEvents>(_json.value("room_events"_ls));
return result;
}
@@ -173,18 +173,20 @@ class SearchJob::Private
BaseJob::Query queryToSearch(const QString& nextBatch)
{
BaseJob::Query _q;
- addParam<IfNotEmpty>(_q, "next_batch", nextBatch);
+ addParam<IfNotEmpty>(_q, QStringLiteral("next_batch"), nextBatch);
return _q;
}
+static const auto SearchJobName = QStringLiteral("SearchJob");
+
SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatch)
- : BaseJob(HttpVerb::Post, "SearchJob",
+ : BaseJob(HttpVerb::Post, SearchJobName,
basePath % "/search",
queryToSearch(nextBatch))
, d(new Private)
{
QJsonObject _data;
- addParam<>(_data, "search_categories", searchCategories);
+ addParam<>(_data, QStringLiteral("search_categories"), searchCategories);
setRequestData(_data);
}
@@ -198,10 +200,10 @@ const SearchJob::ResultCategories& SearchJob::searchCategories() const
BaseJob::Status SearchJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
- if (!json.contains("search_categories"))
+ if (!json.contains("search_categories"_ls))
return { JsonParseError,
"The key 'search_categories' not found in the response" };
- d->searchCategories = fromJson<ResultCategories>(json.value("search_categories"));
+ d->searchCategories = fromJson<ResultCategories>(json.value("search_categories"_ls));
return Success;
}