diff options
40 files changed, 270 insertions, 273 deletions
diff --git a/lib/converters.cpp b/lib/converters.cpp index f09fe5c2..41a9a65e 100644 --- a/lib/converters.cpp +++ b/lib/converters.cpp @@ -22,7 +22,7 @@ using namespace QMatrixClient; -QJsonValue QMatrixClient::toJson(const QVariant& v) +QJsonValue QMatrixClient::variantToJson(const QVariant& v) { return QJsonValue::fromVariant(v); } diff --git a/lib/converters.h b/lib/converters.h index 711d0a7c..7de33c9b 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -82,22 +82,20 @@ namespace QMatrixClient T& value() { return _value; } T&& release() { _omitted = true; return std::move(_value); } - operator bool() const { return !_omitted; } + operator bool() const { return !omitted(); } private: T _value; bool _omitted; }; - // This catches anything implicitly convertible to QJsonValue/Object/Array inline auto toJson(const QJsonValue& val) { return val; } inline auto toJson(const QJsonObject& o) { return o; } inline auto toJson(const QJsonArray& arr) { return arr; } // Special-case QStrings and bools to avoid ambiguity between QJsonValue - // and QVariant (also, QString.isEmpty() is used in _impl::AddNote<> below) + // and QVariant (also, QString.isEmpty() is used in _impl::AddNode<> below) inline auto toJson(const QString& s) { return s; } - inline QJsonValue toJson(bool b) { return b; } inline QJsonArray toJson(const QStringList& strings) { @@ -109,7 +107,18 @@ namespace QMatrixClient return bytes.constData(); } - QJsonValue toJson(const QVariant& v); + // QVariant is outrageously omnivorous - it consumes whatever is not + // exactly matching the signature of other toJson overloads. The trick + // below disables implicit conversion to QVariant through its numerous + // non-explicit constructors. + QJsonValue variantToJson(const QVariant& v); + template <typename T> + inline auto toJson(T&& var) + -> std::enable_if_t<std::is_same<std::decay_t<T>, QVariant>::value, + QJsonValue> + { + return variantToJson(var); + } QJsonObject toJson(const QMap<QString, QVariant>& map); #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) QJsonObject toJson(const QHash<QString, QVariant>& hMap); @@ -151,16 +160,6 @@ namespace QMatrixClient return json; } - template <typename T> - inline auto toJson(const Omittable<T>& omittable) - -> decltype(toJson(omittable.value())) - { - if (omittable) - return toJson(omittable.value()); - - return {}; - } - #if 0 template <typename T> inline auto toJson(const optional<T>& optVal) @@ -333,74 +332,72 @@ namespace QMatrixClient namespace _impl { + template <typename ValT> + inline void addTo(QJsonObject& o, const QString& k, ValT&& v) + { o.insert(k, toJson(v)); } + + template <typename ValT> + inline void addTo(QUrlQuery& q, const QString& k, ValT&& v) + { q.addQueryItem(k, QString("%1").arg(v)); } + + // OpenAPI is entirely JSON-based, which means representing bools as + // textual true/false, rather than 1/0. + template <typename ValT> + inline void addTo(QUrlQuery& q, const QString& k, bool v) + { + q.addQueryItem(k, v ? QStringLiteral("true") + : QStringLiteral("false")); + } + // This one is for types that don't have isEmpty() - template <typename InserterT, typename JsonT, typename = bool> + template <typename ValT, bool Force = true, typename = bool> struct AddNode { - static void impl(InserterT inserter, QString key, JsonT&& value) + template <typename ContT, typename ForwardedT> + static void impl(ContT& container, const QString& key, + ForwardedT&& value) { - inserter(std::move(key), std::forward<JsonT>(value)); + addTo(container, key, std::forward<ForwardedT>(value)); } }; // This one is for types that have isEmpty() - template <typename InserterT, typename JsonT> - struct AddNode<InserterT, JsonT, - decltype(std::declval<JsonT>().isEmpty())> + template <typename ValT> + struct AddNode<ValT, false, + decltype(std::declval<ValT>().isEmpty())> { - static void impl(InserterT inserter, QString key, JsonT&& value) + template <typename ContT, typename ForwardedT> + static void impl(ContT& container, const QString& key, + ForwardedT&& value) { if (!value.isEmpty()) - inserter(std::move(key), std::forward<JsonT>(value)); + AddNode<ValT>::impl(container, + key, std::forward<ForwardedT>(value)); } }; - template <bool Force, typename InserterT, typename ValT> - inline void maybeAdd(InserterT inserter, QString key, ValT&& value) + // This is a special one that unfolds Omittable<> + template <typename ValT, bool Force> + struct AddNode<Omittable<ValT>, Force> { - auto&& json = toJson(std::forward<ValT>(value)); - // QJsonValue doesn't have isEmpty and consumes all other types - // (QString, QJsonObject etc.). - AddNode<InserterT, - std::conditional_t<Force, QJsonValue, decltype(json)>> - ::impl(inserter, std::move(key), std::move(json)); - - } - + template <typename ContT, typename OmittableT> + static void impl(ContT& container, + const QString& key, const OmittableT& value) + { + if (!value.omitted()) + AddNode<ValT>::impl(container, key, value.value()); + else if (Force) // Edge case, no value but must put something + AddNode<ValT>::impl(container, key, QString{}); + } + }; } // namespace _impl static constexpr bool IfNotEmpty = false; - template <bool Force = true, typename ValT> - inline void addToJson(QJsonObject& o, QString key, ValT&& value) - { - using namespace std::placeholders; - _impl::maybeAdd<Force>(bind(&QJsonObject::insert, o, _1, _2), - key, value); - } - - template <bool Force = true, typename ValT> - inline void addToQuery(QUrlQuery& query, QString key, ValT&& value) + template <bool Force = true, typename ContT, typename ValT> + inline void addParam(ContT& container, const QString& key, ValT&& value) { - using namespace std::placeholders; - _impl::maybeAdd<Force>( - [&query] (QString k, auto&& jsonValue) { - query.addQueryItem(k, jsonValue.toString()); - }, key, value); + _impl::AddNode<std::decay_t<ValT>, Force> + ::impl(container, key, std::forward<ValT>(value)); } - - template <bool Force = true> - inline void addToQuery(QUrlQuery& query, QString key, QString value) - { - if (Force || !value.isEmpty()) - query.addQueryItem(key, value); - } - - template <bool Force = true> - inline void addToQuery(QUrlQuery& query, QString key, bool value) - { - query.addQueryItem(key, - value ? QStringLiteral("true") : QStringLiteral("false")); - } - } // namespace QMatrixClient diff --git a/lib/csapi/administrative_contact.cpp b/lib/csapi/administrative_contact.cpp index 14079179..e3dee8ed 100644 --- a/lib/csapi/administrative_contact.cpp +++ b/lib/csapi/administrative_contact.cpp @@ -72,9 +72,9 @@ namespace QMatrixClient QJsonObject toJson(const Post3PIDsJob::ThreePidCredentials& pod) { QJsonObject _json; - addToJson<>(_json, "client_secret", pod.clientSecret); - addToJson<>(_json, "id_server", pod.idServer); - addToJson<>(_json, "sid", pod.sid); + addParam<>(_json, "client_secret", pod.clientSecret); + addParam<>(_json, "id_server", pod.idServer); + addParam<>(_json, "sid", pod.sid); return _json; } } // namespace QMatrixClient @@ -84,8 +84,8 @@ Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind) basePath % "/account/3pid") { QJsonObject _data; - addToJson<>(_data, "three_pid_creds", threePidCreds); - addToJson<IfNotEmpty>(_data, "bind", bind); + addParam<>(_data, "three_pid_creds", threePidCreds); + addParam<IfNotEmpty>(_data, "bind", bind); setRequestData(_data); } diff --git a/lib/csapi/banning.cpp b/lib/csapi/banning.cpp index 5f1df39f..4dbd8a7d 100644 --- a/lib/csapi/banning.cpp +++ b/lib/csapi/banning.cpp @@ -17,8 +17,8 @@ BanJob::BanJob(const QString& roomId, const QString& userId, const QString& reas basePath % "/rooms/" % roomId % "/ban") { QJsonObject _data; - addToJson<>(_data, "user_id", userId); - addToJson<IfNotEmpty>(_data, "reason", reason); + addParam<>(_data, "user_id", userId); + addParam<IfNotEmpty>(_data, "reason", reason); setRequestData(_data); } @@ -27,7 +27,7 @@ UnbanJob::UnbanJob(const QString& roomId, const QString& userId) basePath % "/rooms/" % roomId % "/unban") { QJsonObject _data; - addToJson<>(_data, "user_id", userId); + addParam<>(_data, "user_id", userId); setRequestData(_data); } diff --git a/lib/csapi/content-repo.cpp b/lib/csapi/content-repo.cpp index 81329345..4ce80d08 100644 --- a/lib/csapi/content-repo.cpp +++ b/lib/csapi/content-repo.cpp @@ -22,7 +22,7 @@ class UploadContentJob::Private BaseJob::Query queryToUploadContent(const QString& filename) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "filename", filename); + addParam<IfNotEmpty>(_q, "filename", filename); return _q; } @@ -65,7 +65,7 @@ class GetContentJob::Private BaseJob::Query queryToGetContent(bool allowRemote) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); return _q; } @@ -122,7 +122,7 @@ class GetContentOverrideNameJob::Private BaseJob::Query queryToGetContentOverrideName(bool allowRemote) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); return _q; } @@ -175,24 +175,24 @@ class GetContentThumbnailJob::Private QIODevice* data; }; -BaseJob::Query queryToGetContentThumbnail(Omittable<int> width, Omittable<int> height, const QString& method, bool allowRemote) +BaseJob::Query queryToGetContentThumbnail(int width, int height, const QString& method, bool allowRemote) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "width", width); - addToQuery<IfNotEmpty>(_q, "height", height); - addToQuery<IfNotEmpty>(_q, "method", method); - addToQuery<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<>(_q, "width", width); + addParam<>(_q, "height", height); + addParam<IfNotEmpty>(_q, "method", method); + addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); return _q; } -QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, Omittable<int> width, Omittable<int> height, const QString& method, bool allowRemote) +QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width, int height, const QString& method, bool allowRemote) { return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/thumbnail/" % serverName % "/" % mediaId, queryToGetContentThumbnail(width, height, method, allowRemote)); } -GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, Omittable<int> width, Omittable<int> height, const QString& method, bool allowRemote) +GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method, bool allowRemote) : BaseJob(HttpVerb::Get, "GetContentThumbnailJob", basePath % "/thumbnail/" % serverName % "/" % mediaId, queryToGetContentThumbnail(width, height, method, allowRemote), @@ -231,8 +231,8 @@ class GetUrlPreviewJob::Private BaseJob::Query queryToGetUrlPreview(const QString& url, Omittable<qint64> ts) { BaseJob::Query _q; - addToQuery<>(_q, "url", url); - addToQuery<IfNotEmpty>(_q, "ts", ts); + addParam<>(_q, "url", url); + addParam<IfNotEmpty>(_q, "ts", ts); return _q; } diff --git a/lib/csapi/content-repo.h b/lib/csapi/content-repo.h index f3b90c9d..0883c776 100644 --- a/lib/csapi/content-repo.h +++ b/lib/csapi/content-repo.h @@ -90,14 +90,14 @@ namespace QMatrixClient class GetContentThumbnailJob : public BaseJob { public: - explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, Omittable<int> width = none, Omittable<int> height = none, const QString& method = {}, bool allowRemote = true); + explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method = {}, bool allowRemote = true); /** Construct a URL out of baseUrl and usual parameters passed to * GetContentThumbnailJob. This function can be used when * a URL for GetContentThumbnailJob is necessary but the job * itself isn't. */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, Omittable<int> width = none, Omittable<int> height = none, const QString& method = {}, bool allowRemote = true); + static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width, int height, const QString& method = {}, bool allowRemote = true); ~GetContentThumbnailJob() override; diff --git a/lib/csapi/create_room.cpp b/lib/csapi/create_room.cpp index 17a9c60f..910210bc 100644 --- a/lib/csapi/create_room.cpp +++ b/lib/csapi/create_room.cpp @@ -19,18 +19,18 @@ namespace QMatrixClient QJsonObject toJson(const CreateRoomJob::Invite3pid& pod) { QJsonObject _json; - addToJson<>(_json, "id_server", pod.idServer); - addToJson<>(_json, "medium", pod.medium); - addToJson<>(_json, "address", pod.address); + addParam<>(_json, "id_server", pod.idServer); + addParam<>(_json, "medium", pod.medium); + addParam<>(_json, "address", pod.address); return _json; } QJsonObject toJson(const CreateRoomJob::StateEvent& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "type", pod.type); - addToJson<IfNotEmpty>(_json, "state_key", pod.stateKey); - addToJson<IfNotEmpty>(_json, "content", pod.content); + addParam<IfNotEmpty>(_json, "type", pod.type); + addParam<IfNotEmpty>(_json, "state_key", pod.stateKey); + addParam<IfNotEmpty>(_json, "content", pod.content); return _json; } } // namespace QMatrixClient @@ -47,17 +47,17 @@ CreateRoomJob::CreateRoomJob(const QString& visibility, const QString& roomAlias , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "visibility", visibility); - addToJson<IfNotEmpty>(_data, "room_alias_name", roomAliasName); - addToJson<IfNotEmpty>(_data, "name", name); - addToJson<IfNotEmpty>(_data, "topic", topic); - addToJson<IfNotEmpty>(_data, "invite", invite); - addToJson<IfNotEmpty>(_data, "invite_3pid", invite3pid); - addToJson<IfNotEmpty>(_data, "creation_content", creationContent); - addToJson<IfNotEmpty>(_data, "initial_state", initialState); - addToJson<IfNotEmpty>(_data, "preset", preset); - addToJson<IfNotEmpty>(_data, "is_direct", isDirect); - addToJson<IfNotEmpty>(_data, "guest_can_join", guestCanJoin); + addParam<IfNotEmpty>(_data, "visibility", visibility); + addParam<IfNotEmpty>(_data, "room_alias_name", roomAliasName); + addParam<IfNotEmpty>(_data, "name", name); + addParam<IfNotEmpty>(_data, "topic", topic); + addParam<IfNotEmpty>(_data, "invite", invite); + addParam<IfNotEmpty>(_data, "invite_3pid", invite3pid); + addParam<IfNotEmpty>(_data, "creation_content", creationContent); + addParam<IfNotEmpty>(_data, "initial_state", initialState); + addParam<IfNotEmpty>(_data, "preset", preset); + addParam<IfNotEmpty>(_data, "is_direct", isDirect); + addParam<IfNotEmpty>(_data, "guest_can_join", guestCanJoin); setRequestData(_data); } diff --git a/lib/csapi/definitions/client_device.cpp b/lib/csapi/definitions/client_device.cpp index 60b3617c..7c3d7ea6 100644 --- a/lib/csapi/definitions/client_device.cpp +++ b/lib/csapi/definitions/client_device.cpp @@ -9,10 +9,10 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const Device& pod) { QJsonObject _json; - addToJson<>(_json, "device_id", pod.deviceId); - addToJson<IfNotEmpty>(_json, "display_name", pod.displayName); - addToJson<IfNotEmpty>(_json, "last_seen_ip", pod.lastSeenIp); - addToJson<IfNotEmpty>(_json, "last_seen_ts", pod.lastSeenTs); + addParam<>(_json, "device_id", pod.deviceId); + addParam<IfNotEmpty>(_json, "display_name", pod.displayName); + addParam<IfNotEmpty>(_json, "last_seen_ip", pod.lastSeenIp); + addParam<IfNotEmpty>(_json, "last_seen_ts", pod.lastSeenTs); return _json; } diff --git a/lib/csapi/definitions/device_keys.cpp b/lib/csapi/definitions/device_keys.cpp index 24357993..43cd5d2e 100644 --- a/lib/csapi/definitions/device_keys.cpp +++ b/lib/csapi/definitions/device_keys.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const DeviceKeys& pod) { QJsonObject _json; - addToJson<>(_json, "user_id", pod.userId); - addToJson<>(_json, "device_id", pod.deviceId); - addToJson<>(_json, "algorithms", pod.algorithms); - addToJson<>(_json, "keys", pod.keys); - addToJson<>(_json, "signatures", pod.signatures); + addParam<>(_json, "user_id", pod.userId); + addParam<>(_json, "device_id", pod.deviceId); + addParam<>(_json, "algorithms", pod.algorithms); + addParam<>(_json, "keys", pod.keys); + addParam<>(_json, "signatures", pod.signatures); return _json; } diff --git a/lib/csapi/definitions/event_filter.cpp b/lib/csapi/definitions/event_filter.cpp index b16b082d..21ee2b81 100644 --- a/lib/csapi/definitions/event_filter.cpp +++ b/lib/csapi/definitions/event_filter.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const Filter& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "limit", pod.limit); - addToJson<IfNotEmpty>(_json, "not_senders", pod.notSenders); - addToJson<IfNotEmpty>(_json, "not_types", pod.notTypes); - addToJson<IfNotEmpty>(_json, "senders", pod.senders); - addToJson<IfNotEmpty>(_json, "types", pod.types); + addParam<IfNotEmpty>(_json, "limit", pod.limit); + addParam<IfNotEmpty>(_json, "not_senders", pod.notSenders); + addParam<IfNotEmpty>(_json, "not_types", pod.notTypes); + addParam<IfNotEmpty>(_json, "senders", pod.senders); + addParam<IfNotEmpty>(_json, "types", pod.types); return _json; } diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp index 149419f4..b8595ec6 100644 --- a/lib/csapi/definitions/push_condition.cpp +++ b/lib/csapi/definitions/push_condition.cpp @@ -9,10 +9,10 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushCondition& pod) { QJsonObject _json; - addToJson<>(_json, "kind", pod.kind); - addToJson<IfNotEmpty>(_json, "key", pod.key); - addToJson<IfNotEmpty>(_json, "pattern", pod.pattern); - addToJson<IfNotEmpty>(_json, "is", pod.is); + addParam<>(_json, "kind", pod.kind); + addParam<IfNotEmpty>(_json, "key", pod.key); + addParam<IfNotEmpty>(_json, "pattern", pod.pattern); + addParam<IfNotEmpty>(_json, "is", pod.is); return _json; } diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp index 3a44a385..98f5d788 100644 --- a/lib/csapi/definitions/push_rule.cpp +++ b/lib/csapi/definitions/push_rule.cpp @@ -9,12 +9,12 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRule& pod) { QJsonObject _json; - addToJson<>(_json, "actions", pod.actions); - addToJson<>(_json, "default", pod.isDefault); - addToJson<>(_json, "enabled", pod.enabled); - addToJson<>(_json, "rule_id", pod.ruleId); - addToJson<IfNotEmpty>(_json, "conditions", pod.conditions); - addToJson<IfNotEmpty>(_json, "pattern", pod.pattern); + addParam<>(_json, "actions", pod.actions); + addParam<>(_json, "default", pod.isDefault); + addParam<>(_json, "enabled", pod.enabled); + addParam<>(_json, "rule_id", pod.ruleId); + addParam<IfNotEmpty>(_json, "conditions", pod.conditions); + addParam<IfNotEmpty>(_json, "pattern", pod.pattern); return _json; } diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp index 98d79248..ca2bbc0d 100644 --- a/lib/csapi/definitions/push_ruleset.cpp +++ b/lib/csapi/definitions/push_ruleset.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRuleset& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "content", pod.content); - addToJson<IfNotEmpty>(_json, "override", pod.override); - addToJson<IfNotEmpty>(_json, "room", pod.room); - addToJson<IfNotEmpty>(_json, "sender", pod.sender); - addToJson<IfNotEmpty>(_json, "underride", pod.underride); + addParam<IfNotEmpty>(_json, "content", pod.content); + addParam<IfNotEmpty>(_json, "override", pod.override); + addParam<IfNotEmpty>(_json, "room", pod.room); + addParam<IfNotEmpty>(_json, "sender", pod.sender); + addParam<IfNotEmpty>(_json, "underride", pod.underride); return _json; } diff --git a/lib/csapi/definitions/room_event_filter.cpp b/lib/csapi/definitions/room_event_filter.cpp index 68e56f4c..1702be22 100644 --- a/lib/csapi/definitions/room_event_filter.cpp +++ b/lib/csapi/definitions/room_event_filter.cpp @@ -9,9 +9,9 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomEventFilter& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "not_rooms", pod.notRooms); - addToJson<IfNotEmpty>(_json, "rooms", pod.rooms); - addToJson<IfNotEmpty>(_json, "contains_url", pod.containsUrl); + addParam<IfNotEmpty>(_json, "not_rooms", pod.notRooms); + addParam<IfNotEmpty>(_json, "rooms", pod.rooms); + addParam<IfNotEmpty>(_json, "contains_url", pod.containsUrl); return _json; } diff --git a/lib/csapi/definitions/sync_filter.cpp b/lib/csapi/definitions/sync_filter.cpp index 7ca389b4..2b5cf8be 100644 --- a/lib/csapi/definitions/sync_filter.cpp +++ b/lib/csapi/definitions/sync_filter.cpp @@ -9,13 +9,13 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomFilter& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "not_rooms", pod.notRooms); - addToJson<IfNotEmpty>(_json, "rooms", pod.rooms); - addToJson<IfNotEmpty>(_json, "ephemeral", pod.ephemeral); - addToJson<IfNotEmpty>(_json, "include_leave", pod.includeLeave); - addToJson<IfNotEmpty>(_json, "state", pod.state); - addToJson<IfNotEmpty>(_json, "timeline", pod.timeline); - addToJson<IfNotEmpty>(_json, "account_data", pod.accountData); + addParam<IfNotEmpty>(_json, "not_rooms", pod.notRooms); + addParam<IfNotEmpty>(_json, "rooms", pod.rooms); + addParam<IfNotEmpty>(_json, "ephemeral", pod.ephemeral); + addParam<IfNotEmpty>(_json, "include_leave", pod.includeLeave); + addParam<IfNotEmpty>(_json, "state", pod.state); + addParam<IfNotEmpty>(_json, "timeline", pod.timeline); + addParam<IfNotEmpty>(_json, "account_data", pod.accountData); return _json; } @@ -44,11 +44,11 @@ RoomFilter FromJson<RoomFilter>::operator()(const QJsonValue& jv) QJsonObject QMatrixClient::toJson(const SyncFilter& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "event_fields", pod.eventFields); - addToJson<IfNotEmpty>(_json, "event_format", pod.eventFormat); - addToJson<IfNotEmpty>(_json, "presence", pod.presence); - addToJson<IfNotEmpty>(_json, "account_data", pod.accountData); - addToJson<IfNotEmpty>(_json, "room", pod.room); + addParam<IfNotEmpty>(_json, "event_fields", pod.eventFields); + addParam<IfNotEmpty>(_json, "event_format", pod.eventFormat); + addParam<IfNotEmpty>(_json, "presence", pod.presence); + addParam<IfNotEmpty>(_json, "account_data", pod.accountData); + addParam<IfNotEmpty>(_json, "room", pod.room); return _json; } diff --git a/lib/csapi/device_management.cpp b/lib/csapi/device_management.cpp index 2248a0b4..a4b2daae 100644 --- a/lib/csapi/device_management.cpp +++ b/lib/csapi/device_management.cpp @@ -86,7 +86,7 @@ UpdateDeviceJob::UpdateDeviceJob(const QString& deviceId, const QString& display basePath % "/devices/" % deviceId) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "display_name", displayName); + addParam<IfNotEmpty>(_data, "display_name", displayName); setRequestData(_data); } @@ -95,7 +95,7 @@ DeleteDeviceJob::DeleteDeviceJob(const QString& deviceId, const QJsonObject& aut basePath % "/devices/" % deviceId) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, "auth", auth); setRequestData(_data); } @@ -104,8 +104,8 @@ DeleteDevicesJob::DeleteDevicesJob(const QStringList& devices, const QJsonObject basePath % "/delete_devices") { QJsonObject _data; - addToJson<>(_data, "devices", devices); - addToJson<IfNotEmpty>(_data, "auth", auth); + addParam<>(_data, "devices", devices); + addParam<IfNotEmpty>(_data, "auth", auth); setRequestData(_data); } diff --git a/lib/csapi/directory.cpp b/lib/csapi/directory.cpp index d5c5882f..7e8b87b8 100644 --- a/lib/csapi/directory.cpp +++ b/lib/csapi/directory.cpp @@ -17,7 +17,7 @@ SetRoomAliasJob::SetRoomAliasJob(const QString& roomAlias, const QString& roomId basePath % "/room/" % roomAlias) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "room_id", roomId); + addParam<IfNotEmpty>(_data, "room_id", roomId); setRequestData(_data); } diff --git a/lib/csapi/event_context.cpp b/lib/csapi/event_context.cpp index 37de58ab..9e4c6963 100644 --- a/lib/csapi/event_context.cpp +++ b/lib/csapi/event_context.cpp @@ -26,7 +26,7 @@ class GetEventContextJob::Private BaseJob::Query queryToGetEventContext(Omittable<int> limit) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "limit", limit); + addParam<IfNotEmpty>(_q, "limit", limit); return _q; } diff --git a/lib/csapi/inviting.cpp b/lib/csapi/inviting.cpp index 6f180e6c..94e0910b 100644 --- a/lib/csapi/inviting.cpp +++ b/lib/csapi/inviting.cpp @@ -17,7 +17,7 @@ InviteUserJob::InviteUserJob(const QString& roomId, const QString& userId) basePath % "/rooms/" % roomId % "/invite") { QJsonObject _data; - addToJson<>(_data, "user_id", userId); + addParam<>(_data, "user_id", userId); setRequestData(_data); } diff --git a/lib/csapi/joining.cpp b/lib/csapi/joining.cpp index 90aa58c4..f2d6fbf7 100644 --- a/lib/csapi/joining.cpp +++ b/lib/csapi/joining.cpp @@ -19,10 +19,10 @@ namespace QMatrixClient QJsonObject toJson(const JoinRoomByIdJob::ThirdPartySigned& pod) { QJsonObject _json; - addToJson<>(_json, "sender", pod.sender); - addToJson<>(_json, "mxid", pod.mxid); - addToJson<>(_json, "token", pod.token); - addToJson<>(_json, "signatures", pod.signatures); + addParam<>(_json, "sender", pod.sender); + addParam<>(_json, "mxid", pod.mxid); + addParam<>(_json, "token", pod.token); + addParam<>(_json, "signatures", pod.signatures); return _json; } } // namespace QMatrixClient @@ -39,7 +39,7 @@ JoinRoomByIdJob::JoinRoomByIdJob(const QString& roomId, const Omittable<ThirdPar , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); + addParam<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); setRequestData(_data); } @@ -67,17 +67,17 @@ namespace QMatrixClient QJsonObject toJson(const JoinRoomJob::Signed& pod) { QJsonObject _json; - addToJson<>(_json, "sender", pod.sender); - addToJson<>(_json, "mxid", pod.mxid); - addToJson<>(_json, "token", pod.token); - addToJson<>(_json, "signatures", pod.signatures); + addParam<>(_json, "sender", pod.sender); + addParam<>(_json, "mxid", pod.mxid); + addParam<>(_json, "token", pod.token); + addParam<>(_json, "signatures", pod.signatures); return _json; } QJsonObject toJson(const JoinRoomJob::ThirdPartySigned& pod) { QJsonObject _json; - addToJson<>(_json, "signed", pod.signedData); + addParam<>(_json, "signed", pod.signedData); return _json; } } // namespace QMatrixClient @@ -94,7 +94,7 @@ JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const Omittable<ThirdPart , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); + addParam<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); setRequestData(_data); } diff --git a/lib/csapi/keys.cpp b/lib/csapi/keys.cpp index 88d6690b..4a76b7e2 100644 --- a/lib/csapi/keys.cpp +++ b/lib/csapi/keys.cpp @@ -24,8 +24,8 @@ UploadKeysJob::UploadKeysJob(const Omittable<DeviceKeys>& deviceKeys, const QHas , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "device_keys", deviceKeys); - addToJson<IfNotEmpty>(_data, "one_time_keys", oneTimeKeys); + addParam<IfNotEmpty>(_data, "device_keys", deviceKeys); + addParam<IfNotEmpty>(_data, "one_time_keys", oneTimeKeys); setRequestData(_data); } @@ -90,9 +90,9 @@ QueryKeysJob::QueryKeysJob(const QHash<QString, QStringList>& deviceKeys, Omitta , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "timeout", timeout); - addToJson<>(_data, "device_keys", deviceKeys); - addToJson<IfNotEmpty>(_data, "token", token); + addParam<IfNotEmpty>(_data, "timeout", timeout); + addParam<>(_data, "device_keys", deviceKeys); + addParam<IfNotEmpty>(_data, "token", token); setRequestData(_data); } @@ -129,8 +129,8 @@ ClaimKeysJob::ClaimKeysJob(const QHash<QString, QHash<QString, QString>>& oneTim , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "timeout", timeout); - addToJson<>(_data, "one_time_keys", oneTimeKeys); + addParam<IfNotEmpty>(_data, "timeout", timeout); + addParam<>(_data, "one_time_keys", oneTimeKeys); setRequestData(_data); } @@ -164,8 +164,8 @@ class GetKeysChangesJob::Private BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to) { BaseJob::Query _q; - addToQuery<>(_q, "from", from); - addToQuery<>(_q, "to", to); + addParam<>(_q, "from", from); + addParam<>(_q, "to", to); return _q; } diff --git a/lib/csapi/kicking.cpp b/lib/csapi/kicking.cpp index e143166a..73ef70ae 100644 --- a/lib/csapi/kicking.cpp +++ b/lib/csapi/kicking.cpp @@ -17,8 +17,8 @@ KickJob::KickJob(const QString& roomId, const QString& userId, const QString& re basePath % "/rooms/" % roomId % "/kick") { QJsonObject _data; - addToJson<>(_data, "user_id", userId); - addToJson<IfNotEmpty>(_data, "reason", reason); + addParam<>(_data, "user_id", userId); + addParam<IfNotEmpty>(_data, "reason", reason); setRequestData(_data); } diff --git a/lib/csapi/list_public_rooms.cpp b/lib/csapi/list_public_rooms.cpp index 5952fd6e..5d605bbb 100644 --- a/lib/csapi/list_public_rooms.cpp +++ b/lib/csapi/list_public_rooms.cpp @@ -50,7 +50,7 @@ SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& basePath % "/directory/list/room/" % roomId) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "visibility", visibility); + addParam<IfNotEmpty>(_data, "visibility", visibility); setRequestData(_data); } @@ -100,9 +100,9 @@ class GetPublicRoomsJob::Private BaseJob::Query queryToGetPublicRooms(Omittable<int> limit, const QString& since, const QString& server) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "limit", limit); - addToQuery<IfNotEmpty>(_q, "since", since); - addToQuery<IfNotEmpty>(_q, "server", server); + addParam<IfNotEmpty>(_q, "limit", limit); + addParam<IfNotEmpty>(_q, "since", since); + addParam<IfNotEmpty>(_q, "server", server); return _q; } @@ -164,7 +164,7 @@ namespace QMatrixClient QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "generic_search_term", pod.genericSearchTerm); + addParam<IfNotEmpty>(_json, "generic_search_term", pod.genericSearchTerm); return _json; } @@ -210,7 +210,7 @@ class QueryPublicRoomsJob::Private BaseJob::Query queryToQueryPublicRooms(const QString& server) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "server", server); + addParam<IfNotEmpty>(_q, "server", server); return _q; } @@ -221,9 +221,9 @@ QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, Omittable<int> l , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "limit", limit); - addToJson<IfNotEmpty>(_data, "since", since); - addToJson<IfNotEmpty>(_data, "filter", filter); + addParam<IfNotEmpty>(_data, "limit", limit); + addParam<IfNotEmpty>(_data, "since", since); + addParam<IfNotEmpty>(_data, "filter", filter); setRequestData(_data); } diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp index 7e162871..e0795f8a 100644 --- a/lib/csapi/login.cpp +++ b/lib/csapi/login.cpp @@ -27,14 +27,14 @@ LoginJob::LoginJob(const QString& type, const QString& user, const QString& medi , d(new Private) { QJsonObject _data; - addToJson<>(_data, "type", type); - addToJson<IfNotEmpty>(_data, "user", user); - addToJson<IfNotEmpty>(_data, "medium", medium); - addToJson<IfNotEmpty>(_data, "address", address); - addToJson<IfNotEmpty>(_data, "password", password); - addToJson<IfNotEmpty>(_data, "token", token); - addToJson<IfNotEmpty>(_data, "device_id", deviceId); - addToJson<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); + addParam<>(_data, "type", type); + addParam<IfNotEmpty>(_data, "user", user); + addParam<IfNotEmpty>(_data, "medium", medium); + addParam<IfNotEmpty>(_data, "address", address); + addParam<IfNotEmpty>(_data, "password", password); + addParam<IfNotEmpty>(_data, "token", token); + addParam<IfNotEmpty>(_data, "device_id", deviceId); + addParam<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); setRequestData(_data); } diff --git a/lib/csapi/message_pagination.cpp b/lib/csapi/message_pagination.cpp index 1a7d6ee9..1eb2aa07 100644 --- a/lib/csapi/message_pagination.cpp +++ b/lib/csapi/message_pagination.cpp @@ -23,11 +23,11 @@ class GetRoomEventsJob::Private BaseJob::Query queryToGetRoomEvents(const QString& from, const QString& to, const QString& dir, Omittable<int> limit, const QString& filter) { BaseJob::Query _q; - addToQuery<>(_q, "from", from); - addToQuery<IfNotEmpty>(_q, "to", to); - addToQuery<>(_q, "dir", dir); - addToQuery<IfNotEmpty>(_q, "limit", limit); - addToQuery<IfNotEmpty>(_q, "filter", filter); + addParam<>(_q, "from", from); + addParam<IfNotEmpty>(_q, "to", to); + addParam<>(_q, "dir", dir); + addParam<IfNotEmpty>(_q, "limit", limit); + addParam<IfNotEmpty>(_q, "filter", filter); return _q; } diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp index de5b41f2..39570991 100644 --- a/lib/csapi/notifications.cpp +++ b/lib/csapi/notifications.cpp @@ -50,9 +50,9 @@ class GetNotificationsJob::Private BaseJob::Query queryToGetNotifications(const QString& from, Omittable<int> limit, const QString& only) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "from", from); - addToQuery<IfNotEmpty>(_q, "limit", limit); - addToQuery<IfNotEmpty>(_q, "only", only); + addParam<IfNotEmpty>(_q, "from", from); + addParam<IfNotEmpty>(_q, "limit", limit); + addParam<IfNotEmpty>(_q, "only", only); return _q; } diff --git a/lib/csapi/peeking_events.cpp b/lib/csapi/peeking_events.cpp index 53f2d280..b3be7631 100644 --- a/lib/csapi/peeking_events.cpp +++ b/lib/csapi/peeking_events.cpp @@ -23,9 +23,9 @@ class PeekEventsJob::Private BaseJob::Query queryToPeekEvents(const QString& from, Omittable<int> timeout, const QString& roomId) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "from", from); - addToQuery<IfNotEmpty>(_q, "timeout", timeout); - addToQuery<IfNotEmpty>(_q, "room_id", roomId); + addParam<IfNotEmpty>(_q, "from", from); + addParam<IfNotEmpty>(_q, "timeout", timeout); + addParam<IfNotEmpty>(_q, "room_id", roomId); return _q; } diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp index 707d48d0..35b2c960 100644 --- a/lib/csapi/presence.cpp +++ b/lib/csapi/presence.cpp @@ -17,8 +17,8 @@ SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence, c basePath % "/presence/" % userId % "/status") { QJsonObject _data; - addToJson<>(_data, "presence", presence); - addToJson<IfNotEmpty>(_data, "status_msg", statusMsg); + addParam<>(_data, "presence", presence); + addParam<IfNotEmpty>(_data, "status_msg", statusMsg); setRequestData(_data); } @@ -84,8 +84,8 @@ ModifyPresenceListJob::ModifyPresenceListJob(const QString& userId, const QStrin basePath % "/presence/list/" % userId) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "invite", invite); - addToJson<IfNotEmpty>(_data, "drop", drop); + addParam<IfNotEmpty>(_data, "invite", invite); + addParam<IfNotEmpty>(_data, "drop", drop); setRequestData(_data); } diff --git a/lib/csapi/profile.cpp b/lib/csapi/profile.cpp index 6b93d961..b08eb970 100644 --- a/lib/csapi/profile.cpp +++ b/lib/csapi/profile.cpp @@ -17,7 +17,7 @@ SetDisplayNameJob::SetDisplayNameJob(const QString& userId, const QString& displ basePath % "/profile/" % userId % "/displayname") { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "displayname", displayname); + addParam<IfNotEmpty>(_data, "displayname", displayname); setRequestData(_data); } @@ -59,7 +59,7 @@ SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QString& avatarUrl basePath % "/profile/" % userId % "/avatar_url") { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "avatar_url", avatarUrl); + addParam<IfNotEmpty>(_data, "avatar_url", avatarUrl); setRequestData(_data); } diff --git a/lib/csapi/pusher.cpp b/lib/csapi/pusher.cpp index ba5229d3..1a43900b 100644 --- a/lib/csapi/pusher.cpp +++ b/lib/csapi/pusher.cpp @@ -97,7 +97,7 @@ namespace QMatrixClient QJsonObject toJson(const PostPusherJob::PusherData& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "url", pod.url); + addParam<IfNotEmpty>(_json, "url", pod.url); return _json; } } // namespace QMatrixClient @@ -107,15 +107,15 @@ PostPusherJob::PostPusherJob(const QString& pushkey, const QString& kind, const basePath % "/pushers/set") { QJsonObject _data; - addToJson<>(_data, "pushkey", pushkey); - addToJson<>(_data, "kind", kind); - addToJson<>(_data, "app_id", appId); - addToJson<>(_data, "app_display_name", appDisplayName); - addToJson<>(_data, "device_display_name", deviceDisplayName); - addToJson<IfNotEmpty>(_data, "profile_tag", profileTag); - addToJson<>(_data, "lang", lang); - addToJson<>(_data, "data", data); - addToJson<IfNotEmpty>(_data, "append", append); + addParam<>(_data, "pushkey", pushkey); + addParam<>(_data, "kind", kind); + addParam<>(_data, "app_id", appId); + addParam<>(_data, "app_display_name", appDisplayName); + addParam<>(_data, "device_display_name", deviceDisplayName); + addParam<IfNotEmpty>(_data, "profile_tag", profileTag); + addParam<>(_data, "lang", lang); + addParam<>(_data, "data", data); + addParam<IfNotEmpty>(_data, "append", append); setRequestData(_data); } diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp index 807f1d0f..d7e416dc 100644 --- a/lib/csapi/pushrules.cpp +++ b/lib/csapi/pushrules.cpp @@ -99,8 +99,8 @@ DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, BaseJob::Query queryToSetPushRule(const QString& before, const QString& after) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "before", before); - addToQuery<IfNotEmpty>(_q, "after", after); + addParam<IfNotEmpty>(_q, "before", before); + addParam<IfNotEmpty>(_q, "after", after); return _q; } @@ -110,9 +110,9 @@ SetPushRuleJob::SetPushRuleJob(const QString& scope, const QString& kind, const queryToSetPushRule(before, after)) { QJsonObject _data; - addToJson<>(_data, "actions", actions); - addToJson<IfNotEmpty>(_data, "conditions", conditions); - addToJson<IfNotEmpty>(_data, "pattern", pattern); + addParam<>(_data, "actions", actions); + addParam<IfNotEmpty>(_data, "conditions", conditions); + addParam<IfNotEmpty>(_data, "pattern", pattern); setRequestData(_data); } @@ -157,7 +157,7 @@ SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled") { QJsonObject _data; - addToJson<>(_data, "enabled", enabled); + addParam<>(_data, "enabled", enabled); setRequestData(_data); } @@ -202,7 +202,7 @@ SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions") { QJsonObject _data; - addToJson<>(_data, "actions", actions); + addParam<>(_data, "actions", actions); setRequestData(_data); } diff --git a/lib/csapi/redaction.cpp b/lib/csapi/redaction.cpp index aa6e3b65..2c73800c 100644 --- a/lib/csapi/redaction.cpp +++ b/lib/csapi/redaction.cpp @@ -24,7 +24,7 @@ RedactEventJob::RedactEventJob(const QString& roomId, const QString& eventId, co , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "reason", reason); + addParam<IfNotEmpty>(_data, "reason", reason); setRequestData(_data); } diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp index 85a3e256..4345635a 100644 --- a/lib/csapi/registration.cpp +++ b/lib/csapi/registration.cpp @@ -24,7 +24,7 @@ class RegisterJob::Private BaseJob::Query queryToRegister(const QString& kind) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "kind", kind); + addParam<IfNotEmpty>(_q, "kind", kind); return _q; } @@ -36,12 +36,12 @@ RegisterJob::RegisterJob(const QString& kind, const QJsonObject& auth, bool bind , d(new Private) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "auth", auth); - addToJson<IfNotEmpty>(_data, "bind_email", bindEmail); - addToJson<IfNotEmpty>(_data, "username", username); - addToJson<IfNotEmpty>(_data, "password", password); - addToJson<IfNotEmpty>(_data, "device_id", deviceId); - addToJson<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); + addParam<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, "bind_email", bindEmail); + addParam<IfNotEmpty>(_data, "username", username); + addParam<IfNotEmpty>(_data, "password", password); + addParam<IfNotEmpty>(_data, "device_id", deviceId); + addParam<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); setRequestData(_data); } @@ -82,10 +82,10 @@ RequestTokenToRegisterJob::RequestTokenToRegisterJob(const QString& clientSecret basePath % "/register/email/requestToken", false) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "id_server", idServer); - addToJson<>(_data, "client_secret", clientSecret); - addToJson<>(_data, "email", email); - addToJson<>(_data, "send_attempt", sendAttempt); + addParam<IfNotEmpty>(_data, "id_server", idServer); + addParam<>(_data, "client_secret", clientSecret); + addParam<>(_data, "email", email); + addParam<>(_data, "send_attempt", sendAttempt); setRequestData(_data); } @@ -94,8 +94,8 @@ ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const QJsonObje basePath % "/account/password") { QJsonObject _data; - addToJson<>(_data, "new_password", newPassword); - addToJson<IfNotEmpty>(_data, "auth", auth); + addParam<>(_data, "new_password", newPassword); + addParam<IfNotEmpty>(_data, "auth", auth); setRequestData(_data); } @@ -116,7 +116,7 @@ DeactivateAccountJob::DeactivateAccountJob(const QJsonObject& auth) basePath % "/account/deactivate") { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, "auth", auth); setRequestData(_data); } @@ -129,7 +129,7 @@ class CheckUsernameAvailabilityJob::Private BaseJob::Query queryToCheckUsernameAvailability(const QString& username) { BaseJob::Query _q; - addToQuery<>(_q, "username", username); + addParam<>(_q, "username", username); return _q; } diff --git a/lib/csapi/report_content.cpp b/lib/csapi/report_content.cpp index 9d19e012..f1a1d6f2 100644 --- a/lib/csapi/report_content.cpp +++ b/lib/csapi/report_content.cpp @@ -17,8 +17,8 @@ ReportContentJob::ReportContentJob(const QString& roomId, const QString& eventId basePath % "/rooms/" % roomId % "/report/" % eventId) { QJsonObject _data; - addToJson<>(_data, "score", score); - addToJson<>(_data, "reason", reason); + addParam<>(_data, "score", score); + addParam<>(_data, "reason", reason); setRequestData(_data); } diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp index d172dfbe..75748b38 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; - addToJson<IfNotEmpty>(_json, "before_limit", pod.beforeLimit); - addToJson<IfNotEmpty>(_json, "after_limit", pod.afterLimit); - addToJson<IfNotEmpty>(_json, "include_profile", pod.includeProfile); + addParam<IfNotEmpty>(_json, "before_limit", pod.beforeLimit); + addParam<IfNotEmpty>(_json, "after_limit", pod.afterLimit); + addParam<IfNotEmpty>(_json, "include_profile", pod.includeProfile); return _json; } QJsonObject toJson(const SearchJob::Group& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "key", pod.key); + addParam<IfNotEmpty>(_json, "key", pod.key); return _json; } QJsonObject toJson(const SearchJob::Groupings& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "group_by", pod.groupBy); + addParam<IfNotEmpty>(_json, "group_by", pod.groupBy); return _json; } QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod) { QJsonObject _json; - addToJson<>(_json, "search_term", pod.searchTerm); - addToJson<IfNotEmpty>(_json, "keys", pod.keys); - addToJson<IfNotEmpty>(_json, "filter", pod.filter); - addToJson<IfNotEmpty>(_json, "order_by", pod.orderBy); - addToJson<IfNotEmpty>(_json, "event_context", pod.eventContext); - addToJson<IfNotEmpty>(_json, "include_state", pod.includeState); - addToJson<IfNotEmpty>(_json, "groupings", pod.groupings); + 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); return _json; } QJsonObject toJson(const SearchJob::Categories& pod) { QJsonObject _json; - addToJson<IfNotEmpty>(_json, "room_events", pod.roomEvents); + addParam<IfNotEmpty>(_json, "room_events", pod.roomEvents); return _json; } @@ -173,7 +173,7 @@ class SearchJob::Private BaseJob::Query queryToSearch(const QString& nextBatch) { BaseJob::Query _q; - addToQuery<IfNotEmpty>(_q, "next_batch", nextBatch); + addParam<IfNotEmpty>(_q, "next_batch", nextBatch); return _q; } @@ -184,7 +184,7 @@ SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatc , d(new Private) { QJsonObject _data; - addToJson<>(_data, "search_categories", searchCategories); + addParam<>(_data, "search_categories", searchCategories); setRequestData(_data); } diff --git a/lib/csapi/third_party_membership.cpp b/lib/csapi/third_party_membership.cpp index 4cdad48b..2372f9d7 100644 --- a/lib/csapi/third_party_membership.cpp +++ b/lib/csapi/third_party_membership.cpp @@ -17,9 +17,9 @@ InviteBy3PIDJob::InviteBy3PIDJob(const QString& roomId, const QString& idServer, basePath % "/rooms/" % roomId % "/invite") { QJsonObject _data; - addToJson<>(_data, "id_server", idServer); - addToJson<>(_data, "medium", medium); - addToJson<>(_data, "address", address); + addParam<>(_data, "id_server", idServer); + addParam<>(_data, "medium", medium); + addParam<>(_data, "address", address); setRequestData(_data); } diff --git a/lib/csapi/to_device.cpp b/lib/csapi/to_device.cpp index dfc47ab5..1478a679 100644 --- a/lib/csapi/to_device.cpp +++ b/lib/csapi/to_device.cpp @@ -17,7 +17,7 @@ SendToDeviceJob::SendToDeviceJob(const QString& eventType, const QString& txnId, basePath % "/sendToDevice/" % eventType % "/" % txnId) { QJsonObject _data; - addToJson<IfNotEmpty>(_data, "messages", messages); + addParam<IfNotEmpty>(_data, "messages", messages); setRequestData(_data); } diff --git a/lib/csapi/typing.cpp b/lib/csapi/typing.cpp index 605e143a..6db522c4 100644 --- a/lib/csapi/typing.cpp +++ b/lib/csapi/typing.cpp @@ -17,8 +17,8 @@ SetTypingJob::SetTypingJob(const QString& userId, const QString& roomId, bool ty basePath % "/rooms/" % roomId % "/typing/" % userId) { QJsonObject _data; - addToJson<>(_data, "typing", typing); - addToJson<IfNotEmpty>(_data, "timeout", timeout); + addParam<>(_data, "typing", typing); + addParam<IfNotEmpty>(_data, "timeout", timeout); setRequestData(_data); } diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp index a27be93b..e7f68bda 100644 --- a/lib/csapi/users.cpp +++ b/lib/csapi/users.cpp @@ -47,8 +47,8 @@ SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, Omitta , d(new Private) { QJsonObject _data; - addToJson<>(_data, "search_term", searchTerm); - addToJson<IfNotEmpty>(_data, "limit", limit); + addParam<>(_data, "search_term", searchTerm); + addParam<IfNotEmpty>(_data, "limit", limit); setRequestData(_data); } diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache index 0955984d..0800fef7 100644 --- a/lib/csapi/{{base}}.cpp.mustache +++ b/lib/csapi/{{base}}.cpp.mustache @@ -11,7 +11,7 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod) { QJsonObject _json;{{#vars}} - addToJson<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} return _json; } {{/in?}}{{#out?}} @@ -34,7 +34,7 @@ namespace QMatrixClient QJsonObject toJson(const {{qualifiedName}}& pod) { QJsonObject _json;{{#vars}} - addToJson<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} return _json; } {{/in?}}{{#out?}} @@ -61,7 +61,7 @@ class {{camelCaseOperationId}}Job::Private BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}}) { BaseJob::Query _q;{{#queryParams}} - addToQuery<{{^required?}}IfNotEmpty{{/required?}}>(_q, "{{baseName}}", {{paramName}});{{/queryParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, "{{baseName}}", {{paramName}});{{/queryParams}} return _q; } {{/queryParams?}}{{^bodyParams}} @@ -87,7 +87,7 @@ QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{ }}{{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson? }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));{{/inlineBody }}{{^inlineBody}} QJsonObject _data;{{#bodyParams}} - addToJson<{{^required?}}IfNotEmpty{{/required?}}>(_data, "{{baseName}}", {{paramName}});{{/bodyParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, "{{baseName}}", {{paramName}});{{/bodyParams}} setRequestData(_data);{{/inlineBody}} {{/bodyParams?}}{{#producesNonJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{#@join}}, {{/@join}}{{/produces}} }); {{/producesNonJson?}}}{{!<- mind the actual brace}} |