aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/definitions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/definitions')
-rw-r--r--lib/csapi/definitions/auth_data.cpp19
-rw-r--r--lib/csapi/definitions/auth_data.h8
-rw-r--r--lib/csapi/definitions/client_device.cpp23
-rw-r--r--lib/csapi/definitions/client_device.h8
-rw-r--r--lib/csapi/definitions/device_keys.cpp26
-rw-r--r--lib/csapi/definitions/device_keys.h8
-rw-r--r--lib/csapi/definitions/event_filter.cpp26
-rw-r--r--lib/csapi/definitions/event_filter.h8
-rw-r--r--lib/csapi/definitions/public_rooms_response.cpp61
-rw-r--r--lib/csapi/definitions/public_rooms_response.h16
-rw-r--r--lib/csapi/definitions/push_condition.cpp23
-rw-r--r--lib/csapi/definitions/push_condition.h8
-rw-r--r--lib/csapi/definitions/push_rule.cpp29
-rw-r--r--lib/csapi/definitions/push_rule.h12
-rw-r--r--lib/csapi/definitions/push_ruleset.cpp26
-rw-r--r--lib/csapi/definitions/push_ruleset.h8
-rw-r--r--lib/csapi/definitions/room_event_filter.cpp28
-rw-r--r--lib/csapi/definitions/room_event_filter.h16
-rw-r--r--lib/csapi/definitions/sync_filter.cpp74
-rw-r--r--lib/csapi/definitions/sync_filter.h51
-rw-r--r--lib/csapi/definitions/user_identifier.cpp16
-rw-r--r--lib/csapi/definitions/user_identifier.h8
-rw-r--r--lib/csapi/definitions/wellknown/homeserver.cpp14
-rw-r--r--lib/csapi/definitions/wellknown/homeserver.h8
-rw-r--r--lib/csapi/definitions/wellknown/identity_server.cpp14
-rw-r--r--lib/csapi/definitions/wellknown/identity_server.h8
26 files changed, 226 insertions, 320 deletions
diff --git a/lib/csapi/definitions/auth_data.cpp b/lib/csapi/definitions/auth_data.cpp
index f8639432..006b8c7e 100644
--- a/lib/csapi/definitions/auth_data.cpp
+++ b/lib/csapi/definitions/auth_data.cpp
@@ -6,23 +6,20 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const AuthenticationData& pod)
+void JsonObjectConverter<AuthenticationData>::dumpTo(
+ QJsonObject& jo, const AuthenticationData& pod)
{
- QJsonObject jo = toJson(pod.authInfo);
+ fillJson(jo, pod.authInfo);
addParam<>(jo, QStringLiteral("type"), pod.type);
addParam<IfNotEmpty>(jo, QStringLiteral("session"), pod.session);
- return jo;
}
-AuthenticationData FromJsonObject<AuthenticationData>::operator()(QJsonObject jo) const
+void JsonObjectConverter<AuthenticationData>::fillFrom(
+ QJsonObject jo, AuthenticationData& result)
{
- AuthenticationData result;
- result.type =
- fromJson<QString>(jo.take("type"_ls));
- result.session =
- fromJson<QString>(jo.take("session"_ls));
+ fromJson(jo.take("type"_ls), result.type);
+ fromJson(jo.take("session"_ls), result.session);
- result.authInfo = fromJson<QHash<QString, QJsonObject>>(jo);
- return result;
+ fromJson(jo, result.authInfo);
}
diff --git a/lib/csapi/definitions/auth_data.h b/lib/csapi/definitions/auth_data.h
index 661d3e5f..26eb205c 100644
--- a/lib/csapi/definitions/auth_data.h
+++ b/lib/csapi/definitions/auth_data.h
@@ -23,12 +23,10 @@ namespace QMatrixClient
/// Keys dependent on the login type
QHash<QString, QJsonObject> authInfo;
};
-
- QJsonObject toJson(const AuthenticationData& pod);
-
- template <> struct FromJsonObject<AuthenticationData>
+ template <> struct JsonObjectConverter<AuthenticationData>
{
- AuthenticationData operator()(QJsonObject jo) const;
+ static void dumpTo(QJsonObject& jo, const AuthenticationData& pod);
+ static void fillFrom(QJsonObject jo, AuthenticationData& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/client_device.cpp b/lib/csapi/definitions/client_device.cpp
index 4a192f85..752b806a 100644
--- a/lib/csapi/definitions/client_device.cpp
+++ b/lib/csapi/definitions/client_device.cpp
@@ -6,28 +6,21 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const Device& pod)
+void JsonObjectConverter<Device>::dumpTo(
+ QJsonObject& jo, const Device& pod)
{
- 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 FromJsonObject<Device>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<Device>::fillFrom(
+ const QJsonObject& jo, Device& result)
{
- Device result;
- result.deviceId =
- fromJson<QString>(jo.value("device_id"_ls));
- result.displayName =
- fromJson<QString>(jo.value("display_name"_ls));
- result.lastSeenIp =
- fromJson<QString>(jo.value("last_seen_ip"_ls));
- result.lastSeenTs =
- fromJson<qint64>(jo.value("last_seen_ts"_ls));
-
- return result;
+ fromJson(jo.value("device_id"_ls), result.deviceId);
+ fromJson(jo.value("display_name"_ls), result.displayName);
+ fromJson(jo.value("last_seen_ip"_ls), result.lastSeenIp);
+ fromJson(jo.value("last_seen_ts"_ls), result.lastSeenTs);
}
diff --git a/lib/csapi/definitions/client_device.h b/lib/csapi/definitions/client_device.h
index 9f10888a..a6224f71 100644
--- a/lib/csapi/definitions/client_device.h
+++ b/lib/csapi/definitions/client_device.h
@@ -28,12 +28,10 @@ namespace QMatrixClient
/// reasons).
Omittable<qint64> lastSeenTs;
};
-
- QJsonObject toJson(const Device& pod);
-
- template <> struct FromJsonObject<Device>
+ template <> struct JsonObjectConverter<Device>
{
- Device operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const Device& pod);
+ static void fillFrom(const QJsonObject& jo, Device& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/device_keys.cpp b/lib/csapi/definitions/device_keys.cpp
index a0e0ca42..1e79499f 100644
--- a/lib/csapi/definitions/device_keys.cpp
+++ b/lib/csapi/definitions/device_keys.cpp
@@ -6,31 +6,23 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const DeviceKeys& pod)
+void JsonObjectConverter<DeviceKeys>::dumpTo(
+ QJsonObject& jo, const DeviceKeys& pod)
{
- 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 FromJsonObject<DeviceKeys>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<DeviceKeys>::fillFrom(
+ const QJsonObject& jo, DeviceKeys& result)
{
- DeviceKeys result;
- result.userId =
- fromJson<QString>(jo.value("user_id"_ls));
- result.deviceId =
- fromJson<QString>(jo.value("device_id"_ls));
- result.algorithms =
- fromJson<QStringList>(jo.value("algorithms"_ls));
- result.keys =
- fromJson<QHash<QString, QString>>(jo.value("keys"_ls));
- result.signatures =
- fromJson<QHash<QString, QHash<QString, QString>>>(jo.value("signatures"_ls));
-
- return result;
+ fromJson(jo.value("user_id"_ls), result.userId);
+ fromJson(jo.value("device_id"_ls), result.deviceId);
+ fromJson(jo.value("algorithms"_ls), result.algorithms);
+ fromJson(jo.value("keys"_ls), result.keys);
+ fromJson(jo.value("signatures"_ls), result.signatures);
}
diff --git a/lib/csapi/definitions/device_keys.h b/lib/csapi/definitions/device_keys.h
index 6023e7e8..8ebe1125 100644
--- a/lib/csapi/definitions/device_keys.h
+++ b/lib/csapi/definitions/device_keys.h
@@ -34,12 +34,10 @@ namespace QMatrixClient
/// JSON`_.
QHash<QString, QHash<QString, QString>> signatures;
};
-
- QJsonObject toJson(const DeviceKeys& pod);
-
- template <> struct FromJsonObject<DeviceKeys>
+ template <> struct JsonObjectConverter<DeviceKeys>
{
- DeviceKeys operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const DeviceKeys& pod);
+ static void fillFrom(const QJsonObject& jo, DeviceKeys& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/event_filter.cpp b/lib/csapi/definitions/event_filter.cpp
index cc444db0..b20d7807 100644
--- a/lib/csapi/definitions/event_filter.cpp
+++ b/lib/csapi/definitions/event_filter.cpp
@@ -6,31 +6,23 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const EventFilter& pod)
+void JsonObjectConverter<EventFilter>::dumpTo(
+ QJsonObject& jo, const EventFilter& pod)
{
- 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;
}
-EventFilter FromJsonObject<EventFilter>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<EventFilter>::fillFrom(
+ const QJsonObject& jo, EventFilter& result)
{
- EventFilter result;
- result.limit =
- fromJson<int>(jo.value("limit"_ls));
- result.notSenders =
- fromJson<QStringList>(jo.value("not_senders"_ls));
- result.notTypes =
- fromJson<QStringList>(jo.value("not_types"_ls));
- result.senders =
- fromJson<QStringList>(jo.value("senders"_ls));
- result.types =
- fromJson<QStringList>(jo.value("types"_ls));
-
- return result;
+ fromJson(jo.value("limit"_ls), result.limit);
+ fromJson(jo.value("not_senders"_ls), result.notSenders);
+ fromJson(jo.value("not_types"_ls), result.notTypes);
+ fromJson(jo.value("senders"_ls), result.senders);
+ fromJson(jo.value("types"_ls), result.types);
}
diff --git a/lib/csapi/definitions/event_filter.h b/lib/csapi/definitions/event_filter.h
index 5c6a5b27..6de1fe79 100644
--- a/lib/csapi/definitions/event_filter.h
+++ b/lib/csapi/definitions/event_filter.h
@@ -25,12 +25,10 @@ namespace QMatrixClient
/// A list of event types to include. If this list is absent then all event types are included. A ``'*'`` can be used as a wildcard to match any sequence of characters.
QStringList types;
};
-
- QJsonObject toJson(const EventFilter& pod);
-
- template <> struct FromJsonObject<EventFilter>
+ template <> struct JsonObjectConverter<EventFilter>
{
- EventFilter operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const EventFilter& pod);
+ static void fillFrom(const QJsonObject& jo, EventFilter& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/public_rooms_response.cpp b/lib/csapi/definitions/public_rooms_response.cpp
index 2f52501d..0d26662c 100644
--- a/lib/csapi/definitions/public_rooms_response.cpp
+++ b/lib/csapi/definitions/public_rooms_response.cpp
@@ -6,9 +6,9 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const PublicRoomsChunk& pod)
+void JsonObjectConverter<PublicRoomsChunk>::dumpTo(
+ QJsonObject& jo, const PublicRoomsChunk& pod)
{
- QJsonObject jo;
addParam<IfNotEmpty>(jo, QStringLiteral("aliases"), pod.aliases);
addParam<IfNotEmpty>(jo, QStringLiteral("canonical_alias"), pod.canonicalAlias);
addParam<IfNotEmpty>(jo, QStringLiteral("name"), pod.name);
@@ -18,56 +18,37 @@ QJsonObject QMatrixClient::toJson(const PublicRoomsChunk& pod)
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 FromJsonObject<PublicRoomsChunk>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<PublicRoomsChunk>::fillFrom(
+ const QJsonObject& jo, PublicRoomsChunk& result)
{
- PublicRoomsChunk result;
- result.aliases =
- fromJson<QStringList>(jo.value("aliases"_ls));
- result.canonicalAlias =
- fromJson<QString>(jo.value("canonical_alias"_ls));
- result.name =
- fromJson<QString>(jo.value("name"_ls));
- result.numJoinedMembers =
- fromJson<int>(jo.value("num_joined_members"_ls));
- result.roomId =
- fromJson<QString>(jo.value("room_id"_ls));
- result.topic =
- fromJson<QString>(jo.value("topic"_ls));
- result.worldReadable =
- fromJson<bool>(jo.value("world_readable"_ls));
- result.guestCanJoin =
- fromJson<bool>(jo.value("guest_can_join"_ls));
- result.avatarUrl =
- fromJson<QString>(jo.value("avatar_url"_ls));
-
- return result;
+ fromJson(jo.value("aliases"_ls), result.aliases);
+ fromJson(jo.value("canonical_alias"_ls), result.canonicalAlias);
+ fromJson(jo.value("name"_ls), result.name);
+ fromJson(jo.value("num_joined_members"_ls), result.numJoinedMembers);
+ fromJson(jo.value("room_id"_ls), result.roomId);
+ fromJson(jo.value("topic"_ls), result.topic);
+ fromJson(jo.value("world_readable"_ls), result.worldReadable);
+ fromJson(jo.value("guest_can_join"_ls), result.guestCanJoin);
+ fromJson(jo.value("avatar_url"_ls), result.avatarUrl);
}
-QJsonObject QMatrixClient::toJson(const PublicRoomsResponse& pod)
+void JsonObjectConverter<PublicRoomsResponse>::dumpTo(
+ QJsonObject& jo, const PublicRoomsResponse& pod)
{
- 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 FromJsonObject<PublicRoomsResponse>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<PublicRoomsResponse>::fillFrom(
+ const QJsonObject& jo, PublicRoomsResponse& result)
{
- PublicRoomsResponse result;
- result.chunk =
- fromJson<QVector<PublicRoomsChunk>>(jo.value("chunk"_ls));
- result.nextBatch =
- fromJson<QString>(jo.value("next_batch"_ls));
- result.prevBatch =
- fromJson<QString>(jo.value("prev_batch"_ls));
- result.totalRoomCountEstimate =
- fromJson<int>(jo.value("total_room_count_estimate"_ls));
-
- return result;
+ fromJson(jo.value("chunk"_ls), result.chunk);
+ fromJson(jo.value("next_batch"_ls), result.nextBatch);
+ fromJson(jo.value("prev_batch"_ls), result.prevBatch);
+ fromJson(jo.value("total_room_count_estimate"_ls), result.totalRoomCountEstimate);
}
diff --git a/lib/csapi/definitions/public_rooms_response.h b/lib/csapi/definitions/public_rooms_response.h
index 88c805ba..4c54ac25 100644
--- a/lib/csapi/definitions/public_rooms_response.h
+++ b/lib/csapi/definitions/public_rooms_response.h
@@ -36,12 +36,10 @@ namespace QMatrixClient
/// The URL for the room's avatar, if one is set.
QString avatarUrl;
};
-
- QJsonObject toJson(const PublicRoomsChunk& pod);
-
- template <> struct FromJsonObject<PublicRoomsChunk>
+ template <> struct JsonObjectConverter<PublicRoomsChunk>
{
- PublicRoomsChunk operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const PublicRoomsChunk& pod);
+ static void fillFrom(const QJsonObject& jo, PublicRoomsChunk& pod);
};
/// A list of the rooms on the server.
@@ -61,12 +59,10 @@ namespace QMatrixClient
/// server has an estimate.
Omittable<int> totalRoomCountEstimate;
};
-
- QJsonObject toJson(const PublicRoomsResponse& pod);
-
- template <> struct FromJsonObject<PublicRoomsResponse>
+ template <> struct JsonObjectConverter<PublicRoomsResponse>
{
- PublicRoomsResponse operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const PublicRoomsResponse& pod);
+ static void fillFrom(const QJsonObject& jo, PublicRoomsResponse& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp
index 045094bc..ace02755 100644
--- a/lib/csapi/definitions/push_condition.cpp
+++ b/lib/csapi/definitions/push_condition.cpp
@@ -6,28 +6,21 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const PushCondition& pod)
+void JsonObjectConverter<PushCondition>::dumpTo(
+ QJsonObject& jo, const PushCondition& pod)
{
- 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 FromJsonObject<PushCondition>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<PushCondition>::fillFrom(
+ const QJsonObject& jo, PushCondition& result)
{
- PushCondition result;
- result.kind =
- fromJson<QString>(jo.value("kind"_ls));
- result.key =
- fromJson<QString>(jo.value("key"_ls));
- result.pattern =
- fromJson<QString>(jo.value("pattern"_ls));
- result.is =
- fromJson<QString>(jo.value("is"_ls));
-
- return result;
+ fromJson(jo.value("kind"_ls), result.kind);
+ fromJson(jo.value("key"_ls), result.key);
+ fromJson(jo.value("pattern"_ls), result.pattern);
+ fromJson(jo.value("is"_ls), result.is);
}
diff --git a/lib/csapi/definitions/push_condition.h b/lib/csapi/definitions/push_condition.h
index defcebb3..e45526d2 100644
--- a/lib/csapi/definitions/push_condition.h
+++ b/lib/csapi/definitions/push_condition.h
@@ -28,12 +28,10 @@ namespace QMatrixClient
/// so forth. If no prefix is present, this parameter defaults to ==.
QString is;
};
-
- QJsonObject toJson(const PushCondition& pod);
-
- template <> struct FromJsonObject<PushCondition>
+ template <> struct JsonObjectConverter<PushCondition>
{
- PushCondition operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const PushCondition& pod);
+ static void fillFrom(const QJsonObject& jo, PushCondition& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp
index baddd187..abbb04b5 100644
--- a/lib/csapi/definitions/push_rule.cpp
+++ b/lib/csapi/definitions/push_rule.cpp
@@ -6,34 +6,25 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const PushRule& pod)
+void JsonObjectConverter<PushRule>::dumpTo(
+ QJsonObject& jo, const PushRule& pod)
{
- 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 FromJsonObject<PushRule>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<PushRule>::fillFrom(
+ const QJsonObject& jo, PushRule& result)
{
- PushRule result;
- result.actions =
- fromJson<QVector<QVariant>>(jo.value("actions"_ls));
- result.isDefault =
- fromJson<bool>(jo.value("default"_ls));
- result.enabled =
- fromJson<bool>(jo.value("enabled"_ls));
- result.ruleId =
- fromJson<QString>(jo.value("rule_id"_ls));
- result.conditions =
- fromJson<QVector<PushCondition>>(jo.value("conditions"_ls));
- result.pattern =
- fromJson<QString>(jo.value("pattern"_ls));
-
- return result;
+ fromJson(jo.value("actions"_ls), result.actions);
+ fromJson(jo.value("default"_ls), result.isDefault);
+ fromJson(jo.value("enabled"_ls), result.enabled);
+ fromJson(jo.value("rule_id"_ls), result.ruleId);
+ fromJson(jo.value("conditions"_ls), result.conditions);
+ fromJson(jo.value("pattern"_ls), result.pattern);
}
diff --git a/lib/csapi/definitions/push_rule.h b/lib/csapi/definitions/push_rule.h
index 5f52876d..bea13e96 100644
--- a/lib/csapi/definitions/push_rule.h
+++ b/lib/csapi/definitions/push_rule.h
@@ -7,10 +7,10 @@
#include "converters.h"
#include "csapi/definitions/push_condition.h"
-#include "converters.h"
+#include <QtCore/QJsonObject>
#include <QtCore/QVector>
#include <QtCore/QVariant>
-#include <QtCore/QJsonObject>
+#include "converters.h"
namespace QMatrixClient
{
@@ -34,12 +34,10 @@ namespace QMatrixClient
/// rules.
QString pattern;
};
-
- QJsonObject toJson(const PushRule& pod);
-
- template <> struct FromJsonObject<PushRule>
+ template <> struct JsonObjectConverter<PushRule>
{
- PushRule operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const PushRule& pod);
+ static void fillFrom(const QJsonObject& jo, PushRule& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp
index 14b7a4b6..f1bad882 100644
--- a/lib/csapi/definitions/push_ruleset.cpp
+++ b/lib/csapi/definitions/push_ruleset.cpp
@@ -6,31 +6,23 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const PushRuleset& pod)
+void JsonObjectConverter<PushRuleset>::dumpTo(
+ QJsonObject& jo, const PushRuleset& pod)
{
- 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 FromJsonObject<PushRuleset>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<PushRuleset>::fillFrom(
+ const QJsonObject& jo, PushRuleset& result)
{
- PushRuleset result;
- result.content =
- fromJson<QVector<PushRule>>(jo.value("content"_ls));
- result.override =
- fromJson<QVector<PushRule>>(jo.value("override"_ls));
- result.room =
- fromJson<QVector<PushRule>>(jo.value("room"_ls));
- result.sender =
- fromJson<QVector<PushRule>>(jo.value("sender"_ls));
- result.underride =
- fromJson<QVector<PushRule>>(jo.value("underride"_ls));
-
- return result;
+ fromJson(jo.value("content"_ls), result.content);
+ fromJson(jo.value("override"_ls), result.override);
+ fromJson(jo.value("room"_ls), result.room);
+ fromJson(jo.value("sender"_ls), result.sender);
+ fromJson(jo.value("underride"_ls), result.underride);
}
diff --git a/lib/csapi/definitions/push_ruleset.h b/lib/csapi/definitions/push_ruleset.h
index a274b72a..f2d937c0 100644
--- a/lib/csapi/definitions/push_ruleset.h
+++ b/lib/csapi/definitions/push_ruleset.h
@@ -22,12 +22,10 @@ namespace QMatrixClient
QVector<PushRule> sender;
QVector<PushRule> underride;
};
-
- QJsonObject toJson(const PushRuleset& pod);
-
- template <> struct FromJsonObject<PushRuleset>
+ template <> struct JsonObjectConverter<PushRuleset>
{
- PushRuleset operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const PushRuleset& pod);
+ static void fillFrom(const QJsonObject& jo, PushRuleset& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/room_event_filter.cpp b/lib/csapi/definitions/room_event_filter.cpp
index 8cd2ded7..df92e684 100644
--- a/lib/csapi/definitions/room_event_filter.cpp
+++ b/lib/csapi/definitions/room_event_filter.cpp
@@ -6,31 +6,21 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const RoomEventFilter& pod)
+void JsonObjectConverter<RoomEventFilter>::dumpTo(
+ QJsonObject& jo, const RoomEventFilter& pod)
{
- QJsonObject jo;
+ fillJson<EventFilter>(jo, pod);
addParam<IfNotEmpty>(jo, QStringLiteral("not_rooms"), pod.notRooms);
addParam<IfNotEmpty>(jo, QStringLiteral("rooms"), pod.rooms);
addParam<IfNotEmpty>(jo, QStringLiteral("contains_url"), pod.containsUrl);
- addParam<IfNotEmpty>(jo, QStringLiteral("lazy_load_members"), pod.lazyLoadMembers);
- addParam<IfNotEmpty>(jo, QStringLiteral("include_redundant_members"), pod.includeRedundantMembers);
- return jo;
}
-RoomEventFilter FromJsonObject<RoomEventFilter>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<RoomEventFilter>::fillFrom(
+ const QJsonObject& jo, RoomEventFilter& result)
{
- RoomEventFilter result;
- result.notRooms =
- fromJson<QStringList>(jo.value("not_rooms"_ls));
- result.rooms =
- fromJson<QStringList>(jo.value("rooms"_ls));
- result.containsUrl =
- fromJson<bool>(jo.value("contains_url"_ls));
- result.lazyLoadMembers =
- fromJson<bool>(jo.value("lazy_load_members"_ls));
- result.includeRedundantMembers =
- fromJson<bool>(jo.value("include_redundant_members"_ls));
-
- return result;
+ fillFromJson<EventFilter>(jo, result);
+ fromJson(jo.value("not_rooms"_ls), result.notRooms);
+ fromJson(jo.value("rooms"_ls), result.rooms);
+ fromJson(jo.value("contains_url"_ls), result.containsUrl);
}
diff --git a/lib/csapi/definitions/room_event_filter.h b/lib/csapi/definitions/room_event_filter.h
index 87f01189..6eb9a390 100644
--- a/lib/csapi/definitions/room_event_filter.h
+++ b/lib/csapi/definitions/room_event_filter.h
@@ -19,19 +19,13 @@ namespace QMatrixClient
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. Defaults to ``false``.
- bool containsUrl;
- /// If ``true``, the only ``m.room.member`` events returned in the ``state`` section of the ``/sync`` response are those which are definitely necessary for a client to display the ``sender`` of the timeline events in that response. If ``false``, ``m.room.member`` events are not filtered. By default, servers should suppress duplicate redundant lazy-loaded ``m.room.member`` events from being sent to a given client across multiple calls to ``/sync``, given that most clients cache membership events (see include_redundant_members to change this behaviour).
- bool lazyLoadMembers;
- /// If ``true``, the ``state`` section of the ``/sync`` response will always contain the ``m.room.member`` events required to display the ``sender`` of the timeline events in that response, assuming ``lazy_load_members`` is enabled. This means that redundant duplicate member events may be returned across multiple calls to ``/sync``. This is useful for naive clients who never track membership data. If ``false``, duplicate ``m.room.member`` events may be suppressed by the server across multiple calls to ``/sync``. If ``lazy_load_members`` is ``false`` this field is ignored.
- bool includeRedundantMembers;
+ /// If ``true``, includes only events with a ``url`` key in their content. If ``false``, excludes those events. If omitted, ``url`` key is not considered for filtering.
+ Omittable<bool> containsUrl;
};
-
- QJsonObject toJson(const RoomEventFilter& pod);
-
- template <> struct FromJsonObject<RoomEventFilter>
+ template <> struct JsonObjectConverter<RoomEventFilter>
{
- RoomEventFilter operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const RoomEventFilter& pod);
+ static void fillFrom(const QJsonObject& jo, RoomEventFilter& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/sync_filter.cpp b/lib/csapi/definitions/sync_filter.cpp
index bd87804c..32752d1f 100644
--- a/lib/csapi/definitions/sync_filter.cpp
+++ b/lib/csapi/definitions/sync_filter.cpp
@@ -6,9 +6,25 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const RoomFilter& pod)
+void JsonObjectConverter<StateFilter>::dumpTo(
+ QJsonObject& jo, const StateFilter& pod)
+{
+ fillJson<RoomEventFilter>(jo, pod);
+ addParam<IfNotEmpty>(jo, QStringLiteral("lazy_load_members"), pod.lazyLoadMembers);
+ addParam<IfNotEmpty>(jo, QStringLiteral("include_redundant_members"), pod.includeRedundantMembers);
+}
+
+void JsonObjectConverter<StateFilter>::fillFrom(
+ const QJsonObject& jo, StateFilter& result)
+{
+ fillFromJson<RoomEventFilter>(jo, result);
+ fromJson(jo.value("lazy_load_members"_ls), result.lazyLoadMembers);
+ fromJson(jo.value("include_redundant_members"_ls), result.includeRedundantMembers);
+}
+
+void JsonObjectConverter<RoomFilter>::dumpTo(
+ QJsonObject& jo, const RoomFilter& pod)
{
- QJsonObject jo;
addParam<IfNotEmpty>(jo, QStringLiteral("not_rooms"), pod.notRooms);
addParam<IfNotEmpty>(jo, QStringLiteral("rooms"), pod.rooms);
addParam<IfNotEmpty>(jo, QStringLiteral("ephemeral"), pod.ephemeral);
@@ -16,55 +32,37 @@ QJsonObject QMatrixClient::toJson(const RoomFilter& pod)
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 FromJsonObject<RoomFilter>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<RoomFilter>::fillFrom(
+ const QJsonObject& jo, RoomFilter& result)
{
- RoomFilter result;
- result.notRooms =
- fromJson<QStringList>(jo.value("not_rooms"_ls));
- result.rooms =
- fromJson<QStringList>(jo.value("rooms"_ls));
- result.ephemeral =
- fromJson<RoomEventFilter>(jo.value("ephemeral"_ls));
- result.includeLeave =
- fromJson<bool>(jo.value("include_leave"_ls));
- result.state =
- fromJson<RoomEventFilter>(jo.value("state"_ls));
- result.timeline =
- fromJson<RoomEventFilter>(jo.value("timeline"_ls));
- result.accountData =
- fromJson<RoomEventFilter>(jo.value("account_data"_ls));
-
- return result;
+ fromJson(jo.value("not_rooms"_ls), result.notRooms);
+ fromJson(jo.value("rooms"_ls), result.rooms);
+ fromJson(jo.value("ephemeral"_ls), result.ephemeral);
+ fromJson(jo.value("include_leave"_ls), result.includeLeave);
+ fromJson(jo.value("state"_ls), result.state);
+ fromJson(jo.value("timeline"_ls), result.timeline);
+ fromJson(jo.value("account_data"_ls), result.accountData);
}
-QJsonObject QMatrixClient::toJson(const Filter& pod)
+void JsonObjectConverter<Filter>::dumpTo(
+ QJsonObject& jo, const Filter& pod)
{
- 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;
}
-Filter FromJsonObject<Filter>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<Filter>::fillFrom(
+ const QJsonObject& jo, Filter& result)
{
- Filter result;
- result.eventFields =
- fromJson<QStringList>(jo.value("event_fields"_ls));
- result.eventFormat =
- fromJson<QString>(jo.value("event_format"_ls));
- result.presence =
- fromJson<EventFilter>(jo.value("presence"_ls));
- result.accountData =
- fromJson<EventFilter>(jo.value("account_data"_ls));
- result.room =
- fromJson<RoomFilter>(jo.value("room"_ls));
-
- return result;
+ fromJson(jo.value("event_fields"_ls), result.eventFields);
+ fromJson(jo.value("event_format"_ls), result.eventFormat);
+ fromJson(jo.value("presence"_ls), result.presence);
+ fromJson(jo.value("account_data"_ls), result.accountData);
+ fromJson(jo.value("room"_ls), result.room);
}
diff --git a/lib/csapi/definitions/sync_filter.h b/lib/csapi/definitions/sync_filter.h
index ca275a9a..d94c74d7 100644
--- a/lib/csapi/definitions/sync_filter.h
+++ b/lib/csapi/definitions/sync_filter.h
@@ -14,6 +14,37 @@ namespace QMatrixClient
{
// Data structures
+ /// The state events to include for rooms.
+ struct StateFilter : RoomEventFilter
+ {
+ /// If ``true``, the only ``m.room.member`` events returned in
+ /// the ``state`` section of the ``/sync`` response are those
+ /// which are definitely necessary for a client to display
+ /// the ``sender`` of the timeline events in that response.
+ /// If ``false``, ``m.room.member`` events are not filtered.
+ /// By default, servers should suppress duplicate redundant
+ /// lazy-loaded ``m.room.member`` events from being sent to a given
+ /// client across multiple calls to ``/sync``, given that most clients
+ /// cache membership events (see ``include_redundant_members``
+ /// to change this behaviour).
+ Omittable<bool> lazyLoadMembers;
+ /// If ``true``, the ``state`` section of the ``/sync`` response will
+ /// always contain the ``m.room.member`` events required to display
+ /// the ``sender`` of the timeline events in that response, assuming
+ /// ``lazy_load_members`` is enabled. This means that redundant
+ /// duplicate member events may be returned across multiple calls to
+ /// ``/sync``. This is useful for naive clients who never track
+ /// membership data. If ``false``, duplicate ``m.room.member`` events
+ /// may be suppressed by the server across multiple calls to ``/sync``.
+ /// If ``lazy_load_members`` is ``false`` this field is ignored.
+ Omittable<bool> includeRedundantMembers;
+ };
+ template <> struct JsonObjectConverter<StateFilter>
+ {
+ static void dumpTo(QJsonObject& jo, const StateFilter& pod);
+ static void fillFrom(const QJsonObject& jo, StateFilter& pod);
+ };
+
/// Filters to be applied to room data.
struct RoomFilter
{
@@ -24,20 +55,18 @@ namespace QMatrixClient
/// The events that aren't recorded in the room history, e.g. typing and receipts, to include for rooms.
Omittable<RoomEventFilter> ephemeral;
/// Include rooms that the user has left in the sync, default false
- bool includeLeave;
+ Omittable<bool> includeLeave;
/// The state events to include for rooms.
- Omittable<RoomEventFilter> state;
+ Omittable<StateFilter> state;
/// The message and state update events to include for rooms.
Omittable<RoomEventFilter> timeline;
/// The per user account data to include for rooms.
Omittable<RoomEventFilter> accountData;
};
-
- QJsonObject toJson(const RoomFilter& pod);
-
- template <> struct FromJsonObject<RoomFilter>
+ template <> struct JsonObjectConverter<RoomFilter>
{
- RoomFilter operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const RoomFilter& pod);
+ static void fillFrom(const QJsonObject& jo, RoomFilter& pod);
};
struct Filter
@@ -53,12 +82,10 @@ namespace QMatrixClient
/// Filters to be applied to room data.
Omittable<RoomFilter> room;
};
-
- QJsonObject toJson(const Filter& pod);
-
- template <> struct FromJsonObject<Filter>
+ template <> struct JsonObjectConverter<Filter>
{
- Filter operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const Filter& pod);
+ static void fillFrom(const QJsonObject& jo, Filter& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/user_identifier.cpp b/lib/csapi/definitions/user_identifier.cpp
index 80a6d450..05a27c1c 100644
--- a/lib/csapi/definitions/user_identifier.cpp
+++ b/lib/csapi/definitions/user_identifier.cpp
@@ -6,20 +6,18 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const UserIdentifier& pod)
+void JsonObjectConverter<UserIdentifier>::dumpTo(
+ QJsonObject& jo, const UserIdentifier& pod)
{
- QJsonObject jo = toJson(pod.additionalProperties);
+ fillJson(jo, pod.additionalProperties);
addParam<>(jo, QStringLiteral("type"), pod.type);
- return jo;
}
-UserIdentifier FromJsonObject<UserIdentifier>::operator()(QJsonObject jo) const
+void JsonObjectConverter<UserIdentifier>::fillFrom(
+ QJsonObject jo, UserIdentifier& result)
{
- UserIdentifier result;
- result.type =
- fromJson<QString>(jo.take("type"_ls));
+ fromJson(jo.take("type"_ls), result.type);
- result.additionalProperties = fromJson<QVariantHash>(jo);
- return result;
+ fromJson(jo, result.additionalProperties);
}
diff --git a/lib/csapi/definitions/user_identifier.h b/lib/csapi/definitions/user_identifier.h
index 42614436..cbb1550f 100644
--- a/lib/csapi/definitions/user_identifier.h
+++ b/lib/csapi/definitions/user_identifier.h
@@ -20,12 +20,10 @@ namespace QMatrixClient
/// Identification information for a user
QVariantHash additionalProperties;
};
-
- QJsonObject toJson(const UserIdentifier& pod);
-
- template <> struct FromJsonObject<UserIdentifier>
+ template <> struct JsonObjectConverter<UserIdentifier>
{
- UserIdentifier operator()(QJsonObject jo) const;
+ static void dumpTo(QJsonObject& jo, const UserIdentifier& pod);
+ static void fillFrom(QJsonObject jo, UserIdentifier& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/wellknown/homeserver.cpp b/lib/csapi/definitions/wellknown/homeserver.cpp
index f1482ee4..0783f11b 100644
--- a/lib/csapi/definitions/wellknown/homeserver.cpp
+++ b/lib/csapi/definitions/wellknown/homeserver.cpp
@@ -6,19 +6,15 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const HomeserverInformation& pod)
+void JsonObjectConverter<HomeserverInformation>::dumpTo(
+ QJsonObject& jo, const HomeserverInformation& pod)
{
- QJsonObject jo;
addParam<>(jo, QStringLiteral("base_url"), pod.baseUrl);
- return jo;
}
-HomeserverInformation FromJsonObject<HomeserverInformation>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<HomeserverInformation>::fillFrom(
+ const QJsonObject& jo, HomeserverInformation& result)
{
- HomeserverInformation result;
- result.baseUrl =
- fromJson<QString>(jo.value("base_url"_ls));
-
- return result;
+ fromJson(jo.value("base_url"_ls), result.baseUrl);
}
diff --git a/lib/csapi/definitions/wellknown/homeserver.h b/lib/csapi/definitions/wellknown/homeserver.h
index 09d6ba63..f6761c30 100644
--- a/lib/csapi/definitions/wellknown/homeserver.h
+++ b/lib/csapi/definitions/wellknown/homeserver.h
@@ -17,12 +17,10 @@ namespace QMatrixClient
/// The base URL for the homeserver for client-server connections.
QString baseUrl;
};
-
- QJsonObject toJson(const HomeserverInformation& pod);
-
- template <> struct FromJsonObject<HomeserverInformation>
+ template <> struct JsonObjectConverter<HomeserverInformation>
{
- HomeserverInformation operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const HomeserverInformation& pod);
+ static void fillFrom(const QJsonObject& jo, HomeserverInformation& pod);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/definitions/wellknown/identity_server.cpp b/lib/csapi/definitions/wellknown/identity_server.cpp
index f9d7bc37..99f36641 100644
--- a/lib/csapi/definitions/wellknown/identity_server.cpp
+++ b/lib/csapi/definitions/wellknown/identity_server.cpp
@@ -6,19 +6,15 @@
using namespace QMatrixClient;
-QJsonObject QMatrixClient::toJson(const IdentityServerInformation& pod)
+void JsonObjectConverter<IdentityServerInformation>::dumpTo(
+ QJsonObject& jo, const IdentityServerInformation& pod)
{
- QJsonObject jo;
addParam<>(jo, QStringLiteral("base_url"), pod.baseUrl);
- return jo;
}
-IdentityServerInformation FromJsonObject<IdentityServerInformation>::operator()(const QJsonObject& jo) const
+void JsonObjectConverter<IdentityServerInformation>::fillFrom(
+ const QJsonObject& jo, IdentityServerInformation& result)
{
- IdentityServerInformation result;
- result.baseUrl =
- fromJson<QString>(jo.value("base_url"_ls));
-
- return result;
+ fromJson(jo.value("base_url"_ls), result.baseUrl);
}
diff --git a/lib/csapi/definitions/wellknown/identity_server.h b/lib/csapi/definitions/wellknown/identity_server.h
index cb8ffcee..67d8b08d 100644
--- a/lib/csapi/definitions/wellknown/identity_server.h
+++ b/lib/csapi/definitions/wellknown/identity_server.h
@@ -17,12 +17,10 @@ namespace QMatrixClient
/// The base URL for the identity server for client-server connections.
QString baseUrl;
};
-
- QJsonObject toJson(const IdentityServerInformation& pod);
-
- template <> struct FromJsonObject<IdentityServerInformation>
+ template <> struct JsonObjectConverter<IdentityServerInformation>
{
- IdentityServerInformation operator()(const QJsonObject& jo) const;
+ static void dumpTo(QJsonObject& jo, const IdentityServerInformation& pod);
+ static void fillFrom(const QJsonObject& jo, IdentityServerInformation& pod);
};
} // namespace QMatrixClient