aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/csapi/admin.cpp16
-rw-r--r--lib/csapi/admin.h1
-rw-r--r--lib/csapi/administrative_contact.cpp24
-rw-r--r--lib/csapi/administrative_contact.h5
-rw-r--r--lib/csapi/banning.cpp7
-rw-r--r--lib/csapi/create_room.cpp55
-rw-r--r--lib/csapi/create_room.h9
-rw-r--r--lib/csapi/directory.cpp3
-rw-r--r--lib/csapi/inviting.cpp2
-rw-r--r--lib/csapi/joining.cpp44
-rw-r--r--lib/csapi/joining.h11
-rw-r--r--lib/csapi/kicking.cpp5
-rw-r--r--lib/csapi/list_public_rooms.cpp58
-rw-r--r--lib/csapi/list_public_rooms.h5
-rw-r--r--lib/csapi/login.cpp23
-rw-r--r--lib/csapi/notifications.cpp14
-rw-r--r--lib/csapi/notifications.h3
-rw-r--r--lib/csapi/profile.cpp6
-rw-r--r--lib/csapi/pusher.cpp49
-rw-r--r--lib/csapi/pusher.h5
-rw-r--r--lib/csapi/redaction.cpp3
-rw-r--r--lib/csapi/search.cpp112
-rw-r--r--lib/csapi/search.h13
-rw-r--r--lib/csapi/third_party_membership.cpp6
-rw-r--r--lib/csapi/to_device.cpp2
-rw-r--r--lib/csapi/typing.cpp4
-rw-r--r--lib/csapi/users.cpp12
-rw-r--r--lib/csapi/users.h1
28 files changed, 269 insertions, 229 deletions
diff --git a/lib/csapi/admin.cpp b/lib/csapi/admin.cpp
index 18bac4c9..a0f7f67f 100644
--- a/lib/csapi/admin.cpp
+++ b/lib/csapi/admin.cpp
@@ -20,14 +20,14 @@ namespace QMatrixClient
{
GetWhoIsJob::ConnectionInfo operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetWhoIsJob::ConnectionInfo result;
result.ip =
- fromJson<QString>(o.value("ip"));
+ fromJson<QString>(_json.value("ip"));
result.lastSeen =
- fromJson<qint64>(o.value("last_seen"));
+ fromJson<qint64>(_json.value("last_seen"));
result.userAgent =
- fromJson<QString>(o.value("user_agent"));
+ fromJson<QString>(_json.value("user_agent"));
return result;
}
@@ -37,10 +37,10 @@ namespace QMatrixClient
{
GetWhoIsJob::SessionInfo operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetWhoIsJob::SessionInfo result;
result.connections =
- fromJson<QVector<GetWhoIsJob::ConnectionInfo>>(o.value("connections"));
+ fromJson<QVector<GetWhoIsJob::ConnectionInfo>>(_json.value("connections"));
return result;
}
@@ -50,10 +50,10 @@ namespace QMatrixClient
{
GetWhoIsJob::DeviceInfo operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetWhoIsJob::DeviceInfo result;
result.sessions =
- fromJson<QVector<GetWhoIsJob::SessionInfo>>(o.value("sessions"));
+ fromJson<QVector<GetWhoIsJob::SessionInfo>>(_json.value("sessions"));
return result;
}
diff --git a/lib/csapi/admin.h b/lib/csapi/admin.h
index 74de8e08..e57c6cfe 100644
--- a/lib/csapi/admin.h
+++ b/lib/csapi/admin.h
@@ -7,6 +7,7 @@
#include "jobs/basejob.h"
#include <QtCore/QHash>
+#include "converters.h"
#include <QtCore/QVector>
namespace QMatrixClient
diff --git a/lib/csapi/administrative_contact.cpp b/lib/csapi/administrative_contact.cpp
index eeb7cb68..7c6c4141 100644
--- a/lib/csapi/administrative_contact.cpp
+++ b/lib/csapi/administrative_contact.cpp
@@ -20,12 +20,12 @@ namespace QMatrixClient
{
GetAccount3PIDsJob::ThirdPartyIdentifier operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetAccount3PIDsJob::ThirdPartyIdentifier result;
result.medium =
- fromJson<QString>(o.value("medium"));
+ fromJson<QString>(_json.value("medium"));
result.address =
- fromJson<QString>(o.value("address"));
+ fromJson<QString>(_json.value("address"));
return result;
}
@@ -71,12 +71,14 @@ namespace QMatrixClient
QJsonObject toJson(const Post3PIDsJob::ThreePidCredentials& pod)
{
- QJsonObject o;
- o.insert("client_secret", toJson(pod.clientSecret));
- o.insert("id_server", toJson(pod.idServer));
- o.insert("sid", toJson(pod.sid));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<>(_json, "client_secret", pod.clientSecret);
+ addToJson<>(_json, "id_server", pod.idServer);
+ addToJson<>(_json, "sid", pod.sid);
+ return _json;
}
} // namespace QMatrixClient
@@ -85,8 +87,8 @@ Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind)
basePath % "/account/3pid")
{
QJsonObject _data;
- _data.insert("three_pid_creds", toJson(threePidCreds));
- _data.insert("bind", toJson(bind));
+ addToJson<>(_data, "three_pid_creds", threePidCreds);
+ addToJson<IfNotEmpty>(_data, "bind", bind);
setRequestData(_data);
}
diff --git a/lib/csapi/administrative_contact.h b/lib/csapi/administrative_contact.h
index 55786389..2fbf5c0a 100644
--- a/lib/csapi/administrative_contact.h
+++ b/lib/csapi/administrative_contact.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include "converters.h"
#include <QtCore/QVector>
namespace QMatrixClient
@@ -58,11 +59,13 @@ namespace QMatrixClient
QString clientSecret;
QString idServer;
QString sid;
+
+ bool omitted;
};
// Construction/destruction
- explicit Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind = {});
+ explicit Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind = false);
};
class RequestTokenTo3PIDJob : public BaseJob
diff --git a/lib/csapi/banning.cpp b/lib/csapi/banning.cpp
index f66b27b6..5f1df39f 100644
--- a/lib/csapi/banning.cpp
+++ b/lib/csapi/banning.cpp
@@ -17,9 +17,8 @@ BanJob::BanJob(const QString& roomId, const QString& userId, const QString& reas
basePath % "/rooms/" % roomId % "/ban")
{
QJsonObject _data;
- _data.insert("user_id", toJson(userId));
- if (!reason.isEmpty())
- _data.insert("reason", toJson(reason));
+ addToJson<>(_data, "user_id", userId);
+ addToJson<IfNotEmpty>(_data, "reason", reason);
setRequestData(_data);
}
@@ -28,7 +27,7 @@ UnbanJob::UnbanJob(const QString& roomId, const QString& userId)
basePath % "/rooms/" % roomId % "/unban")
{
QJsonObject _data;
- _data.insert("user_id", toJson(userId));
+ addToJson<>(_data, "user_id", userId);
setRequestData(_data);
}
diff --git a/lib/csapi/create_room.cpp b/lib/csapi/create_room.cpp
index 3764eeab..72c8d547 100644
--- a/lib/csapi/create_room.cpp
+++ b/lib/csapi/create_room.cpp
@@ -18,22 +18,26 @@ namespace QMatrixClient
QJsonObject toJson(const CreateRoomJob::Invite3pid& pod)
{
- QJsonObject o;
- o.insert("id_server", toJson(pod.idServer));
- o.insert("medium", toJson(pod.medium));
- o.insert("address", toJson(pod.address));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<>(_json, "id_server", pod.idServer);
+ addToJson<>(_json, "medium", pod.medium);
+ addToJson<>(_json, "address", pod.address);
+ return _json;
}
QJsonObject toJson(const CreateRoomJob::StateEvent& pod)
{
- QJsonObject o;
- o.insert("type", toJson(pod.type));
- o.insert("state_key", toJson(pod.stateKey));
- o.insert("content", toJson(pod.content));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<IfNotEmpty>(_json, "type", pod.type);
+ addToJson<IfNotEmpty>(_json, "state_key", pod.stateKey);
+ addToJson<IfNotEmpty>(_json, "content", pod.content);
+ return _json;
}
} // namespace QMatrixClient
@@ -49,22 +53,17 @@ CreateRoomJob::CreateRoomJob(const QString& visibility, const QString& roomAlias
, d(new Private)
{
QJsonObject _data;
- if (!visibility.isEmpty())
- _data.insert("visibility", toJson(visibility));
- if (!roomAliasName.isEmpty())
- _data.insert("room_alias_name", toJson(roomAliasName));
- if (!name.isEmpty())
- _data.insert("name", toJson(name));
- if (!topic.isEmpty())
- _data.insert("topic", toJson(topic));
- _data.insert("invite", toJson(invite));
- _data.insert("invite_3pid", toJson(invite3pid));
- _data.insert("creation_content", toJson(creationContent));
- _data.insert("initial_state", toJson(initialState));
- if (!preset.isEmpty())
- _data.insert("preset", toJson(preset));
- _data.insert("is_direct", toJson(isDirect));
- _data.insert("guest_can_join", toJson(guestCanJoin));
+ 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);
setRequestData(_data);
}
diff --git a/lib/csapi/create_room.h b/lib/csapi/create_room.h
index a93215ea..c5f5edf5 100644
--- a/lib/csapi/create_room.h
+++ b/lib/csapi/create_room.h
@@ -6,9 +6,10 @@
#include "jobs/basejob.h"
-#include <QtCore/QVector>
#include <QtCore/QJsonObject>
#include <QtCore/QStringList>
+#include <QtCore/QVector>
+#include "converters.h"
namespace QMatrixClient
{
@@ -24,6 +25,8 @@ namespace QMatrixClient
QString idServer;
QString medium;
QString address;
+
+ bool omitted;
};
struct StateEvent
@@ -31,11 +34,13 @@ namespace QMatrixClient
QString type;
QString stateKey;
QJsonObject content;
+
+ bool omitted;
};
// Construction/destruction
- explicit CreateRoomJob(const QString& visibility = {}, const QString& roomAliasName = {}, const QString& name = {}, const QString& topic = {}, const QStringList& invite = {}, const QVector<Invite3pid>& invite3pid = {}, const QJsonObject& creationContent = {}, const QVector<StateEvent>& initialState = {}, const QString& preset = {}, bool isDirect = {}, bool guestCanJoin = {});
+ explicit CreateRoomJob(const QString& visibility = {}, const QString& roomAliasName = {}, const QString& name = {}, const QString& topic = {}, const QStringList& invite = {}, const QVector<Invite3pid>& invite3pid = {}, const QJsonObject& creationContent = {}, const QVector<StateEvent>& initialState = {}, const QString& preset = {}, bool isDirect = false, bool guestCanJoin = false);
~CreateRoomJob() override;
// Result properties
diff --git a/lib/csapi/directory.cpp b/lib/csapi/directory.cpp
index 3066ebe2..d5c5882f 100644
--- a/lib/csapi/directory.cpp
+++ b/lib/csapi/directory.cpp
@@ -17,8 +17,7 @@ SetRoomAliasJob::SetRoomAliasJob(const QString& roomAlias, const QString& roomId
basePath % "/room/" % roomAlias)
{
QJsonObject _data;
- if (!roomId.isEmpty())
- _data.insert("room_id", toJson(roomId));
+ addToJson<IfNotEmpty>(_data, "room_id", roomId);
setRequestData(_data);
}
diff --git a/lib/csapi/inviting.cpp b/lib/csapi/inviting.cpp
index d2ee2107..6f180e6c 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;
- _data.insert("user_id", toJson(userId));
+ addToJson<>(_data, "user_id", userId);
setRequestData(_data);
}
diff --git a/lib/csapi/joining.cpp b/lib/csapi/joining.cpp
index 71c93867..6f8081d0 100644
--- a/lib/csapi/joining.cpp
+++ b/lib/csapi/joining.cpp
@@ -18,13 +18,15 @@ namespace QMatrixClient
QJsonObject toJson(const JoinRoomByIdJob::ThirdPartySigned& pod)
{
- QJsonObject o;
- o.insert("sender", toJson(pod.sender));
- o.insert("mxid", toJson(pod.mxid));
- o.insert("token", toJson(pod.token));
- o.insert("signatures", toJson(pod.signatures));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<>(_json, "sender", pod.sender);
+ addToJson<>(_json, "mxid", pod.mxid);
+ addToJson<>(_json, "token", pod.token);
+ addToJson<>(_json, "signatures", pod.signatures);
+ return _json;
}
} // namespace QMatrixClient
@@ -40,7 +42,7 @@ JoinRoomByIdJob::JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned&
, d(new Private)
{
QJsonObject _data;
- _data.insert("third_party_signed", toJson(thirdPartySigned));
+ addToJson<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned);
setRequestData(_data);
}
@@ -67,21 +69,25 @@ namespace QMatrixClient
QJsonObject toJson(const JoinRoomJob::Signed& pod)
{
- QJsonObject o;
- o.insert("sender", toJson(pod.sender));
- o.insert("mxid", toJson(pod.mxid));
- o.insert("token", toJson(pod.token));
- o.insert("signatures", toJson(pod.signatures));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<>(_json, "sender", pod.sender);
+ addToJson<>(_json, "mxid", pod.mxid);
+ addToJson<>(_json, "token", pod.token);
+ addToJson<>(_json, "signatures", pod.signatures);
+ return _json;
}
QJsonObject toJson(const JoinRoomJob::ThirdPartySigned& pod)
{
- QJsonObject o;
- o.insert("signed", toJson(pod.signedData));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<>(_json, "signed", pod.signedData);
+ return _json;
}
} // namespace QMatrixClient
@@ -97,7 +103,7 @@ JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& t
, d(new Private)
{
QJsonObject _data;
- _data.insert("third_party_signed", toJson(thirdPartySigned));
+ addToJson<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned);
setRequestData(_data);
}
diff --git a/lib/csapi/joining.h b/lib/csapi/joining.h
index f6200dff..d7c7cbb1 100644
--- a/lib/csapi/joining.h
+++ b/lib/csapi/joining.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include "converters.h"
#include <QtCore/QJsonObject>
namespace QMatrixClient
@@ -23,11 +24,13 @@ namespace QMatrixClient
QString mxid;
QString token;
QJsonObject signatures;
+
+ bool omitted;
};
// Construction/destruction
- explicit JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned& thirdPartySigned = {});
+ explicit JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned& thirdPartySigned = omitted<ThirdPartySigned>());
~JoinRoomByIdJob() override;
// Result properties
@@ -53,16 +56,20 @@ namespace QMatrixClient
QString mxid;
QString token;
QJsonObject signatures;
+
+ bool omitted;
};
struct ThirdPartySigned
{
Signed signedData;
+
+ bool omitted;
};
// Construction/destruction
- explicit JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& thirdPartySigned = {});
+ explicit JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& thirdPartySigned = omitted<ThirdPartySigned>());
~JoinRoomJob() override;
// Result properties
diff --git a/lib/csapi/kicking.cpp b/lib/csapi/kicking.cpp
index bf2490b7..e143166a 100644
--- a/lib/csapi/kicking.cpp
+++ b/lib/csapi/kicking.cpp
@@ -17,9 +17,8 @@ KickJob::KickJob(const QString& roomId, const QString& userId, const QString& re
basePath % "/rooms/" % roomId % "/kick")
{
QJsonObject _data;
- _data.insert("user_id", toJson(userId));
- if (!reason.isEmpty())
- _data.insert("reason", toJson(reason));
+ addToJson<>(_data, "user_id", userId);
+ addToJson<IfNotEmpty>(_data, "reason", reason);
setRequestData(_data);
}
diff --git a/lib/csapi/list_public_rooms.cpp b/lib/csapi/list_public_rooms.cpp
index 65ffd3a3..b60d14fd 100644
--- a/lib/csapi/list_public_rooms.cpp
+++ b/lib/csapi/list_public_rooms.cpp
@@ -50,8 +50,7 @@ SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString&
basePath % "/directory/list/room/" % roomId)
{
QJsonObject _data;
- if (!visibility.isEmpty())
- _data.insert("visibility", toJson(visibility));
+ addToJson<IfNotEmpty>(_data, "visibility", visibility);
setRequestData(_data);
}
@@ -63,26 +62,26 @@ namespace QMatrixClient
{
GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetPublicRoomsJob::PublicRoomsChunk result;
result.aliases =
- fromJson<QStringList>(o.value("aliases"));
+ fromJson<QStringList>(_json.value("aliases"));
result.canonicalAlias =
- fromJson<QString>(o.value("canonical_alias"));
+ fromJson<QString>(_json.value("canonical_alias"));
result.name =
- fromJson<QString>(o.value("name"));
+ fromJson<QString>(_json.value("name"));
result.numJoinedMembers =
- fromJson<qint64>(o.value("num_joined_members"));
+ fromJson<qint64>(_json.value("num_joined_members"));
result.roomId =
- fromJson<QString>(o.value("room_id"));
+ fromJson<QString>(_json.value("room_id"));
result.topic =
- fromJson<QString>(o.value("topic"));
+ fromJson<QString>(_json.value("topic"));
result.worldReadable =
- fromJson<bool>(o.value("world_readable"));
+ fromJson<bool>(_json.value("world_readable"));
result.guestCanJoin =
- fromJson<bool>(o.value("guest_can_join"));
+ fromJson<bool>(_json.value("guest_can_join"));
result.avatarUrl =
- fromJson<QString>(o.value("avatar_url"));
+ fromJson<QString>(_json.value("avatar_url"));
return result;
}
@@ -166,36 +165,38 @@ namespace QMatrixClient
QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod)
{
- QJsonObject o;
- o.insert("generic_search_term", toJson(pod.genericSearchTerm));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<IfNotEmpty>(_json, "generic_search_term", pod.genericSearchTerm);
+ return _json;
}
template <> struct FromJson<QueryPublicRoomsJob::PublicRoomsChunk>
{
QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
QueryPublicRoomsJob::PublicRoomsChunk result;
result.aliases =
- fromJson<QStringList>(o.value("aliases"));
+ fromJson<QStringList>(_json.value("aliases"));
result.canonicalAlias =
- fromJson<QString>(o.value("canonical_alias"));
+ fromJson<QString>(_json.value("canonical_alias"));
result.name =
- fromJson<QString>(o.value("name"));
+ fromJson<QString>(_json.value("name"));
result.numJoinedMembers =
- fromJson<qint64>(o.value("num_joined_members"));
+ fromJson<qint64>(_json.value("num_joined_members"));
result.roomId =
- fromJson<QString>(o.value("room_id"));
+ fromJson<QString>(_json.value("room_id"));
result.topic =
- fromJson<QString>(o.value("topic"));
+ fromJson<QString>(_json.value("topic"));
result.worldReadable =
- fromJson<bool>(o.value("world_readable"));
+ fromJson<bool>(_json.value("world_readable"));
result.guestCanJoin =
- fromJson<bool>(o.value("guest_can_join"));
+ fromJson<bool>(_json.value("guest_can_join"));
result.avatarUrl =
- fromJson<QString>(o.value("avatar_url"));
+ fromJson<QString>(_json.value("avatar_url"));
return result;
}
@@ -226,10 +227,9 @@ QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, int limit, const
, d(new Private)
{
QJsonObject _data;
- _data.insert("limit", toJson(limit));
- if (!since.isEmpty())
- _data.insert("since", toJson(since));
- _data.insert("filter", toJson(filter));
+ addToJson<IfNotEmpty>(_data, "limit", limit);
+ addToJson<IfNotEmpty>(_data, "since", since);
+ addToJson<IfNotEmpty>(_data, "filter", filter);
setRequestData(_data);
}
diff --git a/lib/csapi/list_public_rooms.h b/lib/csapi/list_public_rooms.h
index fc30ad32..ae589378 100644
--- a/lib/csapi/list_public_rooms.h
+++ b/lib/csapi/list_public_rooms.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include "converters.h"
#include <QtCore/QVector>
#include <QtCore/QStringList>
@@ -99,6 +100,8 @@ namespace QMatrixClient
struct Filter
{
QString genericSearchTerm;
+
+ bool omitted;
};
struct PublicRoomsChunk
@@ -116,7 +119,7 @@ namespace QMatrixClient
// Construction/destruction
- explicit QueryPublicRoomsJob(const QString& server = {}, int limit = {}, const QString& since = {}, const Filter& filter = {});
+ explicit QueryPublicRoomsJob(const QString& server = {}, int limit = {}, const QString& since = {}, const Filter& filter = omitted<Filter>());
~QueryPublicRoomsJob() override;
// Result properties
diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp
index a4dab428..7e162871 100644
--- a/lib/csapi/login.cpp
+++ b/lib/csapi/login.cpp
@@ -27,21 +27,14 @@ LoginJob::LoginJob(const QString& type, const QString& user, const QString& medi
, d(new Private)
{
QJsonObject _data;
- _data.insert("type", toJson(type));
- if (!user.isEmpty())
- _data.insert("user", toJson(user));
- if (!medium.isEmpty())
- _data.insert("medium", toJson(medium));
- if (!address.isEmpty())
- _data.insert("address", toJson(address));
- if (!password.isEmpty())
- _data.insert("password", toJson(password));
- if (!token.isEmpty())
- _data.insert("token", toJson(token));
- if (!deviceId.isEmpty())
- _data.insert("device_id", toJson(deviceId));
- if (!initialDeviceDisplayName.isEmpty())
- _data.insert("initial_device_display_name", toJson(initialDeviceDisplayName));
+ 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);
setRequestData(_data);
}
diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp
index 19b2e058..17628cc5 100644
--- a/lib/csapi/notifications.cpp
+++ b/lib/csapi/notifications.cpp
@@ -20,20 +20,20 @@ namespace QMatrixClient
{
GetNotificationsJob::Notification operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetNotificationsJob::Notification result;
result.actions =
- fromJson<QVector<QJsonObject>>(o.value("actions"));
+ fromJson<QVector<QJsonObject>>(_json.value("actions"));
result.event =
- fromJson<EventPtr>(o.value("event"));
+ fromJson<EventPtr>(_json.value("event"));
result.profileTag =
- fromJson<QString>(o.value("profile_tag"));
+ fromJson<QString>(_json.value("profile_tag"));
result.read =
- fromJson<bool>(o.value("read"));
+ fromJson<bool>(_json.value("read"));
result.roomId =
- fromJson<QString>(o.value("room_id"));
+ fromJson<QString>(_json.value("room_id"));
result.ts =
- fromJson<qint64>(o.value("ts"));
+ fromJson<qint64>(_json.value("ts"));
return result;
}
diff --git a/lib/csapi/notifications.h b/lib/csapi/notifications.h
index 1e19471b..2180c658 100644
--- a/lib/csapi/notifications.h
+++ b/lib/csapi/notifications.h
@@ -6,9 +6,10 @@
#include "jobs/basejob.h"
-#include "events/event.h"
#include <QtCore/QJsonObject>
+#include "events/event.h"
#include <QtCore/QVector>
+#include "converters.h"
namespace QMatrixClient
{
diff --git a/lib/csapi/profile.cpp b/lib/csapi/profile.cpp
index d8ddbc14..6b93d961 100644
--- a/lib/csapi/profile.cpp
+++ b/lib/csapi/profile.cpp
@@ -17,8 +17,7 @@ SetDisplayNameJob::SetDisplayNameJob(const QString& userId, const QString& displ
basePath % "/profile/" % userId % "/displayname")
{
QJsonObject _data;
- if (!displayname.isEmpty())
- _data.insert("displayname", toJson(displayname));
+ addToJson<IfNotEmpty>(_data, "displayname", displayname);
setRequestData(_data);
}
@@ -60,8 +59,7 @@ SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QString& avatarUrl
basePath % "/profile/" % userId % "/avatar_url")
{
QJsonObject _data;
- if (!avatarUrl.isEmpty())
- _data.insert("avatar_url", toJson(avatarUrl));
+ addToJson<IfNotEmpty>(_data, "avatar_url", avatarUrl);
setRequestData(_data);
}
diff --git a/lib/csapi/pusher.cpp b/lib/csapi/pusher.cpp
index 324f7991..90ac032b 100644
--- a/lib/csapi/pusher.cpp
+++ b/lib/csapi/pusher.cpp
@@ -20,10 +20,10 @@ namespace QMatrixClient
{
GetPushersJob::PusherData operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetPushersJob::PusherData result;
result.url =
- fromJson<QString>(o.value("url"));
+ fromJson<QString>(_json.value("url"));
return result;
}
@@ -33,24 +33,24 @@ namespace QMatrixClient
{
GetPushersJob::Pusher operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
GetPushersJob::Pusher result;
result.pushkey =
- fromJson<QString>(o.value("pushkey"));
+ fromJson<QString>(_json.value("pushkey"));
result.kind =
- fromJson<QString>(o.value("kind"));
+ fromJson<QString>(_json.value("kind"));
result.appId =
- fromJson<QString>(o.value("app_id"));
+ fromJson<QString>(_json.value("app_id"));
result.appDisplayName =
- fromJson<QString>(o.value("app_display_name"));
+ fromJson<QString>(_json.value("app_display_name"));
result.deviceDisplayName =
- fromJson<QString>(o.value("device_display_name"));
+ fromJson<QString>(_json.value("device_display_name"));
result.profileTag =
- fromJson<QString>(o.value("profile_tag"));
+ fromJson<QString>(_json.value("profile_tag"));
result.lang =
- fromJson<QString>(o.value("lang"));
+ fromJson<QString>(_json.value("lang"));
result.data =
- fromJson<GetPushersJob::PusherData>(o.value("data"));
+ fromJson<GetPushersJob::PusherData>(_json.value("data"));
return result;
}
@@ -96,10 +96,12 @@ namespace QMatrixClient
QJsonObject toJson(const PostPusherJob::PusherData& pod)
{
- QJsonObject o;
- o.insert("url", toJson(pod.url));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<IfNotEmpty>(_json, "url", pod.url);
+ return _json;
}
} // namespace QMatrixClient
@@ -108,16 +110,15 @@ PostPusherJob::PostPusherJob(const QString& pushkey, const QString& kind, const
basePath % "/pushers/set")
{
QJsonObject _data;
- _data.insert("pushkey", toJson(pushkey));
- _data.insert("kind", toJson(kind));
- _data.insert("app_id", toJson(appId));
- _data.insert("app_display_name", toJson(appDisplayName));
- _data.insert("device_display_name", toJson(deviceDisplayName));
- if (!profileTag.isEmpty())
- _data.insert("profile_tag", toJson(profileTag));
- _data.insert("lang", toJson(lang));
- _data.insert("data", toJson(data));
- _data.insert("append", toJson(append));
+ 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);
setRequestData(_data);
}
diff --git a/lib/csapi/pusher.h b/lib/csapi/pusher.h
index 36aa540a..501e93a1 100644
--- a/lib/csapi/pusher.h
+++ b/lib/csapi/pusher.h
@@ -7,6 +7,7 @@
#include "jobs/basejob.h"
#include <QtCore/QVector>
+#include "converters.h"
namespace QMatrixClient
{
@@ -67,10 +68,12 @@ namespace QMatrixClient
struct PusherData
{
QString url;
+
+ bool omitted;
};
// Construction/destruction
- explicit PostPusherJob(const QString& pushkey, const QString& kind, const QString& appId, const QString& appDisplayName, const QString& deviceDisplayName, const QString& lang, const PusherData& data, const QString& profileTag = {}, bool append = {});
+ explicit PostPusherJob(const QString& pushkey, const QString& kind, const QString& appId, const QString& appDisplayName, const QString& deviceDisplayName, const QString& lang, const PusherData& data, const QString& profileTag = {}, bool append = false);
};
} // namespace QMatrixClient
diff --git a/lib/csapi/redaction.cpp b/lib/csapi/redaction.cpp
index 0da35dfc..aa6e3b65 100644
--- a/lib/csapi/redaction.cpp
+++ b/lib/csapi/redaction.cpp
@@ -24,8 +24,7 @@ RedactEventJob::RedactEventJob(const QString& roomId, const QString& eventId, co
, d(new Private)
{
QJsonObject _data;
- if (!reason.isEmpty())
- _data.insert("reason", toJson(reason));
+ addToJson<IfNotEmpty>(_data, "reason", reason);
setRequestData(_data);
}
diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp
index 9e56c24d..1cda979f 100644
--- a/lib/csapi/search.cpp
+++ b/lib/csapi/search.cpp
@@ -18,62 +18,72 @@ namespace QMatrixClient
QJsonObject toJson(const SearchJob::IncludeEventContext& pod)
{
- QJsonObject o;
- o.insert("before_limit", toJson(pod.beforeLimit));
- o.insert("after_limit", toJson(pod.afterLimit));
- o.insert("include_profile", toJson(pod.includeProfile));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
+
+ addToJson<IfNotEmpty>(_json, "before_limit", pod.beforeLimit);
+ addToJson<IfNotEmpty>(_json, "after_limit", pod.afterLimit);
+ addToJson<IfNotEmpty>(_json, "include_profile", pod.includeProfile);
+ return _json;
}
QJsonObject toJson(const SearchJob::Group& pod)
{
- QJsonObject o;
- o.insert("key", toJson(pod.key));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<IfNotEmpty>(_json, "key", pod.key);
+ return _json;
}
QJsonObject toJson(const SearchJob::Groupings& pod)
{
- QJsonObject o;
- o.insert("group_by", toJson(pod.groupBy));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<IfNotEmpty>(_json, "group_by", pod.groupBy);
+ return _json;
}
QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod)
{
- QJsonObject o;
- o.insert("search_term", toJson(pod.searchTerm));
- o.insert("keys", toJson(pod.keys));
- o.insert("filter", toJson(pod.filter));
- o.insert("order_by", toJson(pod.orderBy));
- o.insert("event_context", toJson(pod.eventContext));
- o.insert("include_state", toJson(pod.includeState));
- o.insert("groupings", toJson(pod.groupings));
-
- return o;
+ QJsonObject _json;
+ if (pod.omitted)
+ return _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);
+ return _json;
}
QJsonObject toJson(const SearchJob::Categories& pod)
{
- QJsonObject o;
- o.insert("room_events", toJson(pod.roomEvents));
+ QJsonObject _json;
+ if (pod.omitted)
+ return _json;
- return o;
+ addToJson<IfNotEmpty>(_json, "room_events", pod.roomEvents);
+ return _json;
}
template <> struct FromJson<SearchJob::UserProfile>
{
SearchJob::UserProfile operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::UserProfile result;
result.displayname =
- fromJson<QString>(o.value("displayname"));
+ fromJson<QString>(_json.value("displayname"));
result.avatarUrl =
- fromJson<QString>(o.value("avatar_url"));
+ fromJson<QString>(_json.value("avatar_url"));
return result;
}
@@ -83,18 +93,18 @@ namespace QMatrixClient
{
SearchJob::EventContext operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::EventContext result;
result.begin =
- fromJson<QString>(o.value("start"));
+ fromJson<QString>(_json.value("start"));
result.end =
- fromJson<QString>(o.value("end"));
+ fromJson<QString>(_json.value("end"));
result.profileInfo =
- fromJson<QHash<QString, SearchJob::UserProfile>>(o.value("profile_info"));
+ fromJson<QHash<QString, SearchJob::UserProfile>>(_json.value("profile_info"));
result.eventsBefore =
- fromJson<RoomEvents>(o.value("events_before"));
+ fromJson<RoomEvents>(_json.value("events_before"));
result.eventsAfter =
- fromJson<RoomEvents>(o.value("events_after"));
+ fromJson<RoomEvents>(_json.value("events_after"));
return result;
}
@@ -104,14 +114,14 @@ namespace QMatrixClient
{
SearchJob::Result operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::Result result;
result.rank =
- fromJson<double>(o.value("rank"));
+ fromJson<double>(_json.value("rank"));
result.result =
- fromJson<RoomEventPtr>(o.value("result"));
+ fromJson<RoomEventPtr>(_json.value("result"));
result.context =
- fromJson<SearchJob::EventContext>(o.value("context"));
+ fromJson<SearchJob::EventContext>(_json.value("context"));
return result;
}
@@ -121,14 +131,14 @@ namespace QMatrixClient
{
SearchJob::GroupValue operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::GroupValue result;
result.nextBatch =
- fromJson<QString>(o.value("next_batch"));
+ fromJson<QString>(_json.value("next_batch"));
result.order =
- fromJson<int>(o.value("order"));
+ fromJson<int>(_json.value("order"));
result.results =
- fromJson<QStringList>(o.value("results"));
+ fromJson<QStringList>(_json.value("results"));
return result;
}
@@ -138,18 +148,18 @@ namespace QMatrixClient
{
SearchJob::ResultRoomEvents operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::ResultRoomEvents result;
result.count =
- fromJson<qint64>(o.value("count"));
+ fromJson<qint64>(_json.value("count"));
result.results =
- fromJson<std::vector<SearchJob::Result>>(o.value("results"));
+ fromJson<std::vector<SearchJob::Result>>(_json.value("results"));
result.state =
- fromJson<std::unordered_map<QString, StateEvents>>(o.value("state"));
+ fromJson<std::unordered_map<QString, StateEvents>>(_json.value("state"));
result.groups =
- fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(o.value("groups"));
+ fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(_json.value("groups"));
result.nextBatch =
- fromJson<QString>(o.value("next_batch"));
+ fromJson<QString>(_json.value("next_batch"));
return result;
}
@@ -159,10 +169,10 @@ namespace QMatrixClient
{
SearchJob::ResultCategories operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchJob::ResultCategories result;
result.roomEvents =
- fromJson<SearchJob::ResultRoomEvents>(o.value("room_events"));
+ fromJson<SearchJob::ResultRoomEvents>(_json.value("room_events"));
return result;
}
@@ -190,7 +200,7 @@ SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatc
, d(new Private)
{
QJsonObject _data;
- _data.insert("search_categories", toJson(searchCategories));
+ addToJson<>(_data, "search_categories", searchCategories);
setRequestData(_data);
}
diff --git a/lib/csapi/search.h b/lib/csapi/search.h
index c487f01c..f0fb4546 100644
--- a/lib/csapi/search.h
+++ b/lib/csapi/search.h
@@ -8,9 +8,10 @@
#include <unordered_map>
#include <QtCore/QHash>
-#include <QtCore/QJsonObject>
#include "events/event.h"
+#include <QtCore/QJsonObject>
#include <QtCore/QStringList>
+#include "converters.h"
#include <QtCore/QVector>
namespace QMatrixClient
@@ -27,16 +28,22 @@ namespace QMatrixClient
int beforeLimit;
int afterLimit;
bool includeProfile;
+
+ bool omitted;
};
struct Group
{
QString key;
+
+ bool omitted;
};
struct Groupings
{
QVector<Group> groupBy;
+
+ bool omitted;
};
struct RoomEventsCriteria
@@ -48,11 +55,15 @@ namespace QMatrixClient
IncludeEventContext eventContext;
bool includeState;
Groupings groupings;
+
+ bool omitted;
};
struct Categories
{
RoomEventsCriteria roomEvents;
+
+ bool omitted;
};
struct UserProfile
diff --git a/lib/csapi/third_party_membership.cpp b/lib/csapi/third_party_membership.cpp
index b637d481..4cdad48b 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;
- _data.insert("id_server", toJson(idServer));
- _data.insert("medium", toJson(medium));
- _data.insert("address", toJson(address));
+ addToJson<>(_data, "id_server", idServer);
+ addToJson<>(_data, "medium", medium);
+ addToJson<>(_data, "address", address);
setRequestData(_data);
}
diff --git a/lib/csapi/to_device.cpp b/lib/csapi/to_device.cpp
index e893fa44..dfc47ab5 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;
- _data.insert("messages", toJson(messages));
+ addToJson<IfNotEmpty>(_data, "messages", messages);
setRequestData(_data);
}
diff --git a/lib/csapi/typing.cpp b/lib/csapi/typing.cpp
index fa700290..898bc149 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;
- _data.insert("typing", toJson(typing));
- _data.insert("timeout", toJson(timeout));
+ addToJson<>(_data, "typing", typing);
+ addToJson<IfNotEmpty>(_data, "timeout", timeout);
setRequestData(_data);
}
diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp
index 80081885..36cdf3cc 100644
--- a/lib/csapi/users.cpp
+++ b/lib/csapi/users.cpp
@@ -20,14 +20,14 @@ namespace QMatrixClient
{
SearchUserDirectoryJob::User operator()(const QJsonValue& jv)
{
- const auto& o = jv.toObject();
+ const auto& _json = jv.toObject();
SearchUserDirectoryJob::User result;
result.userId =
- fromJson<QString>(o.value("user_id"));
+ fromJson<QString>(_json.value("user_id"));
result.displayName =
- fromJson<QString>(o.value("display_name"));
+ fromJson<QString>(_json.value("display_name"));
result.avatarUrl =
- fromJson<QString>(o.value("avatar_url"));
+ fromJson<QString>(_json.value("avatar_url"));
return result;
}
@@ -47,8 +47,8 @@ SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, int li
, d(new Private)
{
QJsonObject _data;
- _data.insert("search_term", toJson(searchTerm));
- _data.insert("limit", toJson(limit));
+ addToJson<>(_data, "search_term", searchTerm);
+ addToJson<IfNotEmpty>(_data, "limit", limit);
setRequestData(_data);
}
diff --git a/lib/csapi/users.h b/lib/csapi/users.h
index 2efcf640..203ddc37 100644
--- a/lib/csapi/users.h
+++ b/lib/csapi/users.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include "converters.h"
#include <QtCore/QVector>
namespace QMatrixClient