diff options
Diffstat (limited to 'lib/csapi')
59 files changed, 726 insertions, 536 deletions
diff --git a/lib/csapi/account-data.cpp b/lib/csapi/account-data.cpp index ac45cb85..5021c73a 100644 --- a/lib/csapi/account-data.cpp +++ b/lib/csapi/account-data.cpp @@ -12,15 +12,19 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto SetAccountDataJobName = QStringLiteral("SetAccountDataJob"); + SetAccountDataJob::SetAccountDataJob(const QString& userId, const QString& type, const QJsonObject& content) - : BaseJob(HttpVerb::Put, "SetAccountDataJob", + : BaseJob(HttpVerb::Put, SetAccountDataJobName, basePath % "/user/" % userId % "/account_data/" % type) { setRequestData(Data(toJson(content))); } +static const auto SetAccountDataPerRoomJobName = QStringLiteral("SetAccountDataPerRoomJob"); + SetAccountDataPerRoomJob::SetAccountDataPerRoomJob(const QString& userId, const QString& roomId, const QString& type, const QJsonObject& content) - : BaseJob(HttpVerb::Put, "SetAccountDataPerRoomJob", + : BaseJob(HttpVerb::Put, SetAccountDataPerRoomJobName, basePath % "/user/" % userId % "/rooms/" % roomId % "/account_data/" % type) { setRequestData(Data(toJson(content))); diff --git a/lib/csapi/admin.cpp b/lib/csapi/admin.cpp index a0f7f67f..3effbbc3 100644 --- a/lib/csapi/admin.cpp +++ b/lib/csapi/admin.cpp @@ -23,11 +23,11 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetWhoIsJob::ConnectionInfo result; result.ip = - fromJson<QString>(_json.value("ip")); + fromJson<QString>(_json.value("ip"_ls)); result.lastSeen = - fromJson<qint64>(_json.value("last_seen")); + fromJson<qint64>(_json.value("last_seen"_ls)); result.userAgent = - fromJson<QString>(_json.value("user_agent")); + fromJson<QString>(_json.value("user_agent"_ls)); return result; } @@ -40,7 +40,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetWhoIsJob::SessionInfo result; result.connections = - fromJson<QVector<GetWhoIsJob::ConnectionInfo>>(_json.value("connections")); + fromJson<QVector<GetWhoIsJob::ConnectionInfo>>(_json.value("connections"_ls)); return result; } @@ -53,7 +53,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetWhoIsJob::DeviceInfo result; result.sessions = - fromJson<QVector<GetWhoIsJob::SessionInfo>>(_json.value("sessions")); + fromJson<QVector<GetWhoIsJob::SessionInfo>>(_json.value("sessions"_ls)); return result; } @@ -73,8 +73,10 @@ QUrl GetWhoIsJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/admin/whois/" % userId); } +static const auto GetWhoIsJobName = QStringLiteral("GetWhoIsJob"); + GetWhoIsJob::GetWhoIsJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetWhoIsJob", + : BaseJob(HttpVerb::Get, GetWhoIsJobName, basePath % "/admin/whois/" % userId) , d(new Private) { @@ -95,8 +97,8 @@ const QHash<QString, GetWhoIsJob::DeviceInfo>& GetWhoIsJob::devices() const BaseJob::Status GetWhoIsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->userId = fromJson<QString>(json.value("user_id")); - d->devices = fromJson<QHash<QString, DeviceInfo>>(json.value("devices")); + d->userId = fromJson<QString>(json.value("user_id"_ls)); + d->devices = fromJson<QHash<QString, DeviceInfo>>(json.value("devices"_ls)); return Success; } diff --git a/lib/csapi/administrative_contact.cpp b/lib/csapi/administrative_contact.cpp index e3dee8ed..682a6f05 100644 --- a/lib/csapi/administrative_contact.cpp +++ b/lib/csapi/administrative_contact.cpp @@ -23,9 +23,9 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetAccount3PIDsJob::ThirdPartyIdentifier result; result.medium = - fromJson<QString>(_json.value("medium")); + fromJson<QString>(_json.value("medium"_ls)); result.address = - fromJson<QString>(_json.value("address")); + fromJson<QString>(_json.value("address"_ls)); return result; } @@ -44,8 +44,10 @@ QUrl GetAccount3PIDsJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/3pid"); } +static const auto GetAccount3PIDsJobName = QStringLiteral("GetAccount3PIDsJob"); + GetAccount3PIDsJob::GetAccount3PIDsJob() - : BaseJob(HttpVerb::Get, "GetAccount3PIDsJob", + : BaseJob(HttpVerb::Get, GetAccount3PIDsJobName, basePath % "/account/3pid") , d(new Private) { @@ -61,7 +63,7 @@ const QVector<GetAccount3PIDsJob::ThirdPartyIdentifier>& GetAccount3PIDsJob::thr BaseJob::Status GetAccount3PIDsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->threepids = fromJson<QVector<ThirdPartyIdentifier>>(json.value("threepids")); + d->threepids = fromJson<QVector<ThirdPartyIdentifier>>(json.value("threepids"_ls)); return Success; } @@ -72,20 +74,22 @@ namespace QMatrixClient QJsonObject toJson(const Post3PIDsJob::ThreePidCredentials& pod) { QJsonObject _json; - addParam<>(_json, "client_secret", pod.clientSecret); - addParam<>(_json, "id_server", pod.idServer); - addParam<>(_json, "sid", pod.sid); + addParam<>(_json, QStringLiteral("client_secret"), pod.clientSecret); + addParam<>(_json, QStringLiteral("id_server"), pod.idServer); + addParam<>(_json, QStringLiteral("sid"), pod.sid); return _json; } } // namespace QMatrixClient +static const auto Post3PIDsJobName = QStringLiteral("Post3PIDsJob"); + Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind) - : BaseJob(HttpVerb::Post, "Post3PIDsJob", + : BaseJob(HttpVerb::Post, Post3PIDsJobName, basePath % "/account/3pid") { QJsonObject _data; - addParam<>(_data, "three_pid_creds", threePidCreds); - addParam<IfNotEmpty>(_data, "bind", bind); + addParam<>(_data, QStringLiteral("three_pid_creds"), threePidCreds); + addParam<IfNotEmpty>(_data, QStringLiteral("bind"), bind); setRequestData(_data); } @@ -95,8 +99,10 @@ QUrl RequestTokenTo3PIDJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/3pid/email/requestToken"); } +static const auto RequestTokenTo3PIDJobName = QStringLiteral("RequestTokenTo3PIDJob"); + RequestTokenTo3PIDJob::RequestTokenTo3PIDJob() - : BaseJob(HttpVerb::Post, "RequestTokenTo3PIDJob", + : BaseJob(HttpVerb::Post, RequestTokenTo3PIDJobName, basePath % "/account/3pid/email/requestToken", false) { } diff --git a/lib/csapi/banning.cpp b/lib/csapi/banning.cpp index 4dbd8a7d..4065207b 100644 --- a/lib/csapi/banning.cpp +++ b/lib/csapi/banning.cpp @@ -12,22 +12,26 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto BanJobName = QStringLiteral("BanJob"); + BanJob::BanJob(const QString& roomId, const QString& userId, const QString& reason) - : BaseJob(HttpVerb::Post, "BanJob", + : BaseJob(HttpVerb::Post, BanJobName, basePath % "/rooms/" % roomId % "/ban") { QJsonObject _data; - addParam<>(_data, "user_id", userId); - addParam<IfNotEmpty>(_data, "reason", reason); + addParam<>(_data, QStringLiteral("user_id"), userId); + addParam<IfNotEmpty>(_data, QStringLiteral("reason"), reason); setRequestData(_data); } +static const auto UnbanJobName = QStringLiteral("UnbanJob"); + UnbanJob::UnbanJob(const QString& roomId, const QString& userId) - : BaseJob(HttpVerb::Post, "UnbanJob", + : BaseJob(HttpVerb::Post, UnbanJobName, basePath % "/rooms/" % roomId % "/unban") { QJsonObject _data; - addParam<>(_data, "user_id", userId); + addParam<>(_data, QStringLiteral("user_id"), userId); setRequestData(_data); } diff --git a/lib/csapi/content-repo.cpp b/lib/csapi/content-repo.cpp index 4ce80d08..9ac226ba 100644 --- a/lib/csapi/content-repo.cpp +++ b/lib/csapi/content-repo.cpp @@ -22,12 +22,14 @@ class UploadContentJob::Private BaseJob::Query queryToUploadContent(const QString& filename) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "filename", filename); + addParam<IfNotEmpty>(_q, QStringLiteral("filename"), filename); return _q; } +static const auto UploadContentJobName = QStringLiteral("UploadContentJob"); + UploadContentJob::UploadContentJob(QIODevice* content, const QString& filename, const QString& contentType) - : BaseJob(HttpVerb::Post, "UploadContentJob", + : BaseJob(HttpVerb::Post, UploadContentJobName, basePath % "/upload", queryToUploadContent(filename)) , d(new Private) @@ -47,10 +49,10 @@ const QString& UploadContentJob::contentUri() const BaseJob::Status UploadContentJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("content_uri")) + if (!json.contains("content_uri"_ls)) return { JsonParseError, "The key 'content_uri' not found in the response" }; - d->contentUri = fromJson<QString>(json.value("content_uri")); + d->contentUri = fromJson<QString>(json.value("content_uri"_ls)); return Success; } @@ -65,7 +67,7 @@ class GetContentJob::Private BaseJob::Query queryToGetContent(bool allowRemote) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote); return _q; } @@ -76,8 +78,10 @@ QUrl GetContentJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, cons queryToGetContent(allowRemote)); } +static const auto GetContentJobName = QStringLiteral("GetContentJob"); + GetContentJob::GetContentJob(const QString& serverName, const QString& mediaId, bool allowRemote) - : BaseJob(HttpVerb::Get, "GetContentJob", + : BaseJob(HttpVerb::Get, GetContentJobName, basePath % "/download/" % serverName % "/" % mediaId, queryToGetContent(allowRemote), {}, false) @@ -122,7 +126,7 @@ class GetContentOverrideNameJob::Private BaseJob::Query queryToGetContentOverrideName(bool allowRemote) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote); return _q; } @@ -133,8 +137,10 @@ QUrl GetContentOverrideNameJob::makeRequestUrl(QUrl baseUrl, const QString& serv queryToGetContentOverrideName(allowRemote)); } +static const auto GetContentOverrideNameJobName = QStringLiteral("GetContentOverrideNameJob"); + GetContentOverrideNameJob::GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName, bool allowRemote) - : BaseJob(HttpVerb::Get, "GetContentOverrideNameJob", + : BaseJob(HttpVerb::Get, GetContentOverrideNameJobName, basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName, queryToGetContentOverrideName(allowRemote), {}, false) @@ -178,10 +184,10 @@ class GetContentThumbnailJob::Private BaseJob::Query queryToGetContentThumbnail(int width, int height, const QString& method, bool allowRemote) { BaseJob::Query _q; - addParam<>(_q, "width", width); - addParam<>(_q, "height", height); - addParam<IfNotEmpty>(_q, "method", method); - addParam<IfNotEmpty>(_q, "allow_remote", allowRemote); + addParam<>(_q, QStringLiteral("width"), width); + addParam<>(_q, QStringLiteral("height"), height); + addParam<IfNotEmpty>(_q, QStringLiteral("method"), method); + addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote); return _q; } @@ -192,8 +198,10 @@ QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverN queryToGetContentThumbnail(width, height, method, allowRemote)); } +static const auto GetContentThumbnailJobName = QStringLiteral("GetContentThumbnailJob"); + GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method, bool allowRemote) - : BaseJob(HttpVerb::Get, "GetContentThumbnailJob", + : BaseJob(HttpVerb::Get, GetContentThumbnailJobName, basePath % "/thumbnail/" % serverName % "/" % mediaId, queryToGetContentThumbnail(width, height, method, allowRemote), {}, false) @@ -231,8 +239,8 @@ class GetUrlPreviewJob::Private BaseJob::Query queryToGetUrlPreview(const QString& url, Omittable<qint64> ts) { BaseJob::Query _q; - addParam<>(_q, "url", url); - addParam<IfNotEmpty>(_q, "ts", ts); + addParam<>(_q, QStringLiteral("url"), url); + addParam<IfNotEmpty>(_q, QStringLiteral("ts"), ts); return _q; } @@ -243,8 +251,10 @@ QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, Omittabl queryToGetUrlPreview(url, ts)); } +static const auto GetUrlPreviewJobName = QStringLiteral("GetUrlPreviewJob"); + GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, Omittable<qint64> ts) - : BaseJob(HttpVerb::Get, "GetUrlPreviewJob", + : BaseJob(HttpVerb::Get, GetUrlPreviewJobName, basePath % "/preview_url", queryToGetUrlPreview(url, ts)) , d(new Private) @@ -266,8 +276,8 @@ const QString& GetUrlPreviewJob::ogImage() const BaseJob::Status GetUrlPreviewJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->matrixImageSize = fromJson<qint64>(json.value("matrix:image:size")); - d->ogImage = fromJson<QString>(json.value("og:image")); + d->matrixImageSize = fromJson<qint64>(json.value("matrix:image:size"_ls)); + d->ogImage = fromJson<QString>(json.value("og:image"_ls)); return Success; } diff --git a/lib/csapi/create_room.cpp b/lib/csapi/create_room.cpp index 910210bc..5600e18a 100644 --- a/lib/csapi/create_room.cpp +++ b/lib/csapi/create_room.cpp @@ -19,18 +19,18 @@ namespace QMatrixClient QJsonObject toJson(const CreateRoomJob::Invite3pid& pod) { QJsonObject _json; - addParam<>(_json, "id_server", pod.idServer); - addParam<>(_json, "medium", pod.medium); - addParam<>(_json, "address", pod.address); + addParam<>(_json, QStringLiteral("id_server"), pod.idServer); + addParam<>(_json, QStringLiteral("medium"), pod.medium); + addParam<>(_json, QStringLiteral("address"), pod.address); return _json; } QJsonObject toJson(const CreateRoomJob::StateEvent& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "type", pod.type); - addParam<IfNotEmpty>(_json, "state_key", pod.stateKey); - addParam<IfNotEmpty>(_json, "content", pod.content); + addParam<IfNotEmpty>(_json, QStringLiteral("type"), pod.type); + addParam<IfNotEmpty>(_json, QStringLiteral("state_key"), pod.stateKey); + addParam<IfNotEmpty>(_json, QStringLiteral("content"), pod.content); return _json; } } // namespace QMatrixClient @@ -41,23 +41,25 @@ class CreateRoomJob::Private QString roomId; }; +static const auto CreateRoomJobName = QStringLiteral("CreateRoomJob"); + CreateRoomJob::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) - : BaseJob(HttpVerb::Post, "CreateRoomJob", + : BaseJob(HttpVerb::Post, CreateRoomJobName, basePath % "/createRoom") , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "visibility", visibility); - addParam<IfNotEmpty>(_data, "room_alias_name", roomAliasName); - addParam<IfNotEmpty>(_data, "name", name); - addParam<IfNotEmpty>(_data, "topic", topic); - addParam<IfNotEmpty>(_data, "invite", invite); - addParam<IfNotEmpty>(_data, "invite_3pid", invite3pid); - addParam<IfNotEmpty>(_data, "creation_content", creationContent); - addParam<IfNotEmpty>(_data, "initial_state", initialState); - addParam<IfNotEmpty>(_data, "preset", preset); - addParam<IfNotEmpty>(_data, "is_direct", isDirect); - addParam<IfNotEmpty>(_data, "guest_can_join", guestCanJoin); + addParam<IfNotEmpty>(_data, QStringLiteral("visibility"), visibility); + addParam<IfNotEmpty>(_data, QStringLiteral("room_alias_name"), roomAliasName); + addParam<IfNotEmpty>(_data, QStringLiteral("name"), name); + addParam<IfNotEmpty>(_data, QStringLiteral("topic"), topic); + addParam<IfNotEmpty>(_data, QStringLiteral("invite"), invite); + addParam<IfNotEmpty>(_data, QStringLiteral("invite_3pid"), invite3pid); + addParam<IfNotEmpty>(_data, QStringLiteral("creation_content"), creationContent); + addParam<IfNotEmpty>(_data, QStringLiteral("initial_state"), initialState); + addParam<IfNotEmpty>(_data, QStringLiteral("preset"), preset); + addParam<IfNotEmpty>(_data, QStringLiteral("is_direct"), isDirect); + addParam<IfNotEmpty>(_data, QStringLiteral("guest_can_join"), guestCanJoin); setRequestData(_data); } @@ -71,7 +73,7 @@ const QString& CreateRoomJob::roomId() const BaseJob::Status CreateRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id")); + d->roomId = fromJson<QString>(json.value("room_id"_ls)); return Success; } diff --git a/lib/csapi/definitions/client_device.cpp b/lib/csapi/definitions/client_device.cpp index 7c3d7ea6..bd7acd02 100644 --- a/lib/csapi/definitions/client_device.cpp +++ b/lib/csapi/definitions/client_device.cpp @@ -9,10 +9,10 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const Device& pod) { QJsonObject _json; - addParam<>(_json, "device_id", pod.deviceId); - addParam<IfNotEmpty>(_json, "display_name", pod.displayName); - addParam<IfNotEmpty>(_json, "last_seen_ip", pod.lastSeenIp); - addParam<IfNotEmpty>(_json, "last_seen_ts", pod.lastSeenTs); + 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; } @@ -21,13 +21,13 @@ Device FromJson<Device>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); Device result; result.deviceId = - fromJson<QString>(_json.value("device_id")); + fromJson<QString>(_json.value("device_id"_ls)); result.displayName = - fromJson<QString>(_json.value("display_name")); + fromJson<QString>(_json.value("display_name"_ls)); result.lastSeenIp = - fromJson<QString>(_json.value("last_seen_ip")); + fromJson<QString>(_json.value("last_seen_ip"_ls)); result.lastSeenTs = - fromJson<qint64>(_json.value("last_seen_ts")); + fromJson<qint64>(_json.value("last_seen_ts"_ls)); return result; } diff --git a/lib/csapi/definitions/device_keys.cpp b/lib/csapi/definitions/device_keys.cpp index 43cd5d2e..d17f4c12 100644 --- a/lib/csapi/definitions/device_keys.cpp +++ b/lib/csapi/definitions/device_keys.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const DeviceKeys& pod) { QJsonObject _json; - addParam<>(_json, "user_id", pod.userId); - addParam<>(_json, "device_id", pod.deviceId); - addParam<>(_json, "algorithms", pod.algorithms); - addParam<>(_json, "keys", pod.keys); - addParam<>(_json, "signatures", pod.signatures); + 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; } @@ -22,15 +22,15 @@ DeviceKeys FromJson<DeviceKeys>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); DeviceKeys result; result.userId = - fromJson<QString>(_json.value("user_id")); + fromJson<QString>(_json.value("user_id"_ls)); result.deviceId = - fromJson<QString>(_json.value("device_id")); + fromJson<QString>(_json.value("device_id"_ls)); result.algorithms = - fromJson<QStringList>(_json.value("algorithms")); + fromJson<QStringList>(_json.value("algorithms"_ls)); result.keys = - fromJson<QHash<QString, QString>>(_json.value("keys")); + fromJson<QHash<QString, QString>>(_json.value("keys"_ls)); result.signatures = - fromJson<QHash<QString, QHash<QString, QString>>>(_json.value("signatures")); + fromJson<QHash<QString, QHash<QString, QString>>>(_json.value("signatures"_ls)); return result; } diff --git a/lib/csapi/definitions/event_filter.cpp b/lib/csapi/definitions/event_filter.cpp index 21ee2b81..336de0dd 100644 --- a/lib/csapi/definitions/event_filter.cpp +++ b/lib/csapi/definitions/event_filter.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const Filter& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "limit", pod.limit); - addParam<IfNotEmpty>(_json, "not_senders", pod.notSenders); - addParam<IfNotEmpty>(_json, "not_types", pod.notTypes); - addParam<IfNotEmpty>(_json, "senders", pod.senders); - addParam<IfNotEmpty>(_json, "types", pod.types); + 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; } @@ -22,15 +22,15 @@ Filter FromJson<Filter>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); Filter result; result.limit = - fromJson<int>(_json.value("limit")); + fromJson<int>(_json.value("limit"_ls)); result.notSenders = - fromJson<QStringList>(_json.value("not_senders")); + fromJson<QStringList>(_json.value("not_senders"_ls)); result.notTypes = - fromJson<QStringList>(_json.value("not_types")); + fromJson<QStringList>(_json.value("not_types"_ls)); result.senders = - fromJson<QStringList>(_json.value("senders")); + fromJson<QStringList>(_json.value("senders"_ls)); result.types = - fromJson<QStringList>(_json.value("types")); + fromJson<QStringList>(_json.value("types"_ls)); return result; } diff --git a/lib/csapi/definitions/push_condition.cpp b/lib/csapi/definitions/push_condition.cpp index b8595ec6..19351ae1 100644 --- a/lib/csapi/definitions/push_condition.cpp +++ b/lib/csapi/definitions/push_condition.cpp @@ -9,10 +9,10 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushCondition& pod) { QJsonObject _json; - addParam<>(_json, "kind", pod.kind); - addParam<IfNotEmpty>(_json, "key", pod.key); - addParam<IfNotEmpty>(_json, "pattern", pod.pattern); - addParam<IfNotEmpty>(_json, "is", pod.is); + 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; } @@ -21,13 +21,13 @@ PushCondition FromJson<PushCondition>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); PushCondition result; result.kind = - fromJson<QString>(_json.value("kind")); + fromJson<QString>(_json.value("kind"_ls)); result.key = - fromJson<QString>(_json.value("key")); + fromJson<QString>(_json.value("key"_ls)); result.pattern = - fromJson<QString>(_json.value("pattern")); + fromJson<QString>(_json.value("pattern"_ls)); result.is = - fromJson<QString>(_json.value("is")); + fromJson<QString>(_json.value("is"_ls)); return result; } diff --git a/lib/csapi/definitions/push_rule.cpp b/lib/csapi/definitions/push_rule.cpp index 98f5d788..833135ec 100644 --- a/lib/csapi/definitions/push_rule.cpp +++ b/lib/csapi/definitions/push_rule.cpp @@ -9,12 +9,12 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRule& pod) { QJsonObject _json; - addParam<>(_json, "actions", pod.actions); - addParam<>(_json, "default", pod.isDefault); - addParam<>(_json, "enabled", pod.enabled); - addParam<>(_json, "rule_id", pod.ruleId); - addParam<IfNotEmpty>(_json, "conditions", pod.conditions); - addParam<IfNotEmpty>(_json, "pattern", pod.pattern); + 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; } @@ -23,17 +23,17 @@ PushRule FromJson<PushRule>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); PushRule result; result.actions = - fromJson<QVector<QVariant>>(_json.value("actions")); + fromJson<QVector<QVariant>>(_json.value("actions"_ls)); result.isDefault = - fromJson<bool>(_json.value("default")); + fromJson<bool>(_json.value("default"_ls)); result.enabled = - fromJson<bool>(_json.value("enabled")); + fromJson<bool>(_json.value("enabled"_ls)); result.ruleId = - fromJson<QString>(_json.value("rule_id")); + fromJson<QString>(_json.value("rule_id"_ls)); result.conditions = - fromJson<QVector<PushCondition>>(_json.value("conditions")); + fromJson<QVector<PushCondition>>(_json.value("conditions"_ls)); result.pattern = - fromJson<QString>(_json.value("pattern")); + fromJson<QString>(_json.value("pattern"_ls)); return result; } diff --git a/lib/csapi/definitions/push_ruleset.cpp b/lib/csapi/definitions/push_ruleset.cpp index ca2bbc0d..c424f686 100644 --- a/lib/csapi/definitions/push_ruleset.cpp +++ b/lib/csapi/definitions/push_ruleset.cpp @@ -9,11 +9,11 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const PushRuleset& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "content", pod.content); - addParam<IfNotEmpty>(_json, "override", pod.override); - addParam<IfNotEmpty>(_json, "room", pod.room); - addParam<IfNotEmpty>(_json, "sender", pod.sender); - addParam<IfNotEmpty>(_json, "underride", pod.underride); + 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; } @@ -22,15 +22,15 @@ PushRuleset FromJson<PushRuleset>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); PushRuleset result; result.content = - fromJson<QVector<PushRule>>(_json.value("content")); + fromJson<QVector<PushRule>>(_json.value("content"_ls)); result.override = - fromJson<QVector<PushRule>>(_json.value("override")); + fromJson<QVector<PushRule>>(_json.value("override"_ls)); result.room = - fromJson<QVector<PushRule>>(_json.value("room")); + fromJson<QVector<PushRule>>(_json.value("room"_ls)); result.sender = - fromJson<QVector<PushRule>>(_json.value("sender")); + fromJson<QVector<PushRule>>(_json.value("sender"_ls)); result.underride = - fromJson<QVector<PushRule>>(_json.value("underride")); + fromJson<QVector<PushRule>>(_json.value("underride"_ls)); return result; } diff --git a/lib/csapi/definitions/room_event_filter.cpp b/lib/csapi/definitions/room_event_filter.cpp index 1702be22..18ce07ec 100644 --- a/lib/csapi/definitions/room_event_filter.cpp +++ b/lib/csapi/definitions/room_event_filter.cpp @@ -9,9 +9,9 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomEventFilter& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "not_rooms", pod.notRooms); - addParam<IfNotEmpty>(_json, "rooms", pod.rooms); - addParam<IfNotEmpty>(_json, "contains_url", pod.containsUrl); + 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; } @@ -20,11 +20,11 @@ RoomEventFilter FromJson<RoomEventFilter>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); RoomEventFilter result; result.notRooms = - fromJson<QStringList>(_json.value("not_rooms")); + fromJson<QStringList>(_json.value("not_rooms"_ls)); result.rooms = - fromJson<QStringList>(_json.value("rooms")); + fromJson<QStringList>(_json.value("rooms"_ls)); result.containsUrl = - fromJson<bool>(_json.value("contains_url")); + fromJson<bool>(_json.value("contains_url"_ls)); return result; } diff --git a/lib/csapi/definitions/sync_filter.cpp b/lib/csapi/definitions/sync_filter.cpp index 2b5cf8be..b42f15f5 100644 --- a/lib/csapi/definitions/sync_filter.cpp +++ b/lib/csapi/definitions/sync_filter.cpp @@ -9,13 +9,13 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const RoomFilter& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "not_rooms", pod.notRooms); - addParam<IfNotEmpty>(_json, "rooms", pod.rooms); - addParam<IfNotEmpty>(_json, "ephemeral", pod.ephemeral); - addParam<IfNotEmpty>(_json, "include_leave", pod.includeLeave); - addParam<IfNotEmpty>(_json, "state", pod.state); - addParam<IfNotEmpty>(_json, "timeline", pod.timeline); - addParam<IfNotEmpty>(_json, "account_data", pod.accountData); + 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; } @@ -24,19 +24,19 @@ RoomFilter FromJson<RoomFilter>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); RoomFilter result; result.notRooms = - fromJson<QStringList>(_json.value("not_rooms")); + fromJson<QStringList>(_json.value("not_rooms"_ls)); result.rooms = - fromJson<QStringList>(_json.value("rooms")); + fromJson<QStringList>(_json.value("rooms"_ls)); result.ephemeral = - fromJson<RoomEventFilter>(_json.value("ephemeral")); + fromJson<RoomEventFilter>(_json.value("ephemeral"_ls)); result.includeLeave = - fromJson<bool>(_json.value("include_leave")); + fromJson<bool>(_json.value("include_leave"_ls)); result.state = - fromJson<RoomEventFilter>(_json.value("state")); + fromJson<RoomEventFilter>(_json.value("state"_ls)); result.timeline = - fromJson<RoomEventFilter>(_json.value("timeline")); + fromJson<RoomEventFilter>(_json.value("timeline"_ls)); result.accountData = - fromJson<RoomEventFilter>(_json.value("account_data")); + fromJson<RoomEventFilter>(_json.value("account_data"_ls)); return result; } @@ -44,11 +44,11 @@ RoomFilter FromJson<RoomFilter>::operator()(const QJsonValue& jv) QJsonObject QMatrixClient::toJson(const SyncFilter& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "event_fields", pod.eventFields); - addParam<IfNotEmpty>(_json, "event_format", pod.eventFormat); - addParam<IfNotEmpty>(_json, "presence", pod.presence); - addParam<IfNotEmpty>(_json, "account_data", pod.accountData); - addParam<IfNotEmpty>(_json, "room", pod.room); + 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; } @@ -57,15 +57,15 @@ SyncFilter FromJson<SyncFilter>::operator()(const QJsonValue& jv) const auto& _json = jv.toObject(); SyncFilter result; result.eventFields = - fromJson<QStringList>(_json.value("event_fields")); + fromJson<QStringList>(_json.value("event_fields"_ls)); result.eventFormat = - fromJson<QString>(_json.value("event_format")); + fromJson<QString>(_json.value("event_format"_ls)); result.presence = - fromJson<Filter>(_json.value("presence")); + fromJson<Filter>(_json.value("presence"_ls)); result.accountData = - fromJson<Filter>(_json.value("account_data")); + fromJson<Filter>(_json.value("account_data"_ls)); result.room = - fromJson<RoomFilter>(_json.value("room")); + fromJson<RoomFilter>(_json.value("room"_ls)); return result; } diff --git a/lib/csapi/device_management.cpp b/lib/csapi/device_management.cpp index a4b2daae..bbc7e674 100644 --- a/lib/csapi/device_management.cpp +++ b/lib/csapi/device_management.cpp @@ -24,8 +24,10 @@ QUrl GetDevicesJob::makeRequestUrl(QUrl baseUrl) basePath % "/devices"); } +static const auto GetDevicesJobName = QStringLiteral("GetDevicesJob"); + GetDevicesJob::GetDevicesJob() - : BaseJob(HttpVerb::Get, "GetDevicesJob", + : BaseJob(HttpVerb::Get, GetDevicesJobName, basePath % "/devices") , d(new Private) { @@ -41,7 +43,7 @@ const QVector<Device>& GetDevicesJob::devices() const BaseJob::Status GetDevicesJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->devices = fromJson<QVector<Device>>(json.value("devices")); + d->devices = fromJson<QVector<Device>>(json.value("devices"_ls)); return Success; } @@ -57,8 +59,10 @@ QUrl GetDeviceJob::makeRequestUrl(QUrl baseUrl, const QString& deviceId) basePath % "/devices/" % deviceId); } +static const auto GetDeviceJobName = QStringLiteral("GetDeviceJob"); + GetDeviceJob::GetDeviceJob(const QString& deviceId) - : BaseJob(HttpVerb::Get, "GetDeviceJob", + : BaseJob(HttpVerb::Get, GetDeviceJobName, basePath % "/devices/" % deviceId) , d(new Private) { @@ -74,38 +78,44 @@ const Device& GetDeviceJob::data() const BaseJob::Status GetDeviceJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<Device>(json.value("data")); + d->data = fromJson<Device>(json.value("data"_ls)); return Success; } +static const auto UpdateDeviceJobName = QStringLiteral("UpdateDeviceJob"); + UpdateDeviceJob::UpdateDeviceJob(const QString& deviceId, const QString& displayName) - : BaseJob(HttpVerb::Put, "UpdateDeviceJob", + : BaseJob(HttpVerb::Put, UpdateDeviceJobName, basePath % "/devices/" % deviceId) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "display_name", displayName); + addParam<IfNotEmpty>(_data, QStringLiteral("display_name"), displayName); setRequestData(_data); } +static const auto DeleteDeviceJobName = QStringLiteral("DeleteDeviceJob"); + DeleteDeviceJob::DeleteDeviceJob(const QString& deviceId, const QJsonObject& auth) - : BaseJob(HttpVerb::Delete, "DeleteDeviceJob", + : BaseJob(HttpVerb::Delete, DeleteDeviceJobName, basePath % "/devices/" % deviceId) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } +static const auto DeleteDevicesJobName = QStringLiteral("DeleteDevicesJob"); + DeleteDevicesJob::DeleteDevicesJob(const QStringList& devices, const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "DeleteDevicesJob", + : BaseJob(HttpVerb::Post, DeleteDevicesJobName, basePath % "/delete_devices") { QJsonObject _data; - addParam<>(_data, "devices", devices); - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<>(_data, QStringLiteral("devices"), devices); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } diff --git a/lib/csapi/directory.cpp b/lib/csapi/directory.cpp index 7e8b87b8..fd3b8839 100644 --- a/lib/csapi/directory.cpp +++ b/lib/csapi/directory.cpp @@ -12,12 +12,14 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0/directory"); +static const auto SetRoomAliasJobName = QStringLiteral("SetRoomAliasJob"); + SetRoomAliasJob::SetRoomAliasJob(const QString& roomAlias, const QString& roomId) - : BaseJob(HttpVerb::Put, "SetRoomAliasJob", + : BaseJob(HttpVerb::Put, SetRoomAliasJobName, basePath % "/room/" % roomAlias) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "room_id", roomId); + addParam<IfNotEmpty>(_data, QStringLiteral("room_id"), roomId); setRequestData(_data); } @@ -34,8 +36,10 @@ QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) basePath % "/room/" % roomAlias); } +static const auto GetRoomIdByAliasJobName = QStringLiteral("GetRoomIdByAliasJob"); + GetRoomIdByAliasJob::GetRoomIdByAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Get, "GetRoomIdByAliasJob", + : BaseJob(HttpVerb::Get, GetRoomIdByAliasJobName, basePath % "/room/" % roomAlias, false) , d(new Private) { @@ -56,8 +60,8 @@ const QStringList& GetRoomIdByAliasJob::servers() const BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id")); - d->servers = fromJson<QStringList>(json.value("servers")); + d->roomId = fromJson<QString>(json.value("room_id"_ls)); + d->servers = fromJson<QStringList>(json.value("servers"_ls)); return Success; } @@ -67,8 +71,10 @@ QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) basePath % "/room/" % roomAlias); } +static const auto DeleteRoomAliasJobName = QStringLiteral("DeleteRoomAliasJob"); + DeleteRoomAliasJob::DeleteRoomAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Delete, "DeleteRoomAliasJob", + : BaseJob(HttpVerb::Delete, DeleteRoomAliasJobName, basePath % "/room/" % roomAlias) { } diff --git a/lib/csapi/event_context.cpp b/lib/csapi/event_context.cpp index 9e4c6963..806c1613 100644 --- a/lib/csapi/event_context.cpp +++ b/lib/csapi/event_context.cpp @@ -26,7 +26,7 @@ class GetEventContextJob::Private BaseJob::Query queryToGetEventContext(Omittable<int> limit) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "limit", limit); + addParam<IfNotEmpty>(_q, QStringLiteral("limit"), limit); return _q; } @@ -37,8 +37,10 @@ QUrl GetEventContextJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, con queryToGetEventContext(limit)); } +static const auto GetEventContextJobName = QStringLiteral("GetEventContextJob"); + GetEventContextJob::GetEventContextJob(const QString& roomId, const QString& eventId, Omittable<int> limit) - : BaseJob(HttpVerb::Get, "GetEventContextJob", + : BaseJob(HttpVerb::Get, GetEventContextJobName, basePath % "/rooms/" % roomId % "/context/" % eventId, queryToGetEventContext(limit)) , d(new Private) @@ -80,12 +82,12 @@ StateEvents&& GetEventContextJob::state() BaseJob::Status GetEventContextJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->begin = fromJson<QString>(json.value("start")); - d->end = fromJson<QString>(json.value("end")); - d->eventsBefore = fromJson<RoomEvents>(json.value("events_before")); - d->event = fromJson<RoomEventPtr>(json.value("event")); - d->eventsAfter = fromJson<RoomEvents>(json.value("events_after")); - d->state = fromJson<StateEvents>(json.value("state")); + d->begin = fromJson<QString>(json.value("start"_ls)); + d->end = fromJson<QString>(json.value("end"_ls)); + d->eventsBefore = fromJson<RoomEvents>(json.value("events_before"_ls)); + d->event = fromJson<RoomEventPtr>(json.value("event"_ls)); + d->eventsAfter = fromJson<RoomEvents>(json.value("events_after"_ls)); + d->state = fromJson<StateEvents>(json.value("state"_ls)); return Success; } diff --git a/lib/csapi/event_context.h b/lib/csapi/event_context.h index 0470ba36..22c9cbc3 100644 --- a/lib/csapi/event_context.h +++ b/lib/csapi/event_context.h @@ -6,7 +6,7 @@ #include "jobs/basejob.h" -#include "events/event.h" +#include "events/eventloader.h" #include "converters.h" namespace QMatrixClient diff --git a/lib/csapi/filter.cpp b/lib/csapi/filter.cpp index a1546923..51056cc3 100644 --- a/lib/csapi/filter.cpp +++ b/lib/csapi/filter.cpp @@ -18,8 +18,10 @@ class DefineFilterJob::Private QString filterId; }; +static const auto DefineFilterJobName = QStringLiteral("DefineFilterJob"); + DefineFilterJob::DefineFilterJob(const QString& userId, const SyncFilter& filter) - : BaseJob(HttpVerb::Post, "DefineFilterJob", + : BaseJob(HttpVerb::Post, DefineFilterJobName, basePath % "/user/" % userId % "/filter") , d(new Private) { @@ -36,7 +38,7 @@ const QString& DefineFilterJob::filterId() const BaseJob::Status DefineFilterJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->filterId = fromJson<QString>(json.value("filter_id")); + d->filterId = fromJson<QString>(json.value("filter_id"_ls)); return Success; } @@ -52,8 +54,10 @@ QUrl GetFilterJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QSt basePath % "/user/" % userId % "/filter/" % filterId); } +static const auto GetFilterJobName = QStringLiteral("GetFilterJob"); + GetFilterJob::GetFilterJob(const QString& userId, const QString& filterId) - : BaseJob(HttpVerb::Get, "GetFilterJob", + : BaseJob(HttpVerb::Get, GetFilterJobName, basePath % "/user/" % userId % "/filter/" % filterId) , d(new Private) { @@ -69,10 +73,10 @@ const SyncFilter& GetFilterJob::data() const BaseJob::Status GetFilterJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<SyncFilter>(json.value("data")); + d->data = fromJson<SyncFilter>(json.value("data"_ls)); return Success; } diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml index 3d1b7e88..09344be5 100644 --- a/lib/csapi/gtad.yaml +++ b/lib/csapi/gtad.yaml @@ -62,11 +62,11 @@ analyzer: - +set: { moveOnly: } +on: - /state_event.yaml$/: - { type: StateEventPtr, imports: '"events/event.h"' } + { type: StateEventPtr, imports: '"events/eventloader.h"' } - /room_event.yaml$/: - { type: RoomEventPtr, imports: '"events/event.h"' } + { type: RoomEventPtr, imports: '"events/eventloader.h"' } - /event.yaml$/: - { type: EventPtr, imports: '"events/event.h"' } + { type: EventPtr, imports: '"events/eventloader.h"' } - /auth_data.yaml$/: *QJsonObject # GTAD 0.6 cannot cope with this one - /m\.room\.member$/: pass # This $ref is only used in an array, see below - //: *UseOmittable # Also apply "avoidCopy" to all other ref'ed types @@ -79,7 +79,7 @@ analyzer: +on: - /^Notification|Result$/: type: "std::vector<{{1}}>" - imports: '"events/event.h"' + imports: '"events/eventloader.h"' - /m\.room\.member$/: type: "EventsArray<RoomMemberEvent>" imports: '"events/roommemberevent.h"' diff --git a/lib/csapi/inviting.cpp b/lib/csapi/inviting.cpp index 94e0910b..7dc33b18 100644 --- a/lib/csapi/inviting.cpp +++ b/lib/csapi/inviting.cpp @@ -12,12 +12,14 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto InviteUserJobName = QStringLiteral("InviteUserJob"); + InviteUserJob::InviteUserJob(const QString& roomId, const QString& userId) - : BaseJob(HttpVerb::Post, "InviteUserJob", + : BaseJob(HttpVerb::Post, InviteUserJobName, basePath % "/rooms/" % roomId % "/invite") { QJsonObject _data; - addParam<>(_data, "user_id", userId); + addParam<>(_data, QStringLiteral("user_id"), userId); setRequestData(_data); } diff --git a/lib/csapi/joining.cpp b/lib/csapi/joining.cpp index f2d6fbf7..0a4618af 100644 --- a/lib/csapi/joining.cpp +++ b/lib/csapi/joining.cpp @@ -19,10 +19,10 @@ namespace QMatrixClient QJsonObject toJson(const JoinRoomByIdJob::ThirdPartySigned& pod) { QJsonObject _json; - addParam<>(_json, "sender", pod.sender); - addParam<>(_json, "mxid", pod.mxid); - addParam<>(_json, "token", pod.token); - addParam<>(_json, "signatures", pod.signatures); + addParam<>(_json, QStringLiteral("sender"), pod.sender); + addParam<>(_json, QStringLiteral("mxid"), pod.mxid); + addParam<>(_json, QStringLiteral("token"), pod.token); + addParam<>(_json, QStringLiteral("signatures"), pod.signatures); return _json; } } // namespace QMatrixClient @@ -33,13 +33,15 @@ class JoinRoomByIdJob::Private QString roomId; }; +static const auto JoinRoomByIdJobName = QStringLiteral("JoinRoomByIdJob"); + JoinRoomByIdJob::JoinRoomByIdJob(const QString& roomId, const Omittable<ThirdPartySigned>& thirdPartySigned) - : BaseJob(HttpVerb::Post, "JoinRoomByIdJob", + : BaseJob(HttpVerb::Post, JoinRoomByIdJobName, basePath % "/rooms/" % roomId % "/join") , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); + addParam<IfNotEmpty>(_data, QStringLiteral("third_party_signed"), thirdPartySigned); setRequestData(_data); } @@ -53,10 +55,10 @@ const QString& JoinRoomByIdJob::roomId() const BaseJob::Status JoinRoomByIdJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("room_id")) + if (!json.contains("room_id"_ls)) return { JsonParseError, "The key 'room_id' not found in the response" }; - d->roomId = fromJson<QString>(json.value("room_id")); + d->roomId = fromJson<QString>(json.value("room_id"_ls)); return Success; } @@ -67,17 +69,17 @@ namespace QMatrixClient QJsonObject toJson(const JoinRoomJob::Signed& pod) { QJsonObject _json; - addParam<>(_json, "sender", pod.sender); - addParam<>(_json, "mxid", pod.mxid); - addParam<>(_json, "token", pod.token); - addParam<>(_json, "signatures", pod.signatures); + addParam<>(_json, QStringLiteral("sender"), pod.sender); + addParam<>(_json, QStringLiteral("mxid"), pod.mxid); + addParam<>(_json, QStringLiteral("token"), pod.token); + addParam<>(_json, QStringLiteral("signatures"), pod.signatures); return _json; } QJsonObject toJson(const JoinRoomJob::ThirdPartySigned& pod) { QJsonObject _json; - addParam<>(_json, "signed", pod.signedData); + addParam<>(_json, QStringLiteral("signed"), pod.signedData); return _json; } } // namespace QMatrixClient @@ -88,13 +90,15 @@ class JoinRoomJob::Private QString roomId; }; +static const auto JoinRoomJobName = QStringLiteral("JoinRoomJob"); + JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const Omittable<ThirdPartySigned>& thirdPartySigned) - : BaseJob(HttpVerb::Post, "JoinRoomJob", + : BaseJob(HttpVerb::Post, JoinRoomJobName, basePath % "/join/" % roomIdOrAlias) , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "third_party_signed", thirdPartySigned); + addParam<IfNotEmpty>(_data, QStringLiteral("third_party_signed"), thirdPartySigned); setRequestData(_data); } @@ -108,10 +112,10 @@ const QString& JoinRoomJob::roomId() const BaseJob::Status JoinRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("room_id")) + if (!json.contains("room_id"_ls)) return { JsonParseError, "The key 'room_id' not found in the response" }; - d->roomId = fromJson<QString>(json.value("room_id")); + d->roomId = fromJson<QString>(json.value("room_id"_ls)); return Success; } diff --git a/lib/csapi/keys.cpp b/lib/csapi/keys.cpp index 4a76b7e2..fac811d0 100644 --- a/lib/csapi/keys.cpp +++ b/lib/csapi/keys.cpp @@ -18,14 +18,16 @@ class UploadKeysJob::Private QHash<QString, int> oneTimeKeyCounts; }; +static const auto UploadKeysJobName = QStringLiteral("UploadKeysJob"); + UploadKeysJob::UploadKeysJob(const Omittable<DeviceKeys>& deviceKeys, const QHash<QString, QVariant>& oneTimeKeys) - : BaseJob(HttpVerb::Post, "UploadKeysJob", + : BaseJob(HttpVerb::Post, UploadKeysJobName, basePath % "/keys/upload") , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "device_keys", deviceKeys); - addParam<IfNotEmpty>(_data, "one_time_keys", oneTimeKeys); + addParam<IfNotEmpty>(_data, QStringLiteral("device_keys"), deviceKeys); + addParam<IfNotEmpty>(_data, QStringLiteral("one_time_keys"), oneTimeKeys); setRequestData(_data); } @@ -39,10 +41,10 @@ const QHash<QString, int>& UploadKeysJob::oneTimeKeyCounts() const BaseJob::Status UploadKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("one_time_key_counts")) + if (!json.contains("one_time_key_counts"_ls)) return { JsonParseError, "The key 'one_time_key_counts' not found in the response" }; - d->oneTimeKeyCounts = fromJson<QHash<QString, int>>(json.value("one_time_key_counts")); + d->oneTimeKeyCounts = fromJson<QHash<QString, int>>(json.value("one_time_key_counts"_ls)); return Success; } @@ -57,7 +59,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); QueryKeysJob::UnsignedDeviceInfo result; result.deviceDisplayName = - fromJson<QString>(_json.value("device_display_name")); + fromJson<QString>(_json.value("device_display_name"_ls)); return result; } @@ -70,7 +72,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); QueryKeysJob::DeviceInformation result; result.unsignedData = - fromJson<QueryKeysJob::UnsignedDeviceInfo>(_json.value("unsigned")); + fromJson<QueryKeysJob::UnsignedDeviceInfo>(_json.value("unsigned"_ls)); return result; } @@ -84,15 +86,17 @@ class QueryKeysJob::Private QHash<QString, QHash<QString, DeviceInformation>> deviceKeys; }; +static const auto QueryKeysJobName = QStringLiteral("QueryKeysJob"); + QueryKeysJob::QueryKeysJob(const QHash<QString, QStringList>& deviceKeys, Omittable<int> timeout, const QString& token) - : BaseJob(HttpVerb::Post, "QueryKeysJob", + : BaseJob(HttpVerb::Post, QueryKeysJobName, basePath % "/keys/query") , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "timeout", timeout); - addParam<>(_data, "device_keys", deviceKeys); - addParam<IfNotEmpty>(_data, "token", token); + addParam<IfNotEmpty>(_data, QStringLiteral("timeout"), timeout); + addParam<>(_data, QStringLiteral("device_keys"), deviceKeys); + addParam<IfNotEmpty>(_data, QStringLiteral("token"), token); setRequestData(_data); } @@ -111,8 +115,8 @@ const QHash<QString, QHash<QString, QueryKeysJob::DeviceInformation>>& QueryKeys BaseJob::Status QueryKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures")); - d->deviceKeys = fromJson<QHash<QString, QHash<QString, DeviceInformation>>>(json.value("device_keys")); + d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures"_ls)); + d->deviceKeys = fromJson<QHash<QString, QHash<QString, DeviceInformation>>>(json.value("device_keys"_ls)); return Success; } @@ -123,14 +127,16 @@ class ClaimKeysJob::Private QHash<QString, QHash<QString, QVariant>> oneTimeKeys; }; +static const auto ClaimKeysJobName = QStringLiteral("ClaimKeysJob"); + ClaimKeysJob::ClaimKeysJob(const QHash<QString, QHash<QString, QString>>& oneTimeKeys, Omittable<int> timeout) - : BaseJob(HttpVerb::Post, "ClaimKeysJob", + : BaseJob(HttpVerb::Post, ClaimKeysJobName, basePath % "/keys/claim") , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "timeout", timeout); - addParam<>(_data, "one_time_keys", oneTimeKeys); + addParam<IfNotEmpty>(_data, QStringLiteral("timeout"), timeout); + addParam<>(_data, QStringLiteral("one_time_keys"), oneTimeKeys); setRequestData(_data); } @@ -149,8 +155,8 @@ const QHash<QString, QHash<QString, QVariant>>& ClaimKeysJob::oneTimeKeys() cons BaseJob::Status ClaimKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures")); - d->oneTimeKeys = fromJson<QHash<QString, QHash<QString, QVariant>>>(json.value("one_time_keys")); + d->failures = fromJson<QHash<QString, QJsonObject>>(json.value("failures"_ls)); + d->oneTimeKeys = fromJson<QHash<QString, QHash<QString, QVariant>>>(json.value("one_time_keys"_ls)); return Success; } @@ -164,8 +170,8 @@ class GetKeysChangesJob::Private BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to) { BaseJob::Query _q; - addParam<>(_q, "from", from); - addParam<>(_q, "to", to); + addParam<>(_q, QStringLiteral("from"), from); + addParam<>(_q, QStringLiteral("to"), to); return _q; } @@ -176,8 +182,10 @@ QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from, const queryToGetKeysChanges(from, to)); } +static const auto GetKeysChangesJobName = QStringLiteral("GetKeysChangesJob"); + GetKeysChangesJob::GetKeysChangesJob(const QString& from, const QString& to) - : BaseJob(HttpVerb::Get, "GetKeysChangesJob", + : BaseJob(HttpVerb::Get, GetKeysChangesJobName, basePath % "/keys/changes", queryToGetKeysChanges(from, to)) , d(new Private) @@ -199,8 +207,8 @@ const QStringList& GetKeysChangesJob::left() const BaseJob::Status GetKeysChangesJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->changed = fromJson<QStringList>(json.value("changed")); - d->left = fromJson<QStringList>(json.value("left")); + d->changed = fromJson<QStringList>(json.value("changed"_ls)); + d->left = fromJson<QStringList>(json.value("left"_ls)); return Success; } diff --git a/lib/csapi/kicking.cpp b/lib/csapi/kicking.cpp index 73ef70ae..1d6d5543 100644 --- a/lib/csapi/kicking.cpp +++ b/lib/csapi/kicking.cpp @@ -12,13 +12,15 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto KickJobName = QStringLiteral("KickJob"); + KickJob::KickJob(const QString& roomId, const QString& userId, const QString& reason) - : BaseJob(HttpVerb::Post, "KickJob", + : BaseJob(HttpVerb::Post, KickJobName, basePath % "/rooms/" % roomId % "/kick") { QJsonObject _data; - addParam<>(_data, "user_id", userId); - addParam<IfNotEmpty>(_data, "reason", reason); + addParam<>(_data, QStringLiteral("user_id"), userId); + addParam<IfNotEmpty>(_data, QStringLiteral("reason"), reason); setRequestData(_data); } diff --git a/lib/csapi/leaving.cpp b/lib/csapi/leaving.cpp index afc4adbd..09e5f83b 100644 --- a/lib/csapi/leaving.cpp +++ b/lib/csapi/leaving.cpp @@ -18,8 +18,10 @@ QUrl LeaveRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) basePath % "/rooms/" % roomId % "/leave"); } +static const auto LeaveRoomJobName = QStringLiteral("LeaveRoomJob"); + LeaveRoomJob::LeaveRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Post, "LeaveRoomJob", + : BaseJob(HttpVerb::Post, LeaveRoomJobName, basePath % "/rooms/" % roomId % "/leave") { } @@ -30,8 +32,10 @@ QUrl ForgetRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) basePath % "/rooms/" % roomId % "/forget"); } +static const auto ForgetRoomJobName = QStringLiteral("ForgetRoomJob"); + ForgetRoomJob::ForgetRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Post, "ForgetRoomJob", + : BaseJob(HttpVerb::Post, ForgetRoomJobName, basePath % "/rooms/" % roomId % "/forget") { } diff --git a/lib/csapi/list_joined_rooms.cpp b/lib/csapi/list_joined_rooms.cpp index 82ec8849..a745dba1 100644 --- a/lib/csapi/list_joined_rooms.cpp +++ b/lib/csapi/list_joined_rooms.cpp @@ -24,8 +24,10 @@ QUrl GetJoinedRoomsJob::makeRequestUrl(QUrl baseUrl) basePath % "/joined_rooms"); } +static const auto GetJoinedRoomsJobName = QStringLiteral("GetJoinedRoomsJob"); + GetJoinedRoomsJob::GetJoinedRoomsJob() - : BaseJob(HttpVerb::Get, "GetJoinedRoomsJob", + : BaseJob(HttpVerb::Get, GetJoinedRoomsJobName, basePath % "/joined_rooms") , d(new Private) { @@ -41,10 +43,10 @@ const QStringList& GetJoinedRoomsJob::joinedRooms() const BaseJob::Status GetJoinedRoomsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("joined_rooms")) + if (!json.contains("joined_rooms"_ls)) return { JsonParseError, "The key 'joined_rooms' not found in the response" }; - d->joinedRooms = fromJson<QStringList>(json.value("joined_rooms")); + d->joinedRooms = fromJson<QStringList>(json.value("joined_rooms"_ls)); return Success; } diff --git a/lib/csapi/list_public_rooms.cpp b/lib/csapi/list_public_rooms.cpp index 5d605bbb..c34af34c 100644 --- a/lib/csapi/list_public_rooms.cpp +++ b/lib/csapi/list_public_rooms.cpp @@ -24,8 +24,10 @@ QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString basePath % "/directory/list/room/" % roomId); } +static const auto GetRoomVisibilityOnDirectoryJobName = QStringLiteral("GetRoomVisibilityOnDirectoryJob"); + GetRoomVisibilityOnDirectoryJob::GetRoomVisibilityOnDirectoryJob(const QString& roomId) - : BaseJob(HttpVerb::Get, "GetRoomVisibilityOnDirectoryJob", + : BaseJob(HttpVerb::Get, GetRoomVisibilityOnDirectoryJobName, basePath % "/directory/list/room/" % roomId, false) , d(new Private) { @@ -41,16 +43,18 @@ const QString& GetRoomVisibilityOnDirectoryJob::visibility() const BaseJob::Status GetRoomVisibilityOnDirectoryJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->visibility = fromJson<QString>(json.value("visibility")); + d->visibility = fromJson<QString>(json.value("visibility"_ls)); return Success; } +static const auto SetRoomVisibilityOnDirectoryJobName = QStringLiteral("SetRoomVisibilityOnDirectoryJob"); + SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility) - : BaseJob(HttpVerb::Put, "SetRoomVisibilityOnDirectoryJob", + : BaseJob(HttpVerb::Put, SetRoomVisibilityOnDirectoryJobName, basePath % "/directory/list/room/" % roomId) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "visibility", visibility); + addParam<IfNotEmpty>(_data, QStringLiteral("visibility"), visibility); setRequestData(_data); } @@ -65,23 +69,23 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson<QStringList>(_json.value("aliases")); + fromJson<QStringList>(_json.value("aliases"_ls)); result.canonicalAlias = - fromJson<QString>(_json.value("canonical_alias")); + fromJson<QString>(_json.value("canonical_alias"_ls)); result.name = - fromJson<QString>(_json.value("name")); + fromJson<QString>(_json.value("name"_ls)); result.numJoinedMembers = - fromJson<qint64>(_json.value("num_joined_members")); + fromJson<qint64>(_json.value("num_joined_members"_ls)); result.roomId = - fromJson<QString>(_json.value("room_id")); + fromJson<QString>(_json.value("room_id"_ls)); result.topic = - fromJson<QString>(_json.value("topic")); + fromJson<QString>(_json.value("topic"_ls)); result.worldReadable = - fromJson<bool>(_json.value("world_readable")); + fromJson<bool>(_json.value("world_readable"_ls)); result.guestCanJoin = - fromJson<bool>(_json.value("guest_can_join")); + fromJson<bool>(_json.value("guest_can_join"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url")); + fromJson<QString>(_json.value("avatar_url"_ls)); return result; } @@ -100,9 +104,9 @@ class GetPublicRoomsJob::Private BaseJob::Query queryToGetPublicRooms(Omittable<int> limit, const QString& since, const QString& server) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "limit", limit); - addParam<IfNotEmpty>(_q, "since", since); - addParam<IfNotEmpty>(_q, "server", server); + addParam<IfNotEmpty>(_q, QStringLiteral("limit"), limit); + addParam<IfNotEmpty>(_q, QStringLiteral("since"), since); + addParam<IfNotEmpty>(_q, QStringLiteral("server"), server); return _q; } @@ -113,8 +117,10 @@ QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, Omittable<int> limit, const queryToGetPublicRooms(limit, since, server)); } +static const auto GetPublicRoomsJobName = QStringLiteral("GetPublicRoomsJob"); + GetPublicRoomsJob::GetPublicRoomsJob(Omittable<int> limit, const QString& since, const QString& server) - : BaseJob(HttpVerb::Get, "GetPublicRoomsJob", + : BaseJob(HttpVerb::Get, GetPublicRoomsJobName, basePath % "/publicRooms", queryToGetPublicRooms(limit, since, server), {}, false) @@ -147,13 +153,13 @@ Omittable<qint64> GetPublicRoomsJob::totalRoomCountEstimate() const BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("chunk")) + if (!json.contains("chunk"_ls)) return { JsonParseError, "The key 'chunk' not found in the response" }; - d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk")); - d->nextBatch = fromJson<QString>(json.value("next_batch")); - d->prevBatch = fromJson<QString>(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate")); + d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk"_ls)); + d->nextBatch = fromJson<QString>(json.value("next_batch"_ls)); + d->prevBatch = fromJson<QString>(json.value("prev_batch"_ls)); + d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate"_ls)); return Success; } @@ -164,7 +170,7 @@ namespace QMatrixClient QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "generic_search_term", pod.genericSearchTerm); + addParam<IfNotEmpty>(_json, QStringLiteral("generic_search_term"), pod.genericSearchTerm); return _json; } @@ -175,23 +181,23 @@ namespace QMatrixClient const auto& _json = jv.toObject(); QueryPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson<QStringList>(_json.value("aliases")); + fromJson<QStringList>(_json.value("aliases"_ls)); result.canonicalAlias = - fromJson<QString>(_json.value("canonical_alias")); + fromJson<QString>(_json.value("canonical_alias"_ls)); result.name = - fromJson<QString>(_json.value("name")); + fromJson<QString>(_json.value("name"_ls)); result.numJoinedMembers = - fromJson<qint64>(_json.value("num_joined_members")); + fromJson<qint64>(_json.value("num_joined_members"_ls)); result.roomId = - fromJson<QString>(_json.value("room_id")); + fromJson<QString>(_json.value("room_id"_ls)); result.topic = - fromJson<QString>(_json.value("topic")); + fromJson<QString>(_json.value("topic"_ls)); result.worldReadable = - fromJson<bool>(_json.value("world_readable")); + fromJson<bool>(_json.value("world_readable"_ls)); result.guestCanJoin = - fromJson<bool>(_json.value("guest_can_join")); + fromJson<bool>(_json.value("guest_can_join"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url")); + fromJson<QString>(_json.value("avatar_url"_ls)); return result; } @@ -210,20 +216,22 @@ class QueryPublicRoomsJob::Private BaseJob::Query queryToQueryPublicRooms(const QString& server) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "server", server); + addParam<IfNotEmpty>(_q, QStringLiteral("server"), server); return _q; } +static const auto QueryPublicRoomsJobName = QStringLiteral("QueryPublicRoomsJob"); + QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, Omittable<int> limit, const QString& since, const Omittable<Filter>& filter) - : BaseJob(HttpVerb::Post, "QueryPublicRoomsJob", + : BaseJob(HttpVerb::Post, QueryPublicRoomsJobName, basePath % "/publicRooms", queryToQueryPublicRooms(server)) , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "limit", limit); - addParam<IfNotEmpty>(_data, "since", since); - addParam<IfNotEmpty>(_data, "filter", filter); + addParam<IfNotEmpty>(_data, QStringLiteral("limit"), limit); + addParam<IfNotEmpty>(_data, QStringLiteral("since"), since); + addParam<IfNotEmpty>(_data, QStringLiteral("filter"), filter); setRequestData(_data); } @@ -252,13 +260,13 @@ Omittable<qint64> QueryPublicRoomsJob::totalRoomCountEstimate() const BaseJob::Status QueryPublicRoomsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("chunk")) + if (!json.contains("chunk"_ls)) return { JsonParseError, "The key 'chunk' not found in the response" }; - d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk")); - d->nextBatch = fromJson<QString>(json.value("next_batch")); - d->prevBatch = fromJson<QString>(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate")); + d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk"_ls)); + d->nextBatch = fromJson<QString>(json.value("next_batch"_ls)); + d->prevBatch = fromJson<QString>(json.value("prev_batch"_ls)); + d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate"_ls)); return Success; } diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp index e0795f8a..b8734d05 100644 --- a/lib/csapi/login.cpp +++ b/lib/csapi/login.cpp @@ -21,20 +21,22 @@ class LoginJob::Private QString deviceId; }; +static const auto LoginJobName = QStringLiteral("LoginJob"); + LoginJob::LoginJob(const QString& type, const QString& user, const QString& medium, const QString& address, const QString& password, const QString& token, const QString& deviceId, const QString& initialDeviceDisplayName) - : BaseJob(HttpVerb::Post, "LoginJob", + : BaseJob(HttpVerb::Post, LoginJobName, basePath % "/login", false) , d(new Private) { QJsonObject _data; - addParam<>(_data, "type", type); - addParam<IfNotEmpty>(_data, "user", user); - addParam<IfNotEmpty>(_data, "medium", medium); - addParam<IfNotEmpty>(_data, "address", address); - addParam<IfNotEmpty>(_data, "password", password); - addParam<IfNotEmpty>(_data, "token", token); - addParam<IfNotEmpty>(_data, "device_id", deviceId); - addParam<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); + addParam<>(_data, QStringLiteral("type"), type); + addParam<IfNotEmpty>(_data, QStringLiteral("user"), user); + addParam<IfNotEmpty>(_data, QStringLiteral("medium"), medium); + addParam<IfNotEmpty>(_data, QStringLiteral("address"), address); + addParam<IfNotEmpty>(_data, QStringLiteral("password"), password); + addParam<IfNotEmpty>(_data, QStringLiteral("token"), token); + addParam<IfNotEmpty>(_data, QStringLiteral("device_id"), deviceId); + addParam<IfNotEmpty>(_data, QStringLiteral("initial_device_display_name"), initialDeviceDisplayName); setRequestData(_data); } @@ -63,10 +65,10 @@ const QString& LoginJob::deviceId() const BaseJob::Status LoginJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->userId = fromJson<QString>(json.value("user_id")); - d->accessToken = fromJson<QString>(json.value("access_token")); - d->homeServer = fromJson<QString>(json.value("home_server")); - d->deviceId = fromJson<QString>(json.value("device_id")); + d->userId = fromJson<QString>(json.value("user_id"_ls)); + d->accessToken = fromJson<QString>(json.value("access_token"_ls)); + d->homeServer = fromJson<QString>(json.value("home_server"_ls)); + d->deviceId = fromJson<QString>(json.value("device_id"_ls)); return Success; } diff --git a/lib/csapi/logout.cpp b/lib/csapi/logout.cpp index 42f99bbc..6e209e07 100644 --- a/lib/csapi/logout.cpp +++ b/lib/csapi/logout.cpp @@ -18,8 +18,10 @@ QUrl LogoutJob::makeRequestUrl(QUrl baseUrl) basePath % "/logout"); } +static const auto LogoutJobName = QStringLiteral("LogoutJob"); + LogoutJob::LogoutJob() - : BaseJob(HttpVerb::Post, "LogoutJob", + : BaseJob(HttpVerb::Post, LogoutJobName, basePath % "/logout") { } @@ -30,8 +32,10 @@ QUrl LogoutAllJob::makeRequestUrl(QUrl baseUrl) basePath % "/logout/all"); } +static const auto LogoutAllJobName = QStringLiteral("LogoutAllJob"); + LogoutAllJob::LogoutAllJob() - : BaseJob(HttpVerb::Post, "LogoutAllJob", + : BaseJob(HttpVerb::Post, LogoutAllJobName, basePath % "/logout/all") { } diff --git a/lib/csapi/message_pagination.cpp b/lib/csapi/message_pagination.cpp index 1eb2aa07..c59a51ab 100644 --- a/lib/csapi/message_pagination.cpp +++ b/lib/csapi/message_pagination.cpp @@ -23,11 +23,11 @@ class GetRoomEventsJob::Private BaseJob::Query queryToGetRoomEvents(const QString& from, const QString& to, const QString& dir, Omittable<int> limit, const QString& filter) { BaseJob::Query _q; - addParam<>(_q, "from", from); - addParam<IfNotEmpty>(_q, "to", to); - addParam<>(_q, "dir", dir); - addParam<IfNotEmpty>(_q, "limit", limit); - addParam<IfNotEmpty>(_q, "filter", filter); + addParam<>(_q, QStringLiteral("from"), from); + addParam<IfNotEmpty>(_q, QStringLiteral("to"), to); + addParam<>(_q, QStringLiteral("dir"), dir); + addParam<IfNotEmpty>(_q, QStringLiteral("limit"), limit); + addParam<IfNotEmpty>(_q, QStringLiteral("filter"), filter); return _q; } @@ -38,8 +38,10 @@ QUrl GetRoomEventsJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const queryToGetRoomEvents(from, to, dir, limit, filter)); } +static const auto GetRoomEventsJobName = QStringLiteral("GetRoomEventsJob"); + GetRoomEventsJob::GetRoomEventsJob(const QString& roomId, const QString& from, const QString& dir, const QString& to, Omittable<int> limit, const QString& filter) - : BaseJob(HttpVerb::Get, "GetRoomEventsJob", + : BaseJob(HttpVerb::Get, GetRoomEventsJobName, basePath % "/rooms/" % roomId % "/messages", queryToGetRoomEvents(from, to, dir, limit, filter)) , d(new Private) @@ -66,9 +68,9 @@ RoomEvents&& GetRoomEventsJob::chunk() BaseJob::Status GetRoomEventsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->begin = fromJson<QString>(json.value("start")); - d->end = fromJson<QString>(json.value("end")); - d->chunk = fromJson<RoomEvents>(json.value("chunk")); + d->begin = fromJson<QString>(json.value("start"_ls)); + d->end = fromJson<QString>(json.value("end"_ls)); + d->chunk = fromJson<RoomEvents>(json.value("chunk"_ls)); return Success; } diff --git a/lib/csapi/message_pagination.h b/lib/csapi/message_pagination.h index 92b258ea..58900940 100644 --- a/lib/csapi/message_pagination.h +++ b/lib/csapi/message_pagination.h @@ -6,7 +6,7 @@ #include "jobs/basejob.h" -#include "events/event.h" +#include "events/eventloader.h" #include "converters.h" namespace QMatrixClient diff --git a/lib/csapi/notifications.cpp b/lib/csapi/notifications.cpp index 39570991..f98cddd2 100644 --- a/lib/csapi/notifications.cpp +++ b/lib/csapi/notifications.cpp @@ -23,17 +23,17 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetNotificationsJob::Notification result; result.actions = - fromJson<QVector<QVariant>>(_json.value("actions")); + fromJson<QVector<QVariant>>(_json.value("actions"_ls)); result.event = - fromJson<EventPtr>(_json.value("event")); + fromJson<EventPtr>(_json.value("event"_ls)); result.profileTag = - fromJson<QString>(_json.value("profile_tag")); + fromJson<QString>(_json.value("profile_tag"_ls)); result.read = - fromJson<bool>(_json.value("read")); + fromJson<bool>(_json.value("read"_ls)); result.roomId = - fromJson<QString>(_json.value("room_id")); + fromJson<QString>(_json.value("room_id"_ls)); result.ts = - fromJson<qint64>(_json.value("ts")); + fromJson<qint64>(_json.value("ts"_ls)); return result; } @@ -50,9 +50,9 @@ class GetNotificationsJob::Private BaseJob::Query queryToGetNotifications(const QString& from, Omittable<int> limit, const QString& only) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "from", from); - addParam<IfNotEmpty>(_q, "limit", limit); - addParam<IfNotEmpty>(_q, "only", only); + addParam<IfNotEmpty>(_q, QStringLiteral("from"), from); + addParam<IfNotEmpty>(_q, QStringLiteral("limit"), limit); + addParam<IfNotEmpty>(_q, QStringLiteral("only"), only); return _q; } @@ -63,8 +63,10 @@ QUrl GetNotificationsJob::makeRequestUrl(QUrl baseUrl, const QString& from, Omit queryToGetNotifications(from, limit, only)); } +static const auto GetNotificationsJobName = QStringLiteral("GetNotificationsJob"); + GetNotificationsJob::GetNotificationsJob(const QString& from, Omittable<int> limit, const QString& only) - : BaseJob(HttpVerb::Get, "GetNotificationsJob", + : BaseJob(HttpVerb::Get, GetNotificationsJobName, basePath % "/notifications", queryToGetNotifications(from, limit, only)) , d(new Private) @@ -86,11 +88,11 @@ std::vector<GetNotificationsJob::Notification>&& GetNotificationsJob::notificati BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->nextToken = fromJson<QString>(json.value("next_token")); - if (!json.contains("notifications")) + d->nextToken = fromJson<QString>(json.value("next_token"_ls)); + if (!json.contains("notifications"_ls)) return { JsonParseError, "The key 'notifications' not found in the response" }; - d->notifications = fromJson<std::vector<Notification>>(json.value("notifications")); + d->notifications = fromJson<std::vector<Notification>>(json.value("notifications"_ls)); return Success; } diff --git a/lib/csapi/notifications.h b/lib/csapi/notifications.h index 094fa3af..3698431d 100644 --- a/lib/csapi/notifications.h +++ b/lib/csapi/notifications.h @@ -6,7 +6,7 @@ #include "jobs/basejob.h" -#include "events/event.h" +#include "events/eventloader.h" #include "converters.h" #include <QtCore/QVector> #include <QtCore/QVariant> diff --git a/lib/csapi/peeking_events.cpp b/lib/csapi/peeking_events.cpp index b3be7631..e046a62e 100644 --- a/lib/csapi/peeking_events.cpp +++ b/lib/csapi/peeking_events.cpp @@ -23,9 +23,9 @@ class PeekEventsJob::Private BaseJob::Query queryToPeekEvents(const QString& from, Omittable<int> timeout, const QString& roomId) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "from", from); - addParam<IfNotEmpty>(_q, "timeout", timeout); - addParam<IfNotEmpty>(_q, "room_id", roomId); + addParam<IfNotEmpty>(_q, QStringLiteral("from"), from); + addParam<IfNotEmpty>(_q, QStringLiteral("timeout"), timeout); + addParam<IfNotEmpty>(_q, QStringLiteral("room_id"), roomId); return _q; } @@ -36,8 +36,10 @@ QUrl PeekEventsJob::makeRequestUrl(QUrl baseUrl, const QString& from, Omittable< queryToPeekEvents(from, timeout, roomId)); } +static const auto PeekEventsJobName = QStringLiteral("PeekEventsJob"); + PeekEventsJob::PeekEventsJob(const QString& from, Omittable<int> timeout, const QString& roomId) - : BaseJob(HttpVerb::Get, "PeekEventsJob", + : BaseJob(HttpVerb::Get, PeekEventsJobName, basePath % "/events", queryToPeekEvents(from, timeout, roomId)) , d(new Private) @@ -64,9 +66,9 @@ RoomEvents&& PeekEventsJob::chunk() BaseJob::Status PeekEventsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->begin = fromJson<QString>(json.value("start")); - d->end = fromJson<QString>(json.value("end")); - d->chunk = fromJson<RoomEvents>(json.value("chunk")); + d->begin = fromJson<QString>(json.value("start"_ls)); + d->end = fromJson<QString>(json.value("end"_ls)); + d->chunk = fromJson<RoomEvents>(json.value("chunk"_ls)); return Success; } diff --git a/lib/csapi/peeking_events.h b/lib/csapi/peeking_events.h index f8876bf1..5f2c4233 100644 --- a/lib/csapi/peeking_events.h +++ b/lib/csapi/peeking_events.h @@ -6,7 +6,7 @@ #include "jobs/basejob.h" -#include "events/event.h" +#include "events/eventloader.h" #include "converters.h" namespace QMatrixClient diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp index 35b2c960..66827163 100644 --- a/lib/csapi/presence.cpp +++ b/lib/csapi/presence.cpp @@ -12,13 +12,15 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto SetPresenceJobName = QStringLiteral("SetPresenceJob"); + SetPresenceJob::SetPresenceJob(const QString& userId, const QString& presence, const QString& statusMsg) - : BaseJob(HttpVerb::Put, "SetPresenceJob", + : BaseJob(HttpVerb::Put, SetPresenceJobName, basePath % "/presence/" % userId % "/status") { QJsonObject _data; - addParam<>(_data, "presence", presence); - addParam<IfNotEmpty>(_data, "status_msg", statusMsg); + addParam<>(_data, QStringLiteral("presence"), presence); + addParam<IfNotEmpty>(_data, QStringLiteral("status_msg"), statusMsg); setRequestData(_data); } @@ -37,8 +39,10 @@ QUrl GetPresenceJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/presence/" % userId % "/status"); } +static const auto GetPresenceJobName = QStringLiteral("GetPresenceJob"); + GetPresenceJob::GetPresenceJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetPresenceJob", + : BaseJob(HttpVerb::Get, GetPresenceJobName, basePath % "/presence/" % userId % "/status", false) , d(new Private) { @@ -69,23 +73,25 @@ bool GetPresenceJob::currentlyActive() const BaseJob::Status GetPresenceJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("presence")) + if (!json.contains("presence"_ls)) return { JsonParseError, "The key 'presence' not found in the response" }; - d->presence = fromJson<QString>(json.value("presence")); - d->lastActiveAgo = fromJson<int>(json.value("last_active_ago")); - d->statusMsg = fromJson<QString>(json.value("status_msg")); - d->currentlyActive = fromJson<bool>(json.value("currently_active")); + d->presence = fromJson<QString>(json.value("presence"_ls)); + d->lastActiveAgo = fromJson<int>(json.value("last_active_ago"_ls)); + d->statusMsg = fromJson<QString>(json.value("status_msg"_ls)); + d->currentlyActive = fromJson<bool>(json.value("currently_active"_ls)); return Success; } +static const auto ModifyPresenceListJobName = QStringLiteral("ModifyPresenceListJob"); + ModifyPresenceListJob::ModifyPresenceListJob(const QString& userId, const QStringList& invite, const QStringList& drop) - : BaseJob(HttpVerb::Post, "ModifyPresenceListJob", + : BaseJob(HttpVerb::Post, ModifyPresenceListJobName, basePath % "/presence/list/" % userId) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "invite", invite); - addParam<IfNotEmpty>(_data, "drop", drop); + addParam<IfNotEmpty>(_data, QStringLiteral("invite"), invite); + addParam<IfNotEmpty>(_data, QStringLiteral("drop"), drop); setRequestData(_data); } @@ -101,8 +107,10 @@ QUrl GetPresenceForListJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/presence/list/" % userId); } +static const auto GetPresenceForListJobName = QStringLiteral("GetPresenceForListJob"); + GetPresenceForListJob::GetPresenceForListJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetPresenceForListJob", + : BaseJob(HttpVerb::Get, GetPresenceForListJobName, basePath % "/presence/list/" % userId, false) , d(new Private) { @@ -118,10 +126,10 @@ Events&& GetPresenceForListJob::data() BaseJob::Status GetPresenceForListJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<Events>(json.value("data")); + d->data = fromJson<Events>(json.value("data"_ls)); return Success; } diff --git a/lib/csapi/presence.h b/lib/csapi/presence.h index 2def94ba..7d6665f3 100644 --- a/lib/csapi/presence.h +++ b/lib/csapi/presence.h @@ -6,7 +6,7 @@ #include "jobs/basejob.h" -#include "events/event.h" +#include "events/eventloader.h" #include "converters.h" namespace QMatrixClient diff --git a/lib/csapi/profile.cpp b/lib/csapi/profile.cpp index b08eb970..bb053062 100644 --- a/lib/csapi/profile.cpp +++ b/lib/csapi/profile.cpp @@ -12,12 +12,14 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto SetDisplayNameJobName = QStringLiteral("SetDisplayNameJob"); + SetDisplayNameJob::SetDisplayNameJob(const QString& userId, const QString& displayname) - : BaseJob(HttpVerb::Put, "SetDisplayNameJob", + : BaseJob(HttpVerb::Put, SetDisplayNameJobName, basePath % "/profile/" % userId % "/displayname") { QJsonObject _data; - addParam<IfNotEmpty>(_data, "displayname", displayname); + addParam<IfNotEmpty>(_data, QStringLiteral("displayname"), displayname); setRequestData(_data); } @@ -33,8 +35,10 @@ QUrl GetDisplayNameJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/profile/" % userId % "/displayname"); } +static const auto GetDisplayNameJobName = QStringLiteral("GetDisplayNameJob"); + GetDisplayNameJob::GetDisplayNameJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetDisplayNameJob", + : BaseJob(HttpVerb::Get, GetDisplayNameJobName, basePath % "/profile/" % userId % "/displayname", false) , d(new Private) { @@ -50,16 +54,18 @@ const QString& GetDisplayNameJob::displayname() const BaseJob::Status GetDisplayNameJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->displayname = fromJson<QString>(json.value("displayname")); + d->displayname = fromJson<QString>(json.value("displayname"_ls)); return Success; } +static const auto SetAvatarUrlJobName = QStringLiteral("SetAvatarUrlJob"); + SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QString& avatarUrl) - : BaseJob(HttpVerb::Put, "SetAvatarUrlJob", + : BaseJob(HttpVerb::Put, SetAvatarUrlJobName, basePath % "/profile/" % userId % "/avatar_url") { QJsonObject _data; - addParam<IfNotEmpty>(_data, "avatar_url", avatarUrl); + addParam<IfNotEmpty>(_data, QStringLiteral("avatar_url"), avatarUrl); setRequestData(_data); } @@ -75,8 +81,10 @@ QUrl GetAvatarUrlJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/profile/" % userId % "/avatar_url"); } +static const auto GetAvatarUrlJobName = QStringLiteral("GetAvatarUrlJob"); + GetAvatarUrlJob::GetAvatarUrlJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetAvatarUrlJob", + : BaseJob(HttpVerb::Get, GetAvatarUrlJobName, basePath % "/profile/" % userId % "/avatar_url", false) , d(new Private) { @@ -92,7 +100,7 @@ const QString& GetAvatarUrlJob::avatarUrl() const BaseJob::Status GetAvatarUrlJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->avatarUrl = fromJson<QString>(json.value("avatar_url")); + d->avatarUrl = fromJson<QString>(json.value("avatar_url"_ls)); return Success; } @@ -109,8 +117,10 @@ QUrl GetUserProfileJob::makeRequestUrl(QUrl baseUrl, const QString& userId) basePath % "/profile/" % userId); } +static const auto GetUserProfileJobName = QStringLiteral("GetUserProfileJob"); + GetUserProfileJob::GetUserProfileJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetUserProfileJob", + : BaseJob(HttpVerb::Get, GetUserProfileJobName, basePath % "/profile/" % userId, false) , d(new Private) { @@ -131,8 +141,8 @@ const QString& GetUserProfileJob::displayname() const BaseJob::Status GetUserProfileJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->avatarUrl = fromJson<QString>(json.value("avatar_url")); - d->displayname = fromJson<QString>(json.value("displayname")); + d->avatarUrl = fromJson<QString>(json.value("avatar_url"_ls)); + d->displayname = fromJson<QString>(json.value("displayname"_ls)); return Success; } diff --git a/lib/csapi/pusher.cpp b/lib/csapi/pusher.cpp index 1a43900b..feecdbc7 100644 --- a/lib/csapi/pusher.cpp +++ b/lib/csapi/pusher.cpp @@ -23,7 +23,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetPushersJob::PusherData result; result.url = - fromJson<QString>(_json.value("url")); + fromJson<QString>(_json.value("url"_ls)); return result; } @@ -36,21 +36,21 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetPushersJob::Pusher result; result.pushkey = - fromJson<QString>(_json.value("pushkey")); + fromJson<QString>(_json.value("pushkey"_ls)); result.kind = - fromJson<QString>(_json.value("kind")); + fromJson<QString>(_json.value("kind"_ls)); result.appId = - fromJson<QString>(_json.value("app_id")); + fromJson<QString>(_json.value("app_id"_ls)); result.appDisplayName = - fromJson<QString>(_json.value("app_display_name")); + fromJson<QString>(_json.value("app_display_name"_ls)); result.deviceDisplayName = - fromJson<QString>(_json.value("device_display_name")); + fromJson<QString>(_json.value("device_display_name"_ls)); result.profileTag = - fromJson<QString>(_json.value("profile_tag")); + fromJson<QString>(_json.value("profile_tag"_ls)); result.lang = - fromJson<QString>(_json.value("lang")); + fromJson<QString>(_json.value("lang"_ls)); result.data = - fromJson<GetPushersJob::PusherData>(_json.value("data")); + fromJson<GetPushersJob::PusherData>(_json.value("data"_ls)); return result; } @@ -69,8 +69,10 @@ QUrl GetPushersJob::makeRequestUrl(QUrl baseUrl) basePath % "/pushers"); } +static const auto GetPushersJobName = QStringLiteral("GetPushersJob"); + GetPushersJob::GetPushersJob() - : BaseJob(HttpVerb::Get, "GetPushersJob", + : BaseJob(HttpVerb::Get, GetPushersJobName, basePath % "/pushers") , d(new Private) { @@ -86,7 +88,7 @@ const QVector<GetPushersJob::Pusher>& GetPushersJob::pushers() const BaseJob::Status GetPushersJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->pushers = fromJson<QVector<Pusher>>(json.value("pushers")); + d->pushers = fromJson<QVector<Pusher>>(json.value("pushers"_ls)); return Success; } @@ -97,25 +99,27 @@ namespace QMatrixClient QJsonObject toJson(const PostPusherJob::PusherData& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "url", pod.url); + addParam<IfNotEmpty>(_json, QStringLiteral("url"), pod.url); return _json; } } // namespace QMatrixClient +static const auto PostPusherJobName = QStringLiteral("PostPusherJob"); + PostPusherJob::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) - : BaseJob(HttpVerb::Post, "PostPusherJob", + : BaseJob(HttpVerb::Post, PostPusherJobName, basePath % "/pushers/set") { QJsonObject _data; - addParam<>(_data, "pushkey", pushkey); - addParam<>(_data, "kind", kind); - addParam<>(_data, "app_id", appId); - addParam<>(_data, "app_display_name", appDisplayName); - addParam<>(_data, "device_display_name", deviceDisplayName); - addParam<IfNotEmpty>(_data, "profile_tag", profileTag); - addParam<>(_data, "lang", lang); - addParam<>(_data, "data", data); - addParam<IfNotEmpty>(_data, "append", append); + addParam<>(_data, QStringLiteral("pushkey"), pushkey); + addParam<>(_data, QStringLiteral("kind"), kind); + addParam<>(_data, QStringLiteral("app_id"), appId); + addParam<>(_data, QStringLiteral("app_display_name"), appDisplayName); + addParam<>(_data, QStringLiteral("device_display_name"), deviceDisplayName); + addParam<IfNotEmpty>(_data, QStringLiteral("profile_tag"), profileTag); + addParam<>(_data, QStringLiteral("lang"), lang); + addParam<>(_data, QStringLiteral("data"), data); + addParam<IfNotEmpty>(_data, QStringLiteral("append"), append); setRequestData(_data); } diff --git a/lib/csapi/pushrules.cpp b/lib/csapi/pushrules.cpp index d7e416dc..22976641 100644 --- a/lib/csapi/pushrules.cpp +++ b/lib/csapi/pushrules.cpp @@ -24,8 +24,10 @@ QUrl GetPushRulesJob::makeRequestUrl(QUrl baseUrl) basePath % "/pushrules"); } +static const auto GetPushRulesJobName = QStringLiteral("GetPushRulesJob"); + GetPushRulesJob::GetPushRulesJob() - : BaseJob(HttpVerb::Get, "GetPushRulesJob", + : BaseJob(HttpVerb::Get, GetPushRulesJobName, basePath % "/pushrules") , d(new Private) { @@ -41,10 +43,10 @@ const PushRuleset& GetPushRulesJob::global() const BaseJob::Status GetPushRulesJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("global")) + if (!json.contains("global"_ls)) return { JsonParseError, "The key 'global' not found in the response" }; - d->global = fromJson<PushRuleset>(json.value("global")); + d->global = fromJson<PushRuleset>(json.value("global"_ls)); return Success; } @@ -60,8 +62,10 @@ QUrl GetPushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const QS basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId); } +static const auto GetPushRuleJobName = QStringLiteral("GetPushRuleJob"); + GetPushRuleJob::GetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId) - : BaseJob(HttpVerb::Get, "GetPushRuleJob", + : BaseJob(HttpVerb::Get, GetPushRuleJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId) , d(new Private) { @@ -77,10 +81,10 @@ const PushRule& GetPushRuleJob::data() const BaseJob::Status GetPushRuleJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<PushRule>(json.value("data")); + d->data = fromJson<PushRule>(json.value("data"_ls)); return Success; } @@ -90,8 +94,10 @@ QUrl DeletePushRuleJob::makeRequestUrl(QUrl baseUrl, const QString& scope, const basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId); } +static const auto DeletePushRuleJobName = QStringLiteral("DeletePushRuleJob"); + DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, const QString& ruleId) - : BaseJob(HttpVerb::Delete, "DeletePushRuleJob", + : BaseJob(HttpVerb::Delete, DeletePushRuleJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId) { } @@ -99,20 +105,22 @@ DeletePushRuleJob::DeletePushRuleJob(const QString& scope, const QString& kind, BaseJob::Query queryToSetPushRule(const QString& before, const QString& after) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "before", before); - addParam<IfNotEmpty>(_q, "after", after); + addParam<IfNotEmpty>(_q, QStringLiteral("before"), before); + addParam<IfNotEmpty>(_q, QStringLiteral("after"), after); return _q; } +static const auto SetPushRuleJobName = QStringLiteral("SetPushRuleJob"); + SetPushRuleJob::SetPushRuleJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions, const QString& before, const QString& after, const QVector<PushCondition>& conditions, const QString& pattern) - : BaseJob(HttpVerb::Put, "SetPushRuleJob", + : BaseJob(HttpVerb::Put, SetPushRuleJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId, queryToSetPushRule(before, after)) { QJsonObject _data; - addParam<>(_data, "actions", actions); - addParam<IfNotEmpty>(_data, "conditions", conditions); - addParam<IfNotEmpty>(_data, "pattern", pattern); + addParam<>(_data, QStringLiteral("actions"), actions); + addParam<IfNotEmpty>(_data, QStringLiteral("conditions"), conditions); + addParam<IfNotEmpty>(_data, QStringLiteral("pattern"), pattern); setRequestData(_data); } @@ -128,8 +136,10 @@ QUrl IsPushRuleEnabledJob::makeRequestUrl(QUrl baseUrl, const QString& scope, co basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled"); } +static const auto IsPushRuleEnabledJobName = QStringLiteral("IsPushRuleEnabledJob"); + IsPushRuleEnabledJob::IsPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId) - : BaseJob(HttpVerb::Get, "IsPushRuleEnabledJob", + : BaseJob(HttpVerb::Get, IsPushRuleEnabledJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled") , d(new Private) { @@ -145,19 +155,21 @@ bool IsPushRuleEnabledJob::enabled() const BaseJob::Status IsPushRuleEnabledJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("enabled")) + if (!json.contains("enabled"_ls)) return { JsonParseError, "The key 'enabled' not found in the response" }; - d->enabled = fromJson<bool>(json.value("enabled")); + d->enabled = fromJson<bool>(json.value("enabled"_ls)); return Success; } +static const auto SetPushRuleEnabledJobName = QStringLiteral("SetPushRuleEnabledJob"); + SetPushRuleEnabledJob::SetPushRuleEnabledJob(const QString& scope, const QString& kind, const QString& ruleId, bool enabled) - : BaseJob(HttpVerb::Put, "SetPushRuleEnabledJob", + : BaseJob(HttpVerb::Put, SetPushRuleEnabledJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/enabled") { QJsonObject _data; - addParam<>(_data, "enabled", enabled); + addParam<>(_data, QStringLiteral("enabled"), enabled); setRequestData(_data); } @@ -173,8 +185,10 @@ QUrl GetPushRuleActionsJob::makeRequestUrl(QUrl baseUrl, const QString& scope, c basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions"); } +static const auto GetPushRuleActionsJobName = QStringLiteral("GetPushRuleActionsJob"); + GetPushRuleActionsJob::GetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId) - : BaseJob(HttpVerb::Get, "GetPushRuleActionsJob", + : BaseJob(HttpVerb::Get, GetPushRuleActionsJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions") , d(new Private) { @@ -190,19 +204,21 @@ const QStringList& GetPushRuleActionsJob::actions() const BaseJob::Status GetPushRuleActionsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("actions")) + if (!json.contains("actions"_ls)) return { JsonParseError, "The key 'actions' not found in the response" }; - d->actions = fromJson<QStringList>(json.value("actions")); + d->actions = fromJson<QStringList>(json.value("actions"_ls)); return Success; } +static const auto SetPushRuleActionsJobName = QStringLiteral("SetPushRuleActionsJob"); + SetPushRuleActionsJob::SetPushRuleActionsJob(const QString& scope, const QString& kind, const QString& ruleId, const QStringList& actions) - : BaseJob(HttpVerb::Put, "SetPushRuleActionsJob", + : BaseJob(HttpVerb::Put, SetPushRuleActionsJobName, basePath % "/pushrules/" % scope % "/" % kind % "/" % ruleId % "/actions") { QJsonObject _data; - addParam<>(_data, "actions", actions); + addParam<>(_data, QStringLiteral("actions"), actions); setRequestData(_data); } diff --git a/lib/csapi/receipts.cpp b/lib/csapi/receipts.cpp index 945e8673..b78ba533 100644 --- a/lib/csapi/receipts.cpp +++ b/lib/csapi/receipts.cpp @@ -12,8 +12,10 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto PostReceiptJobName = QStringLiteral("PostReceiptJob"); + PostReceiptJob::PostReceiptJob(const QString& roomId, const QString& receiptType, const QString& eventId, const QJsonObject& receipt) - : BaseJob(HttpVerb::Post, "PostReceiptJob", + : BaseJob(HttpVerb::Post, PostReceiptJobName, basePath % "/rooms/" % roomId % "/receipt/" % receiptType % "/" % eventId) { setRequestData(Data(toJson(receipt))); diff --git a/lib/csapi/redaction.cpp b/lib/csapi/redaction.cpp index 2c73800c..64098670 100644 --- a/lib/csapi/redaction.cpp +++ b/lib/csapi/redaction.cpp @@ -18,13 +18,15 @@ class RedactEventJob::Private QString eventId; }; +static const auto RedactEventJobName = QStringLiteral("RedactEventJob"); + RedactEventJob::RedactEventJob(const QString& roomId, const QString& eventId, const QString& txnId, const QString& reason) - : BaseJob(HttpVerb::Put, "RedactEventJob", + : BaseJob(HttpVerb::Put, RedactEventJobName, basePath % "/rooms/" % roomId % "/redact/" % eventId % "/" % txnId) , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "reason", reason); + addParam<IfNotEmpty>(_data, QStringLiteral("reason"), reason); setRequestData(_data); } @@ -38,7 +40,7 @@ const QString& RedactEventJob::eventId() const BaseJob::Status RedactEventJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->eventId = fromJson<QString>(json.value("event_id")); + d->eventId = fromJson<QString>(json.value("event_id"_ls)); return Success; } diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp index 4345635a..4991829c 100644 --- a/lib/csapi/registration.cpp +++ b/lib/csapi/registration.cpp @@ -24,24 +24,26 @@ class RegisterJob::Private BaseJob::Query queryToRegister(const QString& kind) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "kind", kind); + addParam<IfNotEmpty>(_q, QStringLiteral("kind"), kind); return _q; } +static const auto RegisterJobName = QStringLiteral("RegisterJob"); + RegisterJob::RegisterJob(const QString& kind, const QJsonObject& auth, bool bindEmail, const QString& username, const QString& password, const QString& deviceId, const QString& initialDeviceDisplayName) - : BaseJob(HttpVerb::Post, "RegisterJob", + : BaseJob(HttpVerb::Post, RegisterJobName, basePath % "/register", queryToRegister(kind), {}, false) , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "auth", auth); - addParam<IfNotEmpty>(_data, "bind_email", bindEmail); - addParam<IfNotEmpty>(_data, "username", username); - addParam<IfNotEmpty>(_data, "password", password); - addParam<IfNotEmpty>(_data, "device_id", deviceId); - addParam<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); + addParam<IfNotEmpty>(_data, QStringLiteral("bind_email"), bindEmail); + addParam<IfNotEmpty>(_data, QStringLiteral("username"), username); + addParam<IfNotEmpty>(_data, QStringLiteral("password"), password); + addParam<IfNotEmpty>(_data, QStringLiteral("device_id"), deviceId); + addParam<IfNotEmpty>(_data, QStringLiteral("initial_device_display_name"), initialDeviceDisplayName); setRequestData(_data); } @@ -70,32 +72,36 @@ const QString& RegisterJob::deviceId() const BaseJob::Status RegisterJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->userId = fromJson<QString>(json.value("user_id")); - d->accessToken = fromJson<QString>(json.value("access_token")); - d->homeServer = fromJson<QString>(json.value("home_server")); - d->deviceId = fromJson<QString>(json.value("device_id")); + d->userId = fromJson<QString>(json.value("user_id"_ls)); + d->accessToken = fromJson<QString>(json.value("access_token"_ls)); + d->homeServer = fromJson<QString>(json.value("home_server"_ls)); + d->deviceId = fromJson<QString>(json.value("device_id"_ls)); return Success; } +static const auto RequestTokenToRegisterJobName = QStringLiteral("RequestTokenToRegisterJob"); + RequestTokenToRegisterJob::RequestTokenToRegisterJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer) - : BaseJob(HttpVerb::Post, "RequestTokenToRegisterJob", + : BaseJob(HttpVerb::Post, RequestTokenToRegisterJobName, basePath % "/register/email/requestToken", false) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "id_server", idServer); - addParam<>(_data, "client_secret", clientSecret); - addParam<>(_data, "email", email); - addParam<>(_data, "send_attempt", sendAttempt); + addParam<IfNotEmpty>(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("client_secret"), clientSecret); + addParam<>(_data, QStringLiteral("email"), email); + addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt); setRequestData(_data); } +static const auto ChangePasswordJobName = QStringLiteral("ChangePasswordJob"); + ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "ChangePasswordJob", + : BaseJob(HttpVerb::Post, ChangePasswordJobName, basePath % "/account/password") { QJsonObject _data; - addParam<>(_data, "new_password", newPassword); - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<>(_data, QStringLiteral("new_password"), newPassword); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -105,18 +111,22 @@ QUrl RequestTokenToResetPasswordJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/password/email/requestToken"); } +static const auto RequestTokenToResetPasswordJobName = QStringLiteral("RequestTokenToResetPasswordJob"); + RequestTokenToResetPasswordJob::RequestTokenToResetPasswordJob() - : BaseJob(HttpVerb::Post, "RequestTokenToResetPasswordJob", + : BaseJob(HttpVerb::Post, RequestTokenToResetPasswordJobName, basePath % "/account/password/email/requestToken", false) { } +static const auto DeactivateAccountJobName = QStringLiteral("DeactivateAccountJob"); + DeactivateAccountJob::DeactivateAccountJob(const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "DeactivateAccountJob", + : BaseJob(HttpVerb::Post, DeactivateAccountJobName, basePath % "/account/deactivate") { QJsonObject _data; - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -129,7 +139,7 @@ class CheckUsernameAvailabilityJob::Private BaseJob::Query queryToCheckUsernameAvailability(const QString& username) { BaseJob::Query _q; - addParam<>(_q, "username", username); + addParam<>(_q, QStringLiteral("username"), username); return _q; } @@ -140,8 +150,10 @@ QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl, const QString& u queryToCheckUsernameAvailability(username)); } +static const auto CheckUsernameAvailabilityJobName = QStringLiteral("CheckUsernameAvailabilityJob"); + CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(const QString& username) - : BaseJob(HttpVerb::Get, "CheckUsernameAvailabilityJob", + : BaseJob(HttpVerb::Get, CheckUsernameAvailabilityJobName, basePath % "/register/available", queryToCheckUsernameAvailability(username), {}, false) @@ -159,7 +171,7 @@ bool CheckUsernameAvailabilityJob::available() const BaseJob::Status CheckUsernameAvailabilityJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->available = fromJson<bool>(json.value("available")); + d->available = fromJson<bool>(json.value("available"_ls)); return Success; } diff --git a/lib/csapi/report_content.cpp b/lib/csapi/report_content.cpp index f1a1d6f2..a79d4dad 100644 --- a/lib/csapi/report_content.cpp +++ b/lib/csapi/report_content.cpp @@ -12,13 +12,15 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto ReportContentJobName = QStringLiteral("ReportContentJob"); + ReportContentJob::ReportContentJob(const QString& roomId, const QString& eventId, int score, const QString& reason) - : BaseJob(HttpVerb::Post, "ReportContentJob", + : BaseJob(HttpVerb::Post, ReportContentJobName, basePath % "/rooms/" % roomId % "/report/" % eventId) { QJsonObject _data; - addParam<>(_data, "score", score); - addParam<>(_data, "reason", reason); + addParam<>(_data, QStringLiteral("score"), score); + addParam<>(_data, QStringLiteral("reason"), reason); setRequestData(_data); } diff --git a/lib/csapi/room_send.cpp b/lib/csapi/room_send.cpp index 9637a205..2b39ede2 100644 --- a/lib/csapi/room_send.cpp +++ b/lib/csapi/room_send.cpp @@ -18,8 +18,10 @@ class SendMessageJob::Private QString eventId; }; +static const auto SendMessageJobName = QStringLiteral("SendMessageJob"); + SendMessageJob::SendMessageJob(const QString& roomId, const QString& eventType, const QString& txnId, const QJsonObject& body) - : BaseJob(HttpVerb::Put, "SendMessageJob", + : BaseJob(HttpVerb::Put, SendMessageJobName, basePath % "/rooms/" % roomId % "/send/" % eventType % "/" % txnId) , d(new Private) { @@ -36,7 +38,7 @@ const QString& SendMessageJob::eventId() const BaseJob::Status SendMessageJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->eventId = fromJson<QString>(json.value("event_id")); + d->eventId = fromJson<QString>(json.value("event_id"_ls)); return Success; } diff --git a/lib/csapi/room_state.cpp b/lib/csapi/room_state.cpp index 39f36afb..8f87979d 100644 --- a/lib/csapi/room_state.cpp +++ b/lib/csapi/room_state.cpp @@ -18,8 +18,10 @@ class SetRoomStateWithKeyJob::Private QString eventId; }; +static const auto SetRoomStateWithKeyJobName = QStringLiteral("SetRoomStateWithKeyJob"); + SetRoomStateWithKeyJob::SetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey, const QJsonObject& body) - : BaseJob(HttpVerb::Put, "SetRoomStateWithKeyJob", + : BaseJob(HttpVerb::Put, SetRoomStateWithKeyJobName, basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey) , d(new Private) { @@ -36,7 +38,7 @@ const QString& SetRoomStateWithKeyJob::eventId() const BaseJob::Status SetRoomStateWithKeyJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->eventId = fromJson<QString>(json.value("event_id")); + d->eventId = fromJson<QString>(json.value("event_id"_ls)); return Success; } @@ -46,8 +48,10 @@ class SetRoomStateJob::Private QString eventId; }; +static const auto SetRoomStateJobName = QStringLiteral("SetRoomStateJob"); + SetRoomStateJob::SetRoomStateJob(const QString& roomId, const QString& eventType, const QJsonObject& body) - : BaseJob(HttpVerb::Put, "SetRoomStateJob", + : BaseJob(HttpVerb::Put, SetRoomStateJobName, basePath % "/rooms/" % roomId % "/state/" % eventType) , d(new Private) { @@ -64,7 +68,7 @@ const QString& SetRoomStateJob::eventId() const BaseJob::Status SetRoomStateJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->eventId = fromJson<QString>(json.value("event_id")); + d->eventId = fromJson<QString>(json.value("event_id"_ls)); return Success; } diff --git a/lib/csapi/rooms.cpp b/lib/csapi/rooms.cpp index 4b66b447..a70d9543 100644 --- a/lib/csapi/rooms.cpp +++ b/lib/csapi/rooms.cpp @@ -24,8 +24,10 @@ QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, con basePath % "/rooms/" % roomId % "/event/" % eventId); } +static const auto GetOneRoomEventJobName = QStringLiteral("GetOneRoomEventJob"); + GetOneRoomEventJob::GetOneRoomEventJob(const QString& roomId, const QString& eventId) - : BaseJob(HttpVerb::Get, "GetOneRoomEventJob", + : BaseJob(HttpVerb::Get, GetOneRoomEventJobName, basePath % "/rooms/" % roomId % "/event/" % eventId) , d(new Private) { @@ -41,10 +43,10 @@ EventPtr&& GetOneRoomEventJob::data() BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<EventPtr>(json.value("data")); + d->data = fromJson<EventPtr>(json.value("data"_ls)); return Success; } @@ -60,8 +62,10 @@ QUrl GetRoomStateWithKeyJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey); } +static const auto GetRoomStateWithKeyJobName = QStringLiteral("GetRoomStateWithKeyJob"); + GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey) - : BaseJob(HttpVerb::Get, "GetRoomStateWithKeyJob", + : BaseJob(HttpVerb::Get, GetRoomStateWithKeyJobName, basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey) , d(new Private) { @@ -77,10 +81,10 @@ StateEventPtr&& GetRoomStateWithKeyJob::data() BaseJob::Status GetRoomStateWithKeyJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<StateEventPtr>(json.value("data")); + d->data = fromJson<StateEventPtr>(json.value("data"_ls)); return Success; } @@ -96,8 +100,10 @@ QUrl GetRoomStateByTypeJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, basePath % "/rooms/" % roomId % "/state/" % eventType); } +static const auto GetRoomStateByTypeJobName = QStringLiteral("GetRoomStateByTypeJob"); + GetRoomStateByTypeJob::GetRoomStateByTypeJob(const QString& roomId, const QString& eventType) - : BaseJob(HttpVerb::Get, "GetRoomStateByTypeJob", + : BaseJob(HttpVerb::Get, GetRoomStateByTypeJobName, basePath % "/rooms/" % roomId % "/state/" % eventType) , d(new Private) { @@ -113,10 +119,10 @@ StateEventPtr&& GetRoomStateByTypeJob::data() BaseJob::Status GetRoomStateByTypeJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<StateEventPtr>(json.value("data")); + d->data = fromJson<StateEventPtr>(json.value("data"_ls)); return Success; } @@ -132,8 +138,10 @@ QUrl GetRoomStateJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) basePath % "/rooms/" % roomId % "/state"); } +static const auto GetRoomStateJobName = QStringLiteral("GetRoomStateJob"); + GetRoomStateJob::GetRoomStateJob(const QString& roomId) - : BaseJob(HttpVerb::Get, "GetRoomStateJob", + : BaseJob(HttpVerb::Get, GetRoomStateJobName, basePath % "/rooms/" % roomId % "/state") , d(new Private) { @@ -149,10 +157,10 @@ StateEvents&& GetRoomStateJob::data() BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<StateEvents>(json.value("data")); + d->data = fromJson<StateEvents>(json.value("data"_ls)); return Success; } @@ -168,8 +176,10 @@ QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) basePath % "/rooms/" % roomId % "/members"); } +static const auto GetMembersByRoomJobName = QStringLiteral("GetMembersByRoomJob"); + GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Get, "GetMembersByRoomJob", + : BaseJob(HttpVerb::Get, GetMembersByRoomJobName, basePath % "/rooms/" % roomId % "/members") , d(new Private) { @@ -185,7 +195,7 @@ EventsArray<RoomMemberEvent>&& GetMembersByRoomJob::chunk() BaseJob::Status GetMembersByRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->chunk = fromJson<EventsArray<RoomMemberEvent>>(json.value("chunk")); + d->chunk = fromJson<EventsArray<RoomMemberEvent>>(json.value("chunk"_ls)); return Success; } @@ -200,9 +210,9 @@ namespace QMatrixClient const auto& _json = jv.toObject(); GetJoinedMembersByRoomJob::RoomMember result; result.displayName = - fromJson<QString>(_json.value("display_name")); + fromJson<QString>(_json.value("display_name"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url")); + fromJson<QString>(_json.value("avatar_url"_ls)); return result; } @@ -221,8 +231,10 @@ QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& room basePath % "/rooms/" % roomId % "/joined_members"); } +static const auto GetJoinedMembersByRoomJobName = QStringLiteral("GetJoinedMembersByRoomJob"); + GetJoinedMembersByRoomJob::GetJoinedMembersByRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Get, "GetJoinedMembersByRoomJob", + : BaseJob(HttpVerb::Get, GetJoinedMembersByRoomJobName, basePath % "/rooms/" % roomId % "/joined_members") , d(new Private) { @@ -238,7 +250,7 @@ const QHash<QString, GetJoinedMembersByRoomJob::RoomMember>& GetJoinedMembersByR BaseJob::Status GetJoinedMembersByRoomJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->joined = fromJson<QHash<QString, RoomMember>>(json.value("joined")); + d->joined = fromJson<QHash<QString, RoomMember>>(json.value("joined"_ls)); return Success; } diff --git a/lib/csapi/rooms.h b/lib/csapi/rooms.h index 459c6ad5..7d690ec8 100644 --- a/lib/csapi/rooms.h +++ b/lib/csapi/rooms.h @@ -6,8 +6,8 @@ #include "jobs/basejob.h" -#include "events/event.h" #include "events/roommemberevent.h" +#include "events/eventloader.h" #include <QtCore/QHash> #include "converters.h" diff --git a/lib/csapi/search.cpp b/lib/csapi/search.cpp index 75748b38..f3adb315 100644 --- a/lib/csapi/search.cpp +++ b/lib/csapi/search.cpp @@ -19,43 +19,43 @@ namespace QMatrixClient QJsonObject toJson(const SearchJob::IncludeEventContext& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "before_limit", pod.beforeLimit); - addParam<IfNotEmpty>(_json, "after_limit", pod.afterLimit); - addParam<IfNotEmpty>(_json, "include_profile", pod.includeProfile); + addParam<IfNotEmpty>(_json, QStringLiteral("before_limit"), pod.beforeLimit); + addParam<IfNotEmpty>(_json, QStringLiteral("after_limit"), pod.afterLimit); + addParam<IfNotEmpty>(_json, QStringLiteral("include_profile"), pod.includeProfile); return _json; } QJsonObject toJson(const SearchJob::Group& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "key", pod.key); + addParam<IfNotEmpty>(_json, QStringLiteral("key"), pod.key); return _json; } QJsonObject toJson(const SearchJob::Groupings& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "group_by", pod.groupBy); + addParam<IfNotEmpty>(_json, QStringLiteral("group_by"), pod.groupBy); return _json; } QJsonObject toJson(const SearchJob::RoomEventsCriteria& pod) { QJsonObject _json; - addParam<>(_json, "search_term", pod.searchTerm); - addParam<IfNotEmpty>(_json, "keys", pod.keys); - addParam<IfNotEmpty>(_json, "filter", pod.filter); - addParam<IfNotEmpty>(_json, "order_by", pod.orderBy); - addParam<IfNotEmpty>(_json, "event_context", pod.eventContext); - addParam<IfNotEmpty>(_json, "include_state", pod.includeState); - addParam<IfNotEmpty>(_json, "groupings", pod.groupings); + addParam<>(_json, QStringLiteral("search_term"), pod.searchTerm); + addParam<IfNotEmpty>(_json, QStringLiteral("keys"), pod.keys); + addParam<IfNotEmpty>(_json, QStringLiteral("filter"), pod.filter); + addParam<IfNotEmpty>(_json, QStringLiteral("order_by"), pod.orderBy); + addParam<IfNotEmpty>(_json, QStringLiteral("event_context"), pod.eventContext); + addParam<IfNotEmpty>(_json, QStringLiteral("include_state"), pod.includeState); + addParam<IfNotEmpty>(_json, QStringLiteral("groupings"), pod.groupings); return _json; } QJsonObject toJson(const SearchJob::Categories& pod) { QJsonObject _json; - addParam<IfNotEmpty>(_json, "room_events", pod.roomEvents); + addParam<IfNotEmpty>(_json, QStringLiteral("room_events"), pod.roomEvents); return _json; } @@ -66,9 +66,9 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::UserProfile result; result.displayname = - fromJson<QString>(_json.value("displayname")); + fromJson<QString>(_json.value("displayname"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url")); + fromJson<QString>(_json.value("avatar_url"_ls)); return result; } @@ -81,15 +81,15 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::EventContext result; result.begin = - fromJson<QString>(_json.value("start")); + fromJson<QString>(_json.value("start"_ls)); result.end = - fromJson<QString>(_json.value("end")); + fromJson<QString>(_json.value("end"_ls)); result.profileInfo = - fromJson<QHash<QString, SearchJob::UserProfile>>(_json.value("profile_info")); + fromJson<QHash<QString, SearchJob::UserProfile>>(_json.value("profile_info"_ls)); result.eventsBefore = - fromJson<RoomEvents>(_json.value("events_before")); + fromJson<RoomEvents>(_json.value("events_before"_ls)); result.eventsAfter = - fromJson<RoomEvents>(_json.value("events_after")); + fromJson<RoomEvents>(_json.value("events_after"_ls)); return result; } @@ -102,11 +102,11 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::Result result; result.rank = - fromJson<double>(_json.value("rank")); + fromJson<double>(_json.value("rank"_ls)); result.result = - fromJson<RoomEventPtr>(_json.value("result")); + fromJson<RoomEventPtr>(_json.value("result"_ls)); result.context = - fromJson<SearchJob::EventContext>(_json.value("context")); + fromJson<SearchJob::EventContext>(_json.value("context"_ls)); return result; } @@ -119,11 +119,11 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::GroupValue result; result.nextBatch = - fromJson<QString>(_json.value("next_batch")); + fromJson<QString>(_json.value("next_batch"_ls)); result.order = - fromJson<int>(_json.value("order")); + fromJson<int>(_json.value("order"_ls)); result.results = - fromJson<QStringList>(_json.value("results")); + fromJson<QStringList>(_json.value("results"_ls)); return result; } @@ -136,15 +136,15 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::ResultRoomEvents result; result.count = - fromJson<qint64>(_json.value("count")); + fromJson<qint64>(_json.value("count"_ls)); result.results = - fromJson<std::vector<SearchJob::Result>>(_json.value("results")); + fromJson<std::vector<SearchJob::Result>>(_json.value("results"_ls)); result.state = - fromJson<std::unordered_map<QString, StateEvents>>(_json.value("state")); + fromJson<std::unordered_map<QString, StateEvents>>(_json.value("state"_ls)); result.groups = - fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(_json.value("groups")); + fromJson<QHash<QString, QHash<QString, SearchJob::GroupValue>>>(_json.value("groups"_ls)); result.nextBatch = - fromJson<QString>(_json.value("next_batch")); + fromJson<QString>(_json.value("next_batch"_ls)); return result; } @@ -157,7 +157,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchJob::ResultCategories result; result.roomEvents = - fromJson<SearchJob::ResultRoomEvents>(_json.value("room_events")); + fromJson<SearchJob::ResultRoomEvents>(_json.value("room_events"_ls)); return result; } @@ -173,18 +173,20 @@ class SearchJob::Private BaseJob::Query queryToSearch(const QString& nextBatch) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "next_batch", nextBatch); + addParam<IfNotEmpty>(_q, QStringLiteral("next_batch"), nextBatch); return _q; } +static const auto SearchJobName = QStringLiteral("SearchJob"); + SearchJob::SearchJob(const Categories& searchCategories, const QString& nextBatch) - : BaseJob(HttpVerb::Post, "SearchJob", + : BaseJob(HttpVerb::Post, SearchJobName, basePath % "/search", queryToSearch(nextBatch)) , d(new Private) { QJsonObject _data; - addParam<>(_data, "search_categories", searchCategories); + addParam<>(_data, QStringLiteral("search_categories"), searchCategories); setRequestData(_data); } @@ -198,10 +200,10 @@ const SearchJob::ResultCategories& SearchJob::searchCategories() const BaseJob::Status SearchJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("search_categories")) + if (!json.contains("search_categories"_ls)) return { JsonParseError, "The key 'search_categories' not found in the response" }; - d->searchCategories = fromJson<ResultCategories>(json.value("search_categories")); + d->searchCategories = fromJson<ResultCategories>(json.value("search_categories"_ls)); return Success; } diff --git a/lib/csapi/search.h b/lib/csapi/search.h index 206bacca..572ea6af 100644 --- a/lib/csapi/search.h +++ b/lib/csapi/search.h @@ -6,12 +6,12 @@ #include "jobs/basejob.h" -#include <unordered_map> -#include <QtCore/QHash> #include <QtCore/QJsonObject> -#include "events/event.h" #include "converters.h" #include <QtCore/QVector> +#include <unordered_map> +#include <QtCore/QHash> +#include "events/eventloader.h" namespace QMatrixClient { diff --git a/lib/csapi/tags.cpp b/lib/csapi/tags.cpp index 9cd78aec..1afc3bfc 100644 --- a/lib/csapi/tags.cpp +++ b/lib/csapi/tags.cpp @@ -24,8 +24,10 @@ QUrl GetRoomTagsJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const Q basePath % "/user/" % userId % "/rooms/" % roomId % "/tags"); } +static const auto GetRoomTagsJobName = QStringLiteral("GetRoomTagsJob"); + GetRoomTagsJob::GetRoomTagsJob(const QString& userId, const QString& roomId) - : BaseJob(HttpVerb::Get, "GetRoomTagsJob", + : BaseJob(HttpVerb::Get, GetRoomTagsJobName, basePath % "/user/" % userId % "/rooms/" % roomId % "/tags") , d(new Private) { @@ -41,12 +43,14 @@ const QJsonObject& GetRoomTagsJob::tags() const BaseJob::Status GetRoomTagsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->tags = fromJson<QJsonObject>(json.value("tags")); + d->tags = fromJson<QJsonObject>(json.value("tags"_ls)); return Success; } +static const auto SetRoomTagJobName = QStringLiteral("SetRoomTagJob"); + SetRoomTagJob::SetRoomTagJob(const QString& userId, const QString& roomId, const QString& tag, const QJsonObject& body) - : BaseJob(HttpVerb::Put, "SetRoomTagJob", + : BaseJob(HttpVerb::Put, SetRoomTagJobName, basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag) { setRequestData(Data(toJson(body))); @@ -58,8 +62,10 @@ QUrl DeleteRoomTagJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag); } +static const auto DeleteRoomTagJobName = QStringLiteral("DeleteRoomTagJob"); + DeleteRoomTagJob::DeleteRoomTagJob(const QString& userId, const QString& roomId, const QString& tag) - : BaseJob(HttpVerb::Delete, "DeleteRoomTagJob", + : BaseJob(HttpVerb::Delete, DeleteRoomTagJobName, basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag) { } diff --git a/lib/csapi/third_party_membership.cpp b/lib/csapi/third_party_membership.cpp index 2372f9d7..c1683338 100644 --- a/lib/csapi/third_party_membership.cpp +++ b/lib/csapi/third_party_membership.cpp @@ -12,14 +12,16 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto InviteBy3PIDJobName = QStringLiteral("InviteBy3PIDJob"); + InviteBy3PIDJob::InviteBy3PIDJob(const QString& roomId, const QString& idServer, const QString& medium, const QString& address) - : BaseJob(HttpVerb::Post, "InviteBy3PIDJob", + : BaseJob(HttpVerb::Post, InviteBy3PIDJobName, basePath % "/rooms/" % roomId % "/invite") { QJsonObject _data; - addParam<>(_data, "id_server", idServer); - addParam<>(_data, "medium", medium); - addParam<>(_data, "address", address); + addParam<>(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("medium"), medium); + addParam<>(_data, QStringLiteral("address"), address); setRequestData(_data); } diff --git a/lib/csapi/to_device.cpp b/lib/csapi/to_device.cpp index 1478a679..7c7f495a 100644 --- a/lib/csapi/to_device.cpp +++ b/lib/csapi/to_device.cpp @@ -12,12 +12,14 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto SendToDeviceJobName = QStringLiteral("SendToDeviceJob"); + SendToDeviceJob::SendToDeviceJob(const QString& eventType, const QString& txnId, const QHash<QString, QHash<QString, QJsonObject>>& messages) - : BaseJob(HttpVerb::Put, "SendToDeviceJob", + : BaseJob(HttpVerb::Put, SendToDeviceJobName, basePath % "/sendToDevice/" % eventType % "/" % txnId) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "messages", messages); + addParam<IfNotEmpty>(_data, QStringLiteral("messages"), messages); setRequestData(_data); } diff --git a/lib/csapi/typing.cpp b/lib/csapi/typing.cpp index 6db522c4..bf10912b 100644 --- a/lib/csapi/typing.cpp +++ b/lib/csapi/typing.cpp @@ -12,13 +12,15 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +static const auto SetTypingJobName = QStringLiteral("SetTypingJob"); + SetTypingJob::SetTypingJob(const QString& userId, const QString& roomId, bool typing, Omittable<int> timeout) - : BaseJob(HttpVerb::Put, "SetTypingJob", + : BaseJob(HttpVerb::Put, SetTypingJobName, basePath % "/rooms/" % roomId % "/typing/" % userId) { QJsonObject _data; - addParam<>(_data, "typing", typing); - addParam<IfNotEmpty>(_data, "timeout", timeout); + addParam<>(_data, QStringLiteral("typing"), typing); + addParam<IfNotEmpty>(_data, QStringLiteral("timeout"), timeout); setRequestData(_data); } diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp index e7f68bda..408a8cad 100644 --- a/lib/csapi/users.cpp +++ b/lib/csapi/users.cpp @@ -23,11 +23,11 @@ namespace QMatrixClient const auto& _json = jv.toObject(); SearchUserDirectoryJob::User result; result.userId = - fromJson<QString>(_json.value("user_id")); + fromJson<QString>(_json.value("user_id"_ls)); result.displayName = - fromJson<QString>(_json.value("display_name")); + fromJson<QString>(_json.value("display_name"_ls)); result.avatarUrl = - fromJson<QString>(_json.value("avatar_url")); + fromJson<QString>(_json.value("avatar_url"_ls)); return result; } @@ -41,14 +41,16 @@ class SearchUserDirectoryJob::Private bool limited; }; +static const auto SearchUserDirectoryJobName = QStringLiteral("SearchUserDirectoryJob"); + SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, Omittable<int> limit) - : BaseJob(HttpVerb::Post, "SearchUserDirectoryJob", + : BaseJob(HttpVerb::Post, SearchUserDirectoryJobName, basePath % "/user_directory/search") , d(new Private) { QJsonObject _data; - addParam<>(_data, "search_term", searchTerm); - addParam<IfNotEmpty>(_data, "limit", limit); + addParam<>(_data, QStringLiteral("search_term"), searchTerm); + addParam<IfNotEmpty>(_data, QStringLiteral("limit"), limit); setRequestData(_data); } @@ -67,14 +69,14 @@ bool SearchUserDirectoryJob::limited() const BaseJob::Status SearchUserDirectoryJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("results")) + if (!json.contains("results"_ls)) return { JsonParseError, "The key 'results' not found in the response" }; - d->results = fromJson<QVector<User>>(json.value("results")); - if (!json.contains("limited")) + d->results = fromJson<QVector<User>>(json.value("results"_ls)); + if (!json.contains("limited"_ls)) return { JsonParseError, "The key 'limited' not found in the response" }; - d->limited = fromJson<bool>(json.value("limited")); + d->limited = fromJson<bool>(json.value("limited"_ls)); return Success; } diff --git a/lib/csapi/versions.cpp b/lib/csapi/versions.cpp index 7b55b94f..128902e2 100644 --- a/lib/csapi/versions.cpp +++ b/lib/csapi/versions.cpp @@ -24,8 +24,10 @@ QUrl GetVersionsJob::makeRequestUrl(QUrl baseUrl) basePath % "/versions"); } +static const auto GetVersionsJobName = QStringLiteral("GetVersionsJob"); + GetVersionsJob::GetVersionsJob() - : BaseJob(HttpVerb::Get, "GetVersionsJob", + : BaseJob(HttpVerb::Get, GetVersionsJobName, basePath % "/versions", false) , d(new Private) { @@ -41,7 +43,7 @@ const QStringList& GetVersionsJob::versions() const BaseJob::Status GetVersionsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->versions = fromJson<QStringList>(json.value("versions")); + d->versions = fromJson<QStringList>(json.value("versions"_ls)); return Success; } diff --git a/lib/csapi/voip.cpp b/lib/csapi/voip.cpp index f84c140d..8ecf92c6 100644 --- a/lib/csapi/voip.cpp +++ b/lib/csapi/voip.cpp @@ -24,8 +24,10 @@ QUrl GetTurnServerJob::makeRequestUrl(QUrl baseUrl) basePath % "/voip/turnServer"); } +static const auto GetTurnServerJobName = QStringLiteral("GetTurnServerJob"); + GetTurnServerJob::GetTurnServerJob() - : BaseJob(HttpVerb::Get, "GetTurnServerJob", + : BaseJob(HttpVerb::Get, GetTurnServerJobName, basePath % "/voip/turnServer") , d(new Private) { @@ -41,10 +43,10 @@ const QJsonObject& GetTurnServerJob::data() const BaseJob::Status GetTurnServerJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("data")) + if (!json.contains("data"_ls)) return { JsonParseError, "The key 'data' not found in the response" }; - d->data = fromJson<QJsonObject>(json.value("data")); + d->data = fromJson<QJsonObject>(json.value("data"_ls)); return Success; } diff --git a/lib/csapi/whoami.cpp b/lib/csapi/whoami.cpp index 4c231b5f..cb6439ef 100644 --- a/lib/csapi/whoami.cpp +++ b/lib/csapi/whoami.cpp @@ -24,8 +24,10 @@ QUrl GetTokenOwnerJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/whoami"); } +static const auto GetTokenOwnerJobName = QStringLiteral("GetTokenOwnerJob"); + GetTokenOwnerJob::GetTokenOwnerJob() - : BaseJob(HttpVerb::Get, "GetTokenOwnerJob", + : BaseJob(HttpVerb::Get, GetTokenOwnerJobName, basePath % "/account/whoami") , d(new Private) { @@ -41,10 +43,10 @@ const QString& GetTokenOwnerJob::userId() const BaseJob::Status GetTokenOwnerJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("user_id")) + if (!json.contains("user_id"_ls)) return { JsonParseError, "The key 'user_id' not found in the response" }; - d->userId = fromJson<QString>(json.value("user_id")); + d->userId = fromJson<QString>(json.value("user_id"_ls)); return Success; } diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache index 8b5acd65..d25997ed 100644 --- a/lib/csapi/{{base}}.cpp.mustache +++ b/lib/csapi/{{base}}.cpp.mustache @@ -11,7 +11,7 @@ using namespace QMatrixClient; QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod) { QJsonObject _json;{{#vars}} - addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}} return _json; } {{/in?}}{{#out?}} @@ -20,7 +20,7 @@ QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod) const auto& _json = jv.toObject(); {{qualifiedName}} result; {{#vars}}result.{{nameCamelCase}} = - fromJson<{{dataType.name}}>(_json.value("{{baseName}}")); + fromJson<{{dataType.name}}>(_json.value("{{baseName}}"_ls)); {{/vars}} return result; } @@ -34,7 +34,7 @@ namespace QMatrixClient QJsonObject toJson(const {{qualifiedName}}& pod) { QJsonObject _json;{{#vars}} - addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, "{{baseName}}", pod.{{nameCamelCase}});{{/vars}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}} return _json; } {{/in?}}{{#out?}} @@ -45,7 +45,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); {{qualifiedName}} result; {{#vars}} result.{{nameCamelCase}} = - fromJson<{{dataType.qualifiedName}}>(_json.value("{{baseName}}")); + fromJson<{{dataType.qualifiedName}}>(_json.value("{{baseName}}"_ls)); {{/vars}} return result; } @@ -61,7 +61,7 @@ class {{camelCaseOperationId}}Job::Private BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}}) { BaseJob::Query _q;{{#queryParams}} - addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, "{{baseName}}", {{paramName}});{{/queryParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, QStringLiteral("{{baseName}}"), {{paramName}});{{/queryParams}} return _q; } {{/queryParams?}}{{^bodyParams}} @@ -72,8 +72,10 @@ QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{ queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}); } {{/ bodyParams}} +static const auto {{camelCaseOperationId}}JobName = QStringLiteral("{{camelCaseOperationId}}Job"); + {{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}}) - : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, {{camelCaseOperationId}}JobName, basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}}, queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}{{#skipAuth}}{{#queryParams?}}, {}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}} @@ -87,7 +89,7 @@ QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{ }}{{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson? }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));{{/inlineBody }}{{^inlineBody}} QJsonObject _data;{{#bodyParams}} - addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, "{{baseName}}", {{paramName}});{{/bodyParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, QStringLiteral("{{baseName}}"), {{paramName}});{{/bodyParams}} setRequestData(_data);{{/inlineBody}} {{/bodyParams?}}{{#producesNonJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{>cjoin}}{{/produces}} }); {{/producesNonJson?}}}{{!<- mind the actual brace}} @@ -108,10 +110,10 @@ BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply) BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) { auto json = data.object(); - {{# properties}}{{#required?}}if (!json.contains("{{baseName}}")) + {{# properties}}{{#required?}}if (!json.contains("{{baseName}}"_ls)) return { JsonParseError, "The key '{{baseName}}' not found in the response" }; - {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}")); + {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"_ls)); {{/ properties}}return Success; }{{/ producesNonJson?}} {{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} |