diff options
Diffstat (limited to 'lib/csapi/definitions')
26 files changed, 318 insertions, 227 deletions
diff --git a/lib/csapi/definitions/auth_data.cpp b/lib/csapi/definitions/auth_data.cpp index 94e3c05c..f8639432 100644 --- a/lib/csapi/definitions/auth_data.cpp +++ b/lib/csapi/definitions/auth_data.cpp @@ -8,22 +8,21 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const AuthenticationData& pod) { - QJsonObject _json = toJson(pod.authInfo); - addParam<>(_json, QStringLiteral("type"), pod.type); - addParam<IfNotEmpty>(_json, QStringLiteral("session"), pod.session); - return _json; + QJsonObject jo = toJson(pod.authInfo); + addParam<>(jo, QStringLiteral("type"), pod.type); + addParam<IfNotEmpty>(jo, QStringLiteral("session"), pod.session); + return jo; } -AuthenticationData FromJson<AuthenticationData>::operator()(const QJsonValue& jv) +AuthenticationData FromJsonObject<AuthenticationData>::operator()(QJsonObject jo) const { - auto _json = jv.toObject(); AuthenticationData result; result.type = - fromJson<QString>(_json.take("type"_ls)); + fromJson<QString>(jo.take("type"_ls)); result.session = - fromJson<QString>(_json.take("session"_ls)); - - result.authInfo = fromJson<QHash<QString, QJsonObject>>(_json); + fromJson<QString>(jo.take("session"_ls)); + + result.authInfo = fromJson<QHash<QString, QJsonObject>>(jo); return result; } diff --git a/lib/csapi/definitions/auth_data.h b/lib/csapi/definitions/auth_data.h index dce55396..661d3e5f 100644 --- a/lib/csapi/definitions/auth_data.h +++ b/lib/csapi/definitions/auth_data.h @@ -26,9 +26,9 @@ namespace QMatrixClient QJsonObject toJson(const AuthenticationData& pod); - template <> struct FromJson<AuthenticationData> + template <> struct FromJsonObject<AuthenticationData> { - AuthenticationData operator()(const QJsonValue& jv); + AuthenticationData operator()(QJsonObject jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/client_device.cpp b/lib/csapi/definitions/client_device.cpp index bd7acd02..4a192f85 100644 --- a/lib/csapi/definitions/client_device.cpp +++ b/lib/csapi/definitions/client_device.cpp @@ -8,27 +8,26 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const Device& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("device_id"), pod.deviceId); - addParam<IfNotEmpty>(_json, QStringLiteral("display_name"), pod.displayName); - addParam<IfNotEmpty>(_json, QStringLiteral("last_seen_ip"), pod.lastSeenIp); - addParam<IfNotEmpty>(_json, QStringLiteral("last_seen_ts"), pod.lastSeenTs); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("device_id"), pod.deviceId); + addParam<IfNotEmpty>(jo, QStringLiteral("display_name"), pod.displayName); + addParam<IfNotEmpty>(jo, QStringLiteral("last_seen_ip"), pod.lastSeenIp); + addParam<IfNotEmpty>(jo, QStringLiteral("last_seen_ts"), pod.lastSeenTs); + return jo; } -Device FromJson<Device>::operator()(const QJsonValue& jv) +Device FromJsonObject<Device>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); Device result; result.deviceId = - fromJson<QString>(_json.value("device_id"_ls)); + fromJson<QString>(jo.value("device_id"_ls)); result.displayName = - fromJson<QString>(_json.value("display_name"_ls)); + fromJson<QString>(jo.value("display_name"_ls)); result.lastSeenIp = - fromJson<QString>(_json.value("last_seen_ip"_ls)); + fromJson<QString>(jo.value("last_seen_ip"_ls)); result.lastSeenTs = - fromJson<qint64>(_json.value("last_seen_ts"_ls)); - + fromJson<qint64>(jo.value("last_seen_ts"_ls)); + return result; } diff --git a/lib/csapi/definitions/client_device.h b/lib/csapi/definitions/client_device.h index ba65483d..9f10888a 100644 --- a/lib/csapi/definitions/client_device.h +++ b/lib/csapi/definitions/client_device.h @@ -31,9 +31,9 @@ namespace QMatrixClient QJsonObject toJson(const Device& pod); - template <> struct FromJson<Device> + template <> struct FromJsonObject<Device> { - Device operator()(const QJsonValue& jv); + Device operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/device_keys.cpp b/lib/csapi/definitions/device_keys.cpp index d17f4c12..a0e0ca42 100644 --- a/lib/csapi/definitions/device_keys.cpp +++ b/lib/csapi/definitions/device_keys.cpp @@ -8,30 +8,29 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const DeviceKeys& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("user_id"), pod.userId); - addParam<>(_json, QStringLiteral("device_id"), pod.deviceId); - addParam<>(_json, QStringLiteral("algorithms"), pod.algorithms); - addParam<>(_json, QStringLiteral("keys"), pod.keys); - addParam<>(_json, QStringLiteral("signatures"), pod.signatures); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("user_id"), pod.userId); + addParam<>(jo, QStringLiteral("device_id"), pod.deviceId); + addParam<>(jo, QStringLiteral("algorithms"), pod.algorithms); + addParam<>(jo, QStringLiteral("keys"), pod.keys); + addParam<>(jo, QStringLiteral("signatures"), pod.signatures); + return jo; } -DeviceKeys FromJson<DeviceKeys>::operator()(const QJsonValue& jv) +DeviceKeys FromJsonObject<DeviceKeys>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); DeviceKeys result; result.userId = - fromJson<QString>(_json.value("user_id"_ls)); + fromJson<QString>(jo.value("user_id"_ls)); result.deviceId = - fromJson<QString>(_json.value("device_id"_ls)); + fromJson<QString>(jo.value("device_id"_ls)); result.algorithms = - fromJson<QStringList>(_json.value("algorithms"_ls)); + fromJson<QStringList>(jo.value("algorithms"_ls)); result.keys = - fromJson<QHash<QString, QString>>(_json.value("keys"_ls)); + fromJson<QHash<QString, QString>>(jo.value("keys"_ls)); result.signatures = - fromJson<QHash<QString, QHash<QString, QString>>>(_json.value("signatures"_ls)); - + fromJson<QHash<QString, QHash<QString, QString>>>(jo.value("signatures"_ls)); + return result; } diff --git a/lib/csapi/definitions/device_keys.h b/lib/csapi/definitions/device_keys.h index 4b223609..6023e7e8 100644 --- a/lib/csapi/definitions/device_keys.h +++ b/lib/csapi/definitions/device_keys.h @@ -37,9 +37,9 @@ namespace QMatrixClient QJsonObject toJson(const DeviceKeys& pod); - template <> struct FromJson<DeviceKeys> + template <> struct FromJsonObject<DeviceKeys> { - DeviceKeys operator()(const QJsonValue& jv); + DeviceKeys operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/event_filter.cpp b/lib/csapi/definitions/event_filter.cpp index 336de0dd..cc444db0 100644 --- a/lib/csapi/definitions/event_filter.cpp +++ b/lib/csapi/definitions/event_filter.cpp @@ -6,32 +6,31 @@ using namespace QMatrixClient; -QJsonObject QMatrixClient::toJson(const Filter& pod) +QJsonObject QMatrixClient::toJson(const EventFilter& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("limit"), pod.limit); - addParam<IfNotEmpty>(_json, QStringLiteral("not_senders"), pod.notSenders); - addParam<IfNotEmpty>(_json, QStringLiteral("not_types"), pod.notTypes); - addParam<IfNotEmpty>(_json, QStringLiteral("senders"), pod.senders); - addParam<IfNotEmpty>(_json, QStringLiteral("types"), pod.types); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("limit"), pod.limit); + addParam<IfNotEmpty>(jo, QStringLiteral("not_senders"), pod.notSenders); + addParam<IfNotEmpty>(jo, QStringLiteral("not_types"), pod.notTypes); + addParam<IfNotEmpty>(jo, QStringLiteral("senders"), pod.senders); + addParam<IfNotEmpty>(jo, QStringLiteral("types"), pod.types); + return jo; } -Filter FromJson<Filter>::operator()(const QJsonValue& jv) +EventFilter FromJsonObject<EventFilter>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); - Filter result; + EventFilter result; result.limit = - fromJson<int>(_json.value("limit"_ls)); + fromJson<int>(jo.value("limit"_ls)); result.notSenders = - fromJson<QStringList>(_json.value("not_senders"_ls)); + fromJson<QStringList>(jo.value("not_senders"_ls)); result.notTypes = - fromJson<QStringList>(_json.value("not_types"_ls)); + fromJson<QStringList>(jo.value("not_types"_ls)); result.senders = - fromJson<QStringList>(_json.value("senders"_ls)); + fromJson<QStringList>(jo.value("senders"_ls)); result.types = - fromJson<QStringList>(_json.value("types"_ls)); - + fromJson<QStringList>(jo.value("types"_ls)); + return result; } diff --git a/lib/csapi/definitions/event_filter.h b/lib/csapi/definitions/event_filter.h index 76f08319..5c6a5b27 100644 --- a/lib/csapi/definitions/event_filter.h +++ b/lib/csapi/definitions/event_filter.h @@ -12,7 +12,7 @@ namespace QMatrixClient { // Data structures - struct Filter + struct EventFilter { /// The maximum number of events to return. Omittable<int> limit; @@ -26,11 +26,11 @@ namespace QMatrixClient QStringList types; }; - QJsonObject toJson(const Filter& pod); + QJsonObject toJson(const EventFilter& pod); - template <> struct FromJson<Filter> + template <> struct FromJsonObject<EventFilter> { - Filter operator()(const QJsonValue& jv); + EventFilter operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/public_rooms_response.cpp b/lib/csapi/definitions/public_rooms_response.cpp index 7cdf16af..2f52501d 100644 --- a/lib/csapi/definitions/public_rooms_response.cpp +++ b/lib/csapi/definitions/public_rooms_response.cpp @@ -8,68 +8,66 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PublicRoomsChunk& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("aliases"), pod.aliases); - addParam<IfNotEmpty>(_json, QStringLiteral("canonical_alias"), pod.canonicalAlias); - addParam<IfNotEmpty>(_json, QStringLiteral("name"), pod.name); - addParam<>(_json, QStringLiteral("num_joined_members"), pod.numJoinedMembers); - addParam<>(_json, QStringLiteral("room_id"), pod.roomId); - addParam<IfNotEmpty>(_json, QStringLiteral("topic"), pod.topic); - addParam<>(_json, QStringLiteral("world_readable"), pod.worldReadable); - addParam<>(_json, QStringLiteral("guest_can_join"), pod.guestCanJoin); - addParam<IfNotEmpty>(_json, QStringLiteral("avatar_url"), pod.avatarUrl); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("aliases"), pod.aliases); + addParam<IfNotEmpty>(jo, QStringLiteral("canonical_alias"), pod.canonicalAlias); + addParam<IfNotEmpty>(jo, QStringLiteral("name"), pod.name); + addParam<>(jo, QStringLiteral("num_joined_members"), pod.numJoinedMembers); + addParam<>(jo, QStringLiteral("room_id"), pod.roomId); + addParam<IfNotEmpty>(jo, QStringLiteral("topic"), pod.topic); + addParam<>(jo, QStringLiteral("world_readable"), pod.worldReadable); + addParam<>(jo, QStringLiteral("guest_can_join"), pod.guestCanJoin); + addParam<IfNotEmpty>(jo, QStringLiteral("avatar_url"), pod.avatarUrl); + return jo; } -PublicRoomsChunk FromJson<PublicRoomsChunk>::operator()(const QJsonValue& jv) +PublicRoomsChunk FromJsonObject<PublicRoomsChunk>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); PublicRoomsChunk result; result.aliases = - fromJson<QStringList>(_json.value("aliases"_ls)); + fromJson<QStringList>(jo.value("aliases"_ls)); result.canonicalAlias = - fromJson<QString>(_json.value("canonical_alias"_ls)); + fromJson<QString>(jo.value("canonical_alias"_ls)); result.name = - fromJson<QString>(_json.value("name"_ls)); + fromJson<QString>(jo.value("name"_ls)); result.numJoinedMembers = - fromJson<qint64>(_json.value("num_joined_members"_ls)); + fromJson<int>(jo.value("num_joined_members"_ls)); result.roomId = - fromJson<QString>(_json.value("room_id"_ls)); + fromJson<QString>(jo.value("room_id"_ls)); result.topic = - fromJson<QString>(_json.value("topic"_ls)); + fromJson<QString>(jo.value("topic"_ls)); result.worldReadable = - fromJson<bool>(_json.value("world_readable"_ls)); + fromJson<bool>(jo.value("world_readable"_ls)); result.guestCanJoin = - fromJson<bool>(_json.value("guest_can_join"_ls)); + fromJson<bool>(jo.value("guest_can_join"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url"_ls)); - + fromJson<QString>(jo.value("avatar_url"_ls)); + return result; } QJsonObject QMatrixClient::toJson(const PublicRoomsResponse& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("chunk"), pod.chunk); - addParam<IfNotEmpty>(_json, QStringLiteral("next_batch"), pod.nextBatch); - addParam<IfNotEmpty>(_json, QStringLiteral("prev_batch"), pod.prevBatch); - addParam<IfNotEmpty>(_json, QStringLiteral("total_room_count_estimate"), pod.totalRoomCountEstimate); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("chunk"), pod.chunk); + addParam<IfNotEmpty>(jo, QStringLiteral("next_batch"), pod.nextBatch); + addParam<IfNotEmpty>(jo, QStringLiteral("prev_batch"), pod.prevBatch); + addParam<IfNotEmpty>(jo, QStringLiteral("total_room_count_estimate"), pod.totalRoomCountEstimate); + return jo; } -PublicRoomsResponse FromJson<PublicRoomsResponse>::operator()(const QJsonValue& jv) +PublicRoomsResponse FromJsonObject<PublicRoomsResponse>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); PublicRoomsResponse result; result.chunk = - fromJson<QVector<PublicRoomsChunk>>(_json.value("chunk"_ls)); + fromJson<QVector<PublicRoomsChunk>>(jo.value("chunk"_ls)); result.nextBatch = - fromJson<QString>(_json.value("next_batch"_ls)); + fromJson<QString>(jo.value("next_batch"_ls)); result.prevBatch = - fromJson<QString>(_json.value("prev_batch"_ls)); + fromJson<QString>(jo.value("prev_batch"_ls)); result.totalRoomCountEstimate = - fromJson<qint64>(_json.value("total_room_count_estimate"_ls)); - + fromJson<int>(jo.value("total_room_count_estimate"_ls)); + return result; } diff --git a/lib/csapi/definitions/public_rooms_response.h b/lib/csapi/definitions/public_rooms_response.h index eea4bc5e..88c805ba 100644 --- a/lib/csapi/definitions/public_rooms_response.h +++ b/lib/csapi/definitions/public_rooms_response.h @@ -22,7 +22,7 @@ namespace QMatrixClient /// The name of the room, if any. QString name; /// The number of members joined to the room. - qint64 numJoinedMembers; + int numJoinedMembers; /// The ID of the room. QString roomId; /// The topic of the room, if any. @@ -39,9 +39,9 @@ namespace QMatrixClient QJsonObject toJson(const PublicRoomsChunk& pod); - template <> struct FromJson<PublicRoomsChunk> + template <> struct FromJsonObject<PublicRoomsChunk> { - PublicRoomsChunk operator()(const QJsonValue& jv); + PublicRoomsChunk operator()(const QJsonObject& jo) const; }; /// A list of the rooms on the server. @@ -59,14 +59,14 @@ namespace QMatrixClient QString prevBatch; /// An estimate on the total number of public rooms, if the /// server has an estimate. - Omittable<qint64> totalRoomCountEstimate; + Omittable<int> totalRoomCountEstimate; }; QJsonObject toJson(const PublicRoomsResponse& pod); - template <> struct FromJson<PublicRoomsResponse> + template <> struct FromJsonObject<PublicRoomsResponse> { - PublicRoomsResponse operator()(const QJsonValue& jv); + PublicRoomsResponse operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp index 19351ae1..045094bc 100644 --- a/lib/csapi/definitions/push_condition.cpp +++ b/lib/csapi/definitions/push_condition.cpp @@ -8,27 +8,26 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushCondition& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("kind"), pod.kind); - addParam<IfNotEmpty>(_json, QStringLiteral("key"), pod.key); - addParam<IfNotEmpty>(_json, QStringLiteral("pattern"), pod.pattern); - addParam<IfNotEmpty>(_json, QStringLiteral("is"), pod.is); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("kind"), pod.kind); + addParam<IfNotEmpty>(jo, QStringLiteral("key"), pod.key); + addParam<IfNotEmpty>(jo, QStringLiteral("pattern"), pod.pattern); + addParam<IfNotEmpty>(jo, QStringLiteral("is"), pod.is); + return jo; } -PushCondition FromJson<PushCondition>::operator()(const QJsonValue& jv) +PushCondition FromJsonObject<PushCondition>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); PushCondition result; result.kind = - fromJson<QString>(_json.value("kind"_ls)); + fromJson<QString>(jo.value("kind"_ls)); result.key = - fromJson<QString>(_json.value("key"_ls)); + fromJson<QString>(jo.value("key"_ls)); result.pattern = - fromJson<QString>(_json.value("pattern"_ls)); + fromJson<QString>(jo.value("pattern"_ls)); result.is = - fromJson<QString>(_json.value("is"_ls)); - + fromJson<QString>(jo.value("is"_ls)); + return result; } diff --git a/lib/csapi/definitions/push_condition.h b/lib/csapi/definitions/push_condition.h index 99d7083c..defcebb3 100644 --- a/lib/csapi/definitions/push_condition.h +++ b/lib/csapi/definitions/push_condition.h @@ -31,9 +31,9 @@ namespace QMatrixClient QJsonObject toJson(const PushCondition& pod); - template <> struct FromJson<PushCondition> + template <> struct FromJsonObject<PushCondition> { - PushCondition operator()(const QJsonValue& jv); + PushCondition operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp index 833135ec..baddd187 100644 --- a/lib/csapi/definitions/push_rule.cpp +++ b/lib/csapi/definitions/push_rule.cpp @@ -8,33 +8,32 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRule& pod) { - QJsonObject _json; - addParam<>(_json, QStringLiteral("actions"), pod.actions); - addParam<>(_json, QStringLiteral("default"), pod.isDefault); - addParam<>(_json, QStringLiteral("enabled"), pod.enabled); - addParam<>(_json, QStringLiteral("rule_id"), pod.ruleId); - addParam<IfNotEmpty>(_json, QStringLiteral("conditions"), pod.conditions); - addParam<IfNotEmpty>(_json, QStringLiteral("pattern"), pod.pattern); - return _json; + QJsonObject jo; + addParam<>(jo, QStringLiteral("actions"), pod.actions); + addParam<>(jo, QStringLiteral("default"), pod.isDefault); + addParam<>(jo, QStringLiteral("enabled"), pod.enabled); + addParam<>(jo, QStringLiteral("rule_id"), pod.ruleId); + addParam<IfNotEmpty>(jo, QStringLiteral("conditions"), pod.conditions); + addParam<IfNotEmpty>(jo, QStringLiteral("pattern"), pod.pattern); + return jo; } -PushRule FromJson<PushRule>::operator()(const QJsonValue& jv) +PushRule FromJsonObject<PushRule>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); PushRule result; result.actions = - fromJson<QVector<QVariant>>(_json.value("actions"_ls)); + fromJson<QVector<QVariant>>(jo.value("actions"_ls)); result.isDefault = - fromJson<bool>(_json.value("default"_ls)); + fromJson<bool>(jo.value("default"_ls)); result.enabled = - fromJson<bool>(_json.value("enabled"_ls)); + fromJson<bool>(jo.value("enabled"_ls)); result.ruleId = - fromJson<QString>(_json.value("rule_id"_ls)); + fromJson<QString>(jo.value("rule_id"_ls)); result.conditions = - fromJson<QVector<PushCondition>>(_json.value("conditions"_ls)); + fromJson<QVector<PushCondition>>(jo.value("conditions"_ls)); result.pattern = - fromJson<QString>(_json.value("pattern"_ls)); - + fromJson<QString>(jo.value("pattern"_ls)); + return result; } diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h index c6542aa6..5f52876d 100644 --- a/lib/csapi/definitions/push_rule.h +++ b/lib/csapi/definitions/push_rule.h @@ -37,9 +37,9 @@ namespace QMatrixClient QJsonObject toJson(const PushRule& pod); - template <> struct FromJson<PushRule> + template <> struct FromJsonObject<PushRule> { - PushRule operator()(const QJsonValue& jv); + PushRule operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp index c424f686..14b7a4b6 100644 --- a/lib/csapi/definitions/push_ruleset.cpp +++ b/lib/csapi/definitions/push_ruleset.cpp @@ -8,30 +8,29 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRuleset& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("content"), pod.content); - addParam<IfNotEmpty>(_json, QStringLiteral("override"), pod.override); - addParam<IfNotEmpty>(_json, QStringLiteral("room"), pod.room); - addParam<IfNotEmpty>(_json, QStringLiteral("sender"), pod.sender); - addParam<IfNotEmpty>(_json, QStringLiteral("underride"), pod.underride); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("content"), pod.content); + addParam<IfNotEmpty>(jo, QStringLiteral("override"), pod.override); + addParam<IfNotEmpty>(jo, QStringLiteral("room"), pod.room); + addParam<IfNotEmpty>(jo, QStringLiteral("sender"), pod.sender); + addParam<IfNotEmpty>(jo, QStringLiteral("underride"), pod.underride); + return jo; } -PushRuleset FromJson<PushRuleset>::operator()(const QJsonValue& jv) +PushRuleset FromJsonObject<PushRuleset>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); PushRuleset result; result.content = - fromJson<QVector<PushRule>>(_json.value("content"_ls)); + fromJson<QVector<PushRule>>(jo.value("content"_ls)); result.override = - fromJson<QVector<PushRule>>(_json.value("override"_ls)); + fromJson<QVector<PushRule>>(jo.value("override"_ls)); result.room = - fromJson<QVector<PushRule>>(_json.value("room"_ls)); + fromJson<QVector<PushRule>>(jo.value("room"_ls)); result.sender = - fromJson<QVector<PushRule>>(_json.value("sender"_ls)); + fromJson<QVector<PushRule>>(jo.value("sender"_ls)); result.underride = - fromJson<QVector<PushRule>>(_json.value("underride"_ls)); - + fromJson<QVector<PushRule>>(jo.value("underride"_ls)); + return result; } diff --git a/lib/csapi/definitions/push_ruleset.h b/lib/csapi/definitions/push_ruleset.h index a5e9ff2c..a274b72a 100644 --- a/lib/csapi/definitions/push_ruleset.h +++ b/lib/csapi/definitions/push_ruleset.h @@ -25,9 +25,9 @@ namespace QMatrixClient QJsonObject toJson(const PushRuleset& pod); - template <> struct FromJson<PushRuleset> + template <> struct FromJsonObject<PushRuleset> { - PushRuleset operator()(const QJsonValue& jv); + PushRuleset operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/room_event_filter.cpp b/lib/csapi/definitions/room_event_filter.cpp index 18ce07ec..f6f1e5cb 100644 --- a/lib/csapi/definitions/room_event_filter.cpp +++ b/lib/csapi/definitions/room_event_filter.cpp @@ -8,24 +8,23 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomEventFilter& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("not_rooms"), pod.notRooms); - addParam<IfNotEmpty>(_json, QStringLiteral("rooms"), pod.rooms); - addParam<IfNotEmpty>(_json, QStringLiteral("contains_url"), pod.containsUrl); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("not_rooms"), pod.notRooms); + addParam<IfNotEmpty>(jo, QStringLiteral("rooms"), pod.rooms); + addParam<IfNotEmpty>(jo, QStringLiteral("contains_url"), pod.containsUrl); + return jo; } -RoomEventFilter FromJson<RoomEventFilter>::operator()(const QJsonValue& jv) +RoomEventFilter FromJsonObject<RoomEventFilter>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); RoomEventFilter result; result.notRooms = - fromJson<QStringList>(_json.value("not_rooms"_ls)); + fromJson<QStringList>(jo.value("not_rooms"_ls)); result.rooms = - fromJson<QStringList>(_json.value("rooms"_ls)); + fromJson<QStringList>(jo.value("rooms"_ls)); result.containsUrl = - fromJson<bool>(_json.value("contains_url"_ls)); - + fromJson<bool>(jo.value("contains_url"_ls)); + return result; } diff --git a/lib/csapi/definitions/room_event_filter.h b/lib/csapi/definitions/room_event_filter.h index 3252af30..697fe661 100644 --- a/lib/csapi/definitions/room_event_filter.h +++ b/lib/csapi/definitions/room_event_filter.h @@ -13,21 +13,21 @@ namespace QMatrixClient { // Data structures - struct RoomEventFilter : Filter + struct RoomEventFilter : EventFilter { /// A list of room IDs to exclude. If this list is absent then no rooms are excluded. A matching room will be excluded even if it is listed in the ``'rooms'`` filter. QStringList notRooms; /// A list of room IDs to include. If this list is absent then all rooms are included. QStringList rooms; - /// If ``true``, includes only events with a url key in their content. If ``false``, excludes those events. + /// If ``true``, includes only events with a ``url`` key in their content. If ``false``, excludes those events. Defaults to ``false``. bool containsUrl; }; QJsonObject toJson(const RoomEventFilter& pod); - template <> struct FromJson<RoomEventFilter> + template <> struct FromJsonObject<RoomEventFilter> { - RoomEventFilter operator()(const QJsonValue& jv); + RoomEventFilter operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/sync_filter.cpp b/lib/csapi/definitions/sync_filter.cpp index b42f15f5..bd87804c 100644 --- a/lib/csapi/definitions/sync_filter.cpp +++ b/lib/csapi/definitions/sync_filter.cpp @@ -8,65 +8,63 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomFilter& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("not_rooms"), pod.notRooms); - addParam<IfNotEmpty>(_json, QStringLiteral("rooms"), pod.rooms); - addParam<IfNotEmpty>(_json, QStringLiteral("ephemeral"), pod.ephemeral); - addParam<IfNotEmpty>(_json, QStringLiteral("include_leave"), pod.includeLeave); - addParam<IfNotEmpty>(_json, QStringLiteral("state"), pod.state); - addParam<IfNotEmpty>(_json, QStringLiteral("timeline"), pod.timeline); - addParam<IfNotEmpty>(_json, QStringLiteral("account_data"), pod.accountData); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("not_rooms"), pod.notRooms); + addParam<IfNotEmpty>(jo, QStringLiteral("rooms"), pod.rooms); + addParam<IfNotEmpty>(jo, QStringLiteral("ephemeral"), pod.ephemeral); + addParam<IfNotEmpty>(jo, QStringLiteral("include_leave"), pod.includeLeave); + addParam<IfNotEmpty>(jo, QStringLiteral("state"), pod.state); + addParam<IfNotEmpty>(jo, QStringLiteral("timeline"), pod.timeline); + addParam<IfNotEmpty>(jo, QStringLiteral("account_data"), pod.accountData); + return jo; } -RoomFilter FromJson<RoomFilter>::operator()(const QJsonValue& jv) +RoomFilter FromJsonObject<RoomFilter>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); RoomFilter result; result.notRooms = - fromJson<QStringList>(_json.value("not_rooms"_ls)); + fromJson<QStringList>(jo.value("not_rooms"_ls)); result.rooms = - fromJson<QStringList>(_json.value("rooms"_ls)); + fromJson<QStringList>(jo.value("rooms"_ls)); result.ephemeral = - fromJson<RoomEventFilter>(_json.value("ephemeral"_ls)); + fromJson<RoomEventFilter>(jo.value("ephemeral"_ls)); result.includeLeave = - fromJson<bool>(_json.value("include_leave"_ls)); + fromJson<bool>(jo.value("include_leave"_ls)); result.state = - fromJson<RoomEventFilter>(_json.value("state"_ls)); + fromJson<RoomEventFilter>(jo.value("state"_ls)); result.timeline = - fromJson<RoomEventFilter>(_json.value("timeline"_ls)); + fromJson<RoomEventFilter>(jo.value("timeline"_ls)); result.accountData = - fromJson<RoomEventFilter>(_json.value("account_data"_ls)); - + fromJson<RoomEventFilter>(jo.value("account_data"_ls)); + return result; } -QJsonObject QMatrixClient::toJson(const SyncFilter& pod) +QJsonObject QMatrixClient::toJson(const Filter& pod) { - QJsonObject _json; - addParam<IfNotEmpty>(_json, QStringLiteral("event_fields"), pod.eventFields); - addParam<IfNotEmpty>(_json, QStringLiteral("event_format"), pod.eventFormat); - addParam<IfNotEmpty>(_json, QStringLiteral("presence"), pod.presence); - addParam<IfNotEmpty>(_json, QStringLiteral("account_data"), pod.accountData); - addParam<IfNotEmpty>(_json, QStringLiteral("room"), pod.room); - return _json; + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("event_fields"), pod.eventFields); + addParam<IfNotEmpty>(jo, QStringLiteral("event_format"), pod.eventFormat); + addParam<IfNotEmpty>(jo, QStringLiteral("presence"), pod.presence); + addParam<IfNotEmpty>(jo, QStringLiteral("account_data"), pod.accountData); + addParam<IfNotEmpty>(jo, QStringLiteral("room"), pod.room); + return jo; } -SyncFilter FromJson<SyncFilter>::operator()(const QJsonValue& jv) +Filter FromJsonObject<Filter>::operator()(const QJsonObject& jo) const { - const auto& _json = jv.toObject(); - SyncFilter result; + Filter result; result.eventFields = - fromJson<QStringList>(_json.value("event_fields"_ls)); + fromJson<QStringList>(jo.value("event_fields"_ls)); result.eventFormat = - fromJson<QString>(_json.value("event_format"_ls)); + fromJson<QString>(jo.value("event_format"_ls)); result.presence = - fromJson<Filter>(_json.value("presence"_ls)); + fromJson<EventFilter>(jo.value("presence"_ls)); result.accountData = - fromJson<Filter>(_json.value("account_data"_ls)); + fromJson<EventFilter>(jo.value("account_data"_ls)); result.room = - fromJson<RoomFilter>(_json.value("room"_ls)); - + fromJson<RoomFilter>(jo.value("room"_ls)); + return result; } diff --git a/lib/csapi/definitions/sync_filter.h b/lib/csapi/definitions/sync_filter.h index 7f48f02c..ca275a9a 100644 --- a/lib/csapi/definitions/sync_filter.h +++ b/lib/csapi/definitions/sync_filter.h @@ -35,30 +35,30 @@ namespace QMatrixClient QJsonObject toJson(const RoomFilter& pod); - template <> struct FromJson<RoomFilter> + template <> struct FromJsonObject<RoomFilter> { - RoomFilter operator()(const QJsonValue& jv); + RoomFilter operator()(const QJsonObject& jo) const; }; - struct SyncFilter + struct Filter { /// List of event fields to include. If this list is absent then all fields are included. The entries may include '.' charaters to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' object. A literal '.' character in a field name may be escaped using a '\\'. A server may include more fields than were requested. QStringList eventFields; /// The format to use for events. 'client' will return the events in a format suitable for clients. 'federation' will return the raw event as receieved over federation. The default is 'client'. QString eventFormat; /// The presence updates to include. - Omittable<Filter> presence; + Omittable<EventFilter> presence; /// The user account data that isn't associated with rooms to include. - Omittable<Filter> accountData; + Omittable<EventFilter> accountData; /// Filters to be applied to room data. Omittable<RoomFilter> room; }; - QJsonObject toJson(const SyncFilter& pod); + QJsonObject toJson(const Filter& pod); - template <> struct FromJson<SyncFilter> + template <> struct FromJsonObject<Filter> { - SyncFilter operator()(const QJsonValue& jv); + Filter operator()(const QJsonObject& jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/user_identifier.cpp b/lib/csapi/definitions/user_identifier.cpp index 3d3acaba..80a6d450 100644 --- a/lib/csapi/definitions/user_identifier.cpp +++ b/lib/csapi/definitions/user_identifier.cpp @@ -8,19 +8,18 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const UserIdentifier& pod) { - QJsonObject _json = toJson(pod.additionalProperties); - addParam<>(_json, QStringLiteral("type"), pod.type); - return _json; + QJsonObject jo = toJson(pod.additionalProperties); + addParam<>(jo, QStringLiteral("type"), pod.type); + return jo; } -UserIdentifier FromJson<UserIdentifier>::operator()(const QJsonValue& jv) +UserIdentifier FromJsonObject<UserIdentifier>::operator()(QJsonObject jo) const { - auto _json = jv.toObject(); UserIdentifier result; result.type = - fromJson<QString>(_json.take("type"_ls)); - - result.additionalProperties = fromJson<QVariantHash>(_json); + fromJson<QString>(jo.take("type"_ls)); + + result.additionalProperties = fromJson<QVariantHash>(jo); return result; } diff --git a/lib/csapi/definitions/user_identifier.h b/lib/csapi/definitions/user_identifier.h index edc254d3..42614436 100644 --- a/lib/csapi/definitions/user_identifier.h +++ b/lib/csapi/definitions/user_identifier.h @@ -23,9 +23,9 @@ namespace QMatrixClient QJsonObject toJson(const UserIdentifier& pod); - template <> struct FromJson<UserIdentifier> + template <> struct FromJsonObject<UserIdentifier> { - UserIdentifier operator()(const QJsonValue& jv); + UserIdentifier operator()(QJsonObject jo) const; }; } // namespace QMatrixClient diff --git a/lib/csapi/definitions/wellknown/homeserver.cpp b/lib/csapi/definitions/wellknown/homeserver.cpp new file mode 100644 index 00000000..f1482ee4 --- /dev/null +++ b/lib/csapi/definitions/wellknown/homeserver.cpp @@ -0,0 +1,24 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "homeserver.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const HomeserverInformation& pod) +{ + QJsonObject jo; + addParam<>(jo, QStringLiteral("base_url"), pod.baseUrl); + return jo; +} + +HomeserverInformation FromJsonObject<HomeserverInformation>::operator()(const QJsonObject& jo) const +{ + HomeserverInformation result; + result.baseUrl = + fromJson<QString>(jo.value("base_url"_ls)); + + return result; +} + diff --git a/lib/csapi/definitions/wellknown/homeserver.h b/lib/csapi/definitions/wellknown/homeserver.h new file mode 100644 index 00000000..09d6ba63 --- /dev/null +++ b/lib/csapi/definitions/wellknown/homeserver.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "converters.h" + + +namespace QMatrixClient +{ + // Data structures + + /// Used by clients to discover homeserver information. + struct HomeserverInformation + { + /// The base URL for the homeserver for client-server connections. + QString baseUrl; + }; + + QJsonObject toJson(const HomeserverInformation& pod); + + template <> struct FromJsonObject<HomeserverInformation> + { + HomeserverInformation operator()(const QJsonObject& jo) const; + }; + +} // namespace QMatrixClient diff --git a/lib/csapi/definitions/wellknown/identity_server.cpp b/lib/csapi/definitions/wellknown/identity_server.cpp new file mode 100644 index 00000000..f9d7bc37 --- /dev/null +++ b/lib/csapi/definitions/wellknown/identity_server.cpp @@ -0,0 +1,24 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "identity_server.h" + +using namespace QMatrixClient; + +QJsonObject QMatrixClient::toJson(const IdentityServerInformation& pod) +{ + QJsonObject jo; + addParam<>(jo, QStringLiteral("base_url"), pod.baseUrl); + return jo; +} + +IdentityServerInformation FromJsonObject<IdentityServerInformation>::operator()(const QJsonObject& jo) const +{ + IdentityServerInformation result; + result.baseUrl = + fromJson<QString>(jo.value("base_url"_ls)); + + return result; +} + diff --git a/lib/csapi/definitions/wellknown/identity_server.h b/lib/csapi/definitions/wellknown/identity_server.h new file mode 100644 index 00000000..cb8ffcee --- /dev/null +++ b/lib/csapi/definitions/wellknown/identity_server.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "converters.h" + + +namespace QMatrixClient +{ + // Data structures + + /// Used by clients to discover identity server information. + struct IdentityServerInformation + { + /// The base URL for the identity server for client-server connections. + QString baseUrl; + }; + + QJsonObject toJson(const IdentityServerInformation& pod); + + template <> struct FromJsonObject<IdentityServerInformation> + { + IdentityServerInformation operator()(const QJsonObject& jo) const; + }; + +} // namespace QMatrixClient |