diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 20 | ||||
-rw-r--r-- | lib/connection.h | 10 | ||||
-rw-r--r-- | lib/converters.h | 70 | ||||
-rw-r--r-- | lib/csapi/account-data.cpp (renamed from lib/jobs/generated/account-data.cpp) | 4 | ||||
-rw-r--r-- | lib/csapi/account-data.h (renamed from lib/jobs/generated/account-data.h) | 2 | ||||
-rw-r--r-- | lib/csapi/admin.cpp | 100 | ||||
-rw-r--r-- | lib/csapi/admin.h | 65 | ||||
-rw-r--r-- | lib/csapi/administrative_contact.cpp (renamed from lib/jobs/generated/administrative_contact.cpp) | 46 | ||||
-rw-r--r-- | lib/csapi/administrative_contact.h (renamed from lib/jobs/generated/administrative_contact.h) | 18 | ||||
-rw-r--r-- | lib/csapi/banning.cpp (renamed from lib/jobs/generated/banning.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/banning.h (renamed from lib/jobs/generated/banning.h) | 2 | ||||
-rw-r--r-- | lib/csapi/content-repo.cpp (renamed from lib/jobs/generated/content-repo.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/content-repo.h (renamed from lib/jobs/generated/content-repo.h) | 24 | ||||
-rw-r--r-- | lib/csapi/create_room.cpp | 82 | ||||
-rw-r--r-- | lib/csapi/create_room.h (renamed from lib/jobs/generated/create_room.h) | 15 | ||||
-rw-r--r-- | lib/csapi/directory.cpp (renamed from lib/jobs/generated/directory.cpp) | 6 | ||||
-rw-r--r-- | lib/csapi/directory.h (renamed from lib/jobs/generated/directory.h) | 14 | ||||
-rw-r--r-- | lib/csapi/event_context.cpp | 91 | ||||
-rw-r--r-- | lib/csapi/event_context.h | 46 | ||||
-rw-r--r-- | lib/csapi/gtad.yaml | 139 | ||||
-rw-r--r-- | lib/csapi/inviting.cpp (renamed from lib/jobs/generated/inviting.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/inviting.h (renamed from lib/jobs/generated/inviting.h) | 2 | ||||
-rw-r--r-- | lib/csapi/joining.cpp | 118 | ||||
-rw-r--r-- | lib/csapi/joining.h | 81 | ||||
-rw-r--r-- | lib/csapi/kicking.cpp (renamed from lib/jobs/generated/kicking.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/kicking.h (renamed from lib/jobs/generated/kicking.h) | 2 | ||||
-rw-r--r-- | lib/csapi/leaving.cpp (renamed from lib/jobs/generated/leaving.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/leaving.h (renamed from lib/jobs/generated/leaving.h) | 8 | ||||
-rw-r--r-- | lib/csapi/list_joined_rooms.cpp | 50 | ||||
-rw-r--r-- | lib/csapi/list_joined_rooms.h | 41 | ||||
-rw-r--r-- | lib/csapi/list_public_rooms.cpp (renamed from lib/jobs/generated/list_public_rooms.cpp) | 134 | ||||
-rw-r--r-- | lib/csapi/list_public_rooms.h (renamed from lib/jobs/generated/list_public_rooms.h) | 68 | ||||
-rw-r--r-- | lib/csapi/login.cpp (renamed from lib/jobs/generated/login.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/login.h (renamed from lib/jobs/generated/login.h) | 4 | ||||
-rw-r--r-- | lib/csapi/logout.cpp (renamed from lib/jobs/generated/logout.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/logout.h (renamed from lib/jobs/generated/logout.h) | 5 | ||||
-rw-r--r-- | lib/csapi/message_pagination.cpp | 76 | ||||
-rw-r--r-- | lib/csapi/message_pagination.h | 43 | ||||
-rw-r--r-- | lib/csapi/notifications.cpp (renamed from lib/jobs/generated/notifications.cpp) | 8 | ||||
-rw-r--r-- | lib/csapi/notifications.h (renamed from lib/jobs/generated/notifications.h) | 13 | ||||
-rw-r--r-- | lib/csapi/preamble.mustache | 3 | ||||
-rw-r--r-- | lib/csapi/profile.cpp (renamed from lib/jobs/generated/profile.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/profile.h (renamed from lib/jobs/generated/profile.h) | 17 | ||||
-rw-r--r-- | lib/csapi/pusher.cpp | 121 | ||||
-rw-r--r-- | lib/csapi/pusher.h | 78 | ||||
-rw-r--r-- | lib/csapi/receipts.cpp (renamed from lib/jobs/generated/receipts.cpp) | 2 | ||||
-rw-r--r-- | lib/csapi/receipts.h (renamed from lib/jobs/generated/receipts.h) | 2 | ||||
-rw-r--r-- | lib/csapi/redaction.cpp (renamed from lib/jobs/generated/redaction.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/redaction.h (renamed from lib/jobs/generated/redaction.h) | 4 | ||||
-rw-r--r-- | lib/csapi/room_send.cpp | 42 | ||||
-rw-r--r-- | lib/csapi/room_send.h | 33 | ||||
-rw-r--r-- | lib/csapi/room_state.cpp | 70 | ||||
-rw-r--r-- | lib/csapi/room_state.h | 51 | ||||
-rw-r--r-- | lib/csapi/tags.cpp | 66 | ||||
-rw-r--r-- | lib/csapi/tags.h | 61 | ||||
-rw-r--r-- | lib/csapi/third_party_membership.cpp (renamed from lib/jobs/generated/third_party_membership.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/third_party_membership.h (renamed from lib/jobs/generated/third_party_membership.h) | 2 | ||||
-rw-r--r-- | lib/csapi/to_device.cpp | 23 | ||||
-rw-r--r-- | lib/csapi/to_device.h | 22 | ||||
-rw-r--r-- | lib/csapi/typing.cpp (renamed from lib/jobs/generated/typing.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/typing.h (renamed from lib/jobs/generated/typing.h) | 2 | ||||
-rw-r--r-- | lib/csapi/users.cpp | 78 | ||||
-rw-r--r-- | lib/csapi/users.h | 46 | ||||
-rw-r--r-- | lib/csapi/versions.cpp (renamed from lib/jobs/generated/versions.cpp) | 6 | ||||
-rw-r--r-- | lib/csapi/versions.h (renamed from lib/jobs/generated/versions.h) | 11 | ||||
-rw-r--r-- | lib/csapi/whoami.cpp (renamed from lib/jobs/generated/whoami.cpp) | 0 | ||||
-rw-r--r-- | lib/csapi/whoami.h (renamed from lib/jobs/generated/whoami.h) | 7 | ||||
-rw-r--r-- | lib/csapi/{{base}}.cpp.mustache | 121 | ||||
-rw-r--r-- | lib/csapi/{{base}}.h.mustache | 63 | ||||
-rw-r--r-- | lib/events/accountdataevents.h | 3 | ||||
-rw-r--r-- | lib/events/directchatevent.h | 2 | ||||
-rw-r--r-- | lib/events/event.cpp | 25 | ||||
-rw-r--r-- | lib/events/event.h | 86 | ||||
-rw-r--r-- | lib/events/receiptevent.cpp | 2 | ||||
-rw-r--r-- | lib/events/receiptevent.h | 2 | ||||
-rw-r--r-- | lib/events/redactionevent.h | 2 | ||||
-rw-r--r-- | lib/events/roomavatarevent.h | 2 | ||||
-rw-r--r-- | lib/events/roommemberevent.h | 9 | ||||
-rw-r--r-- | lib/events/roommessageevent.h | 2 | ||||
-rw-r--r-- | lib/events/simplestateevents.h | 2 | ||||
-rw-r--r-- | lib/events/typingevent.h | 2 | ||||
-rw-r--r-- | lib/jobs/basejob.cpp | 1 | ||||
-rw-r--r-- | lib/jobs/downloadfilejob.h | 2 | ||||
-rw-r--r-- | lib/jobs/generated/create_room.cpp | 115 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.cpp | 58 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.h | 40 | ||||
-rw-r--r-- | lib/jobs/mediathumbnailjob.h | 2 | ||||
-rw-r--r-- | lib/jobs/roommessagesjob.cpp | 65 | ||||
-rw-r--r-- | lib/jobs/roommessagesjob.h | 47 | ||||
-rw-r--r-- | lib/jobs/sendeventjob.h | 2 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.cpp | 32 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.h | 64 | ||||
-rw-r--r-- | lib/jobs/syncjob.cpp | 43 | ||||
-rw-r--r-- | lib/jobs/syncjob.h | 27 | ||||
-rw-r--r-- | lib/room.cpp | 259 | ||||
-rw-r--r-- | lib/room.h | 15 | ||||
-rw-r--r-- | lib/user.cpp | 32 | ||||
-rw-r--r-- | lib/user.h | 3 | ||||
-rw-r--r-- | lib/util.h | 31 |
99 files changed, 2393 insertions, 922 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index adeb7929..24bf1af9 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -23,14 +23,13 @@ #include "events/directchatevent.h" #include "room.h" #include "settings.h" -#include "jobs/generated/login.h" -#include "jobs/generated/logout.h" -#include "jobs/generated/receipts.h" -#include "jobs/generated/leaving.h" -#include "jobs/generated/account-data.h" +#include "csapi/login.h" +#include "csapi/logout.h" +#include "csapi/receipts.h" +#include "csapi/leaving.h" +#include "csapi/account-data.h" +#include "csapi/joining.h" #include "jobs/sendeventjob.h" -#include "jobs/joinroomjob.h" -#include "jobs/roommessagesjob.h" #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" @@ -372,11 +371,6 @@ void Connection::leaveRoom(Room* room) callApi<LeaveRoomJob>(room->id()); } -RoomMessagesJob* Connection::getMessages(Room* room, const QString& from) const -{ - return callApi<RoomMessagesJob>(room->id(), from); -} - inline auto splitMediaId(const QString& mediaId) { auto idParts = mediaId.split('/'); @@ -447,7 +441,7 @@ DownloadFileJob* Connection::downloadFile(const QUrl& url, CreateRoomJob* Connection::createRoom(RoomVisibility visibility, const QString& alias, const QString& name, const QString& topic, - const QVector<QString>& invites, const QString& presetName, + const QStringList& invites, const QString& presetName, bool isDirect, bool guestsCanJoin, const QVector<CreateRoomJob::StateEvent>& initialState, const QVector<CreateRoomJob::Invite3pid>& invite3pids, diff --git a/lib/connection.h b/lib/connection.h index 839371ef..6dd0db1d 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -18,7 +18,7 @@ #pragma once -#include "jobs/generated/create_room.h" +#include "csapi/create_room.h" #include "joinstate.h" #include <QtCore/QObject> @@ -272,8 +272,8 @@ namespace QMatrixClient */ CreateRoomJob* createRoom(RoomVisibility visibility, const QString& alias, const QString& name, const QString& topic, - const QVector<QString>& invites, const QString& presetName = {}, bool isDirect = false, - bool guestsCanJoin = false, + const QStringList& invites, const QString& presetName = {}, + bool isDirect = false, bool guestsCanJoin = false, const QVector<CreateRoomJob::StateEvent>& initialState = {}, const QVector<CreateRoomJob::Invite3pid>& invite3pids = {}, const QJsonObject& creationContent = {}); @@ -331,9 +331,7 @@ namespace QMatrixClient RoomEvent* event) const; /** @deprecated Use callApi<LeaveRoomJob>() or Room::leaveRoom() instead */ virtual void leaveRoom( Room* room ); - /** @deprecated User callApi<RoomMessagesJob>() or Room::getPreviousContent() instead */ - virtual RoomMessagesJob* getMessages(Room* room, - const QString& from) const; + signals: /** * @deprecated diff --git a/lib/converters.h b/lib/converters.h index cfe9c01c..68005c0d 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -23,6 +23,20 @@ #include <QtCore/QDate> #include <QtCore/QVariant> +#include <unordered_map> + +// Enable std::unordered_map<QString, T> +namespace std +{ + template <> struct hash<QString> + { + size_t operator()(const QString& s) const Q_DECL_NOEXCEPT + { + return qHash(s, uint(qGlobalQHashSeed())); + } + }; +} + namespace QMatrixClient { // This catches anything implicitly convertible to QJsonValue/Object/Array @@ -83,6 +97,15 @@ namespace QMatrixClient } template <typename T> + inline QJsonObject toJson(const std::unordered_map<QString, T>& hashMap) + { + QJsonObject json; + for (auto it = hashMap.begin(); it != hashMap.end(); ++it) + json.insert(it.key(), toJson(it.value())); + return json; + } + + template <typename T> struct FromJson { T operator()(const QJsonValue& jv) const { return static_cast<T>(jv); } @@ -96,32 +119,32 @@ namespace QMatrixClient template <> struct FromJson<bool> { - bool operator()(const QJsonValue& jv) const { return jv.toBool(); } + auto operator()(const QJsonValue& jv) const { return jv.toBool(); } }; template <> struct FromJson<int> { - int operator()(const QJsonValue& jv) const { return jv.toInt(); } + auto operator()(const QJsonValue& jv) const { return jv.toInt(); } }; template <> struct FromJson<double> { - double operator()(const QJsonValue& jv) const { return jv.toDouble(); } + auto operator()(const QJsonValue& jv) const { return jv.toDouble(); } }; template <> struct FromJson<qint64> { - qint64 operator()(const QJsonValue& jv) const { return qint64(jv.toDouble()); } + auto operator()(const QJsonValue& jv) const { return qint64(jv.toDouble()); } }; template <> struct FromJson<QString> { - QString operator()(const QJsonValue& jv) const { return jv.toString(); } + auto operator()(const QJsonValue& jv) const { return jv.toString(); } }; template <> struct FromJson<QDateTime> { - QDateTime operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return QDateTime::fromMSecsSinceEpoch(fromJson<qint64>(jv), Qt::UTC); } @@ -129,7 +152,7 @@ namespace QMatrixClient template <> struct FromJson<QDate> { - QDate operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return fromJson<QDateTime>(jv).date(); } @@ -137,7 +160,7 @@ namespace QMatrixClient template <> struct FromJson<QJsonObject> { - QJsonObject operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return jv.toObject(); } @@ -145,7 +168,7 @@ namespace QMatrixClient template <> struct FromJson<QJsonArray> { - QJsonArray operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return jv.toArray(); } @@ -153,10 +176,11 @@ namespace QMatrixClient template <typename T> struct FromJson<std::vector<T>> { - std::vector<T> operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { + using size_type = typename std::vector<T>::size_type; const auto jsonArray = jv.toArray(); - std::vector<T> vect; vect.resize(size_t(jsonArray.size())); + std::vector<T> vect; vect.resize(size_type(jsonArray.size())); std::transform(jsonArray.begin(), jsonArray.end(), vect.begin(), FromJson<T>()); return vect; @@ -165,7 +189,7 @@ namespace QMatrixClient template <typename T> struct FromJson<QVector<T>> { - QVector<T> operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { const auto jsonArray = jv.toArray(); QVector<T> vect; vect.resize(jsonArray.size()); @@ -177,7 +201,7 @@ namespace QMatrixClient template <typename T> struct FromJson<QList<T>> { - QList<T> operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { const auto jsonArray = jv.toArray(); QList<T> sl; sl.reserve(jsonArray.size()); @@ -191,7 +215,7 @@ namespace QMatrixClient template <> struct FromJson<QByteArray> { - inline QByteArray operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return fromJson<QString>(jv).toLatin1(); } @@ -199,7 +223,7 @@ namespace QMatrixClient template <> struct FromJson<QVariantMap> { - inline auto operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return jv.toObject().toVariantMap(); } @@ -208,7 +232,7 @@ namespace QMatrixClient #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) template <> struct FromJson<QVariantHash> { - inline auto operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { return jv.toObject().toVariantHash(); } @@ -217,7 +241,7 @@ namespace QMatrixClient template <typename T> struct FromJson<QHash<QString, T>> { - QHash<QString, T> operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { const auto json = jv.toObject(); QHash<QString, T> h; h.reserve(json.size()); @@ -226,4 +250,16 @@ namespace QMatrixClient return h; } }; + + template <typename T> struct FromJson<std::unordered_map<QString, T>> + { + auto operator()(const QJsonValue& jv) const + { + const auto json = jv.toObject(); + std::unordered_map<QString, T> h; h.reserve(size_t(json.size())); + for (auto it = json.begin(); it != json.end(); ++it) + h.insert(std::make_pair(it.key(), fromJson<T>(it.value()))); + return h; + } + }; } // namespace QMatrixClient diff --git a/lib/jobs/generated/account-data.cpp b/lib/csapi/account-data.cpp index 35ee94c0..ac45cb85 100644 --- a/lib/jobs/generated/account-data.cpp +++ b/lib/csapi/account-data.cpp @@ -16,13 +16,13 @@ SetAccountDataJob::SetAccountDataJob(const QString& userId, const QString& type, : BaseJob(HttpVerb::Put, "SetAccountDataJob", basePath % "/user/" % userId % "/account_data/" % type) { - setRequestData(Data(content)); + setRequestData(Data(toJson(content))); } SetAccountDataPerRoomJob::SetAccountDataPerRoomJob(const QString& userId, const QString& roomId, const QString& type, const QJsonObject& content) : BaseJob(HttpVerb::Put, "SetAccountDataPerRoomJob", basePath % "/user/" % userId % "/rooms/" % roomId % "/account_data/" % type) { - setRequestData(Data(content)); + setRequestData(Data(toJson(content))); } diff --git a/lib/jobs/generated/account-data.h b/lib/csapi/account-data.h index 69ad9fb4..784b8b4b 100644 --- a/lib/jobs/generated/account-data.h +++ b/lib/csapi/account-data.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" #include <QtCore/QJsonObject> diff --git a/lib/csapi/admin.cpp b/lib/csapi/admin.cpp new file mode 100644 index 00000000..b325d746 --- /dev/null +++ b/lib/csapi/admin.cpp @@ -0,0 +1,100 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "admin.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<GetWhoIsJob::ConnectionInfo> + { + GetWhoIsJob::ConnectionInfo operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetWhoIsJob::ConnectionInfo result; + result.ip = + fromJson<QString>(o.value("ip")); + result.lastSeen = + fromJson<qint64>(o.value("last_seen")); + result.userAgent = + fromJson<QString>(o.value("user_agent")); + + return result; + } + }; + + template <> struct FromJson<GetWhoIsJob::SessionInfo> + { + GetWhoIsJob::SessionInfo operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetWhoIsJob::SessionInfo result; + result.connections = + fromJson<QVector<GetWhoIsJob::ConnectionInfo>>(o.value("connections")); + + return result; + } + }; + + template <> struct FromJson<GetWhoIsJob::DeviceInfo> + { + GetWhoIsJob::DeviceInfo operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetWhoIsJob::DeviceInfo result; + result.sessions = + fromJson<QVector<GetWhoIsJob::SessionInfo>>(o.value("sessions")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetWhoIsJob::Private +{ + public: + QString userId; + QHash<QString, DeviceInfo> devices; +}; + +QUrl GetWhoIsJob::makeRequestUrl(QUrl baseUrl, const QString& userId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/admin/whois/" % userId); +} + +GetWhoIsJob::GetWhoIsJob(const QString& userId) + : BaseJob(HttpVerb::Get, "GetWhoIsJob", + basePath % "/admin/whois/" % userId) + , d(new Private) +{ +} + +GetWhoIsJob::~GetWhoIsJob() = default; + +const QString& GetWhoIsJob::userId() const +{ + return d->userId; +} + +const QHash<QString, GetWhoIsJob::DeviceInfo>& GetWhoIsJob::devices() const +{ + return d->devices; +} + +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")); + return Success; +} + diff --git a/lib/csapi/admin.h b/lib/csapi/admin.h new file mode 100644 index 00000000..ada5a8ca --- /dev/null +++ b/lib/csapi/admin.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QHash> +#include <QtCore/QVector> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class GetWhoIsJob : public BaseJob + { + public: + // Inner data structures + + struct ConnectionInfo + { + QString ip; + qint64 lastSeen; + QString userAgent; + }; + + struct SessionInfo + { + QVector<ConnectionInfo> connections; + }; + + struct DeviceInfo + { + QVector<SessionInfo> sessions; + }; + + // Construction/destruction + + explicit GetWhoIsJob(const QString& userId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetWhoIsJob. This function can be used when + * a URL for GetWhoIsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); + + ~GetWhoIsJob() override; + + // Result properties + + const QString& userId() const; + const QHash<QString, DeviceInfo>& devices() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/administrative_contact.cpp b/lib/csapi/administrative_contact.cpp index bd74490c..ec7c77c3 100644 --- a/lib/jobs/generated/administrative_contact.cpp +++ b/lib/csapi/administrative_contact.cpp @@ -10,16 +10,10 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); -GetAccount3PIDsJob::ThirdPartyIdentifier::operator QJsonObject() const -{ - QJsonObject o; - o.insert("medium", toJson(medium)); - o.insert("address", toJson(address)); - - return o; -} namespace QMatrixClient { + // Converters + template <> struct FromJson<GetAccount3PIDsJob::ThirdPartyIdentifier> { GetAccount3PIDsJob::ThirdPartyIdentifier operator()(const QJsonValue& jv) @@ -30,7 +24,7 @@ namespace QMatrixClient fromJson<QString>(o.value("medium")); result.address = fromJson<QString>(o.value("address")); - + return result; } }; @@ -69,33 +63,19 @@ BaseJob::Status GetAccount3PIDsJob::parseJson(const QJsonDocument& data) return Success; } -Post3PIDsJob::ThreePidCredentials::operator QJsonObject() const -{ - QJsonObject o; - o.insert("client_secret", toJson(clientSecret)); - o.insert("id_server", toJson(idServer)); - o.insert("sid", toJson(sid)); - - return o; -} namespace QMatrixClient { - template <> struct FromJson<Post3PIDsJob::ThreePidCredentials> + // Converters + + QJsonObject toJson(const Post3PIDsJob::ThreePidCredentials& pod) { - Post3PIDsJob::ThreePidCredentials operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - Post3PIDsJob::ThreePidCredentials result; - result.clientSecret = - fromJson<QString>(o.value("client_secret")); - result.idServer = - fromJson<QString>(o.value("id_server")); - result.sid = - fromJson<QString>(o.value("sid")); - - return result; - } - }; + QJsonObject o; + o.insert("client_secret", toJson(pod.clientSecret)); + o.insert("id_server", toJson(pod.idServer)); + o.insert("sid", toJson(pod.sid)); + + return o; + } } // namespace QMatrixClient Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind) diff --git a/lib/jobs/generated/administrative_contact.h b/lib/csapi/administrative_contact.h index c8429d39..0d1ace3d 100644 --- a/lib/jobs/generated/administrative_contact.h +++ b/lib/csapi/administrative_contact.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" #include <QtCore/QVector> @@ -23,11 +23,11 @@ namespace QMatrixClient { QString medium; QString address; - - operator QJsonObject() const; }; - // End of inner data structures + // Construction/destruction + + explicit GetAccount3PIDsJob(); /** Construct a URL out of baseUrl and usual parameters passed to * GetAccount3PIDsJob. This function can be used when @@ -36,9 +36,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl); - explicit GetAccount3PIDsJob(); ~GetAccount3PIDsJob() override; + // Result properties + const QVector<ThirdPartyIdentifier>& threepids() const; protected: @@ -59,11 +60,9 @@ namespace QMatrixClient QString clientSecret; QString idServer; QString sid; - - operator QJsonObject() const; }; - // End of inner data structures + // Construction/destruction explicit Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind = {}); }; @@ -71,6 +70,8 @@ namespace QMatrixClient class RequestTokenTo3PIDJob : public BaseJob { public: + explicit RequestTokenTo3PIDJob(); + /** Construct a URL out of baseUrl and usual parameters passed to * RequestTokenTo3PIDJob. This function can be used when * a URL for RequestTokenTo3PIDJob is necessary but the job @@ -78,6 +79,5 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl); - explicit RequestTokenTo3PIDJob(); }; } // namespace QMatrixClient diff --git a/lib/jobs/generated/banning.cpp b/lib/csapi/banning.cpp index f66b27b6..f66b27b6 100644 --- a/lib/jobs/generated/banning.cpp +++ b/lib/csapi/banning.cpp diff --git a/lib/jobs/generated/banning.h b/lib/csapi/banning.h index 2d6fbd9b..5d9bae2b 100644 --- a/lib/jobs/generated/banning.h +++ b/lib/csapi/banning.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" diff --git a/lib/jobs/generated/content-repo.cpp b/lib/csapi/content-repo.cpp index 95fc5aed..95fc5aed 100644 --- a/lib/jobs/generated/content-repo.cpp +++ b/lib/csapi/content-repo.cpp diff --git a/lib/jobs/generated/content-repo.h b/lib/csapi/content-repo.h index e1e58f88..4c799b2d 100644 --- a/lib/jobs/generated/content-repo.h +++ b/lib/csapi/content-repo.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" #include <QtCore/QIODevice> @@ -19,6 +19,8 @@ namespace QMatrixClient explicit UploadContentJob(QIODevice* content, const QString& filename = {}, const QString& contentType = {}); ~UploadContentJob() override; + // Result properties + const QString& contentUri() const; protected: @@ -32,6 +34,8 @@ namespace QMatrixClient class GetContentJob : public BaseJob { public: + explicit GetContentJob(const QString& serverName, const QString& mediaId); + /** Construct a URL out of baseUrl and usual parameters passed to * GetContentJob. This function can be used when * a URL for GetContentJob is necessary but the job @@ -39,9 +43,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId); - explicit GetContentJob(const QString& serverName, const QString& mediaId); ~GetContentJob() override; + // Result properties + const QString& contentType() const; const QString& contentDisposition() const; QIODevice* content() const; @@ -57,6 +62,8 @@ namespace QMatrixClient class GetContentOverrideNameJob : public BaseJob { public: + explicit GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName); + /** Construct a URL out of baseUrl and usual parameters passed to * GetContentOverrideNameJob. This function can be used when * a URL for GetContentOverrideNameJob is necessary but the job @@ -64,9 +71,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName); - explicit GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName); ~GetContentOverrideNameJob() override; + // Result properties + const QString& contentType() const; const QString& contentDisposition() const; QIODevice* content() const; @@ -82,6 +90,8 @@ namespace QMatrixClient class GetContentThumbnailJob : public BaseJob { public: + explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {}); + /** Construct a URL out of baseUrl and usual parameters passed to * GetContentThumbnailJob. This function can be used when * a URL for GetContentThumbnailJob is necessary but the job @@ -89,9 +99,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {}); - explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {}); ~GetContentThumbnailJob() override; + // Result properties + const QString& contentType() const; QIODevice* content() const; @@ -106,6 +117,8 @@ namespace QMatrixClient class GetUrlPreviewJob : public BaseJob { public: + explicit GetUrlPreviewJob(const QString& url, qint64 ts = {}); + /** Construct a URL out of baseUrl and usual parameters passed to * GetUrlPreviewJob. This function can be used when * a URL for GetUrlPreviewJob is necessary but the job @@ -113,9 +126,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, qint64 ts = {}); - explicit GetUrlPreviewJob(const QString& url, qint64 ts = {}); ~GetUrlPreviewJob() override; + // Result properties + qint64 matrixImageSize() const; const QString& ogImage() const; diff --git a/lib/csapi/create_room.cpp b/lib/csapi/create_room.cpp new file mode 100644 index 00000000..0a7eb208 --- /dev/null +++ b/lib/csapi/create_room.cpp @@ -0,0 +1,82 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "create_room.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + QJsonObject toJson(const CreateRoomJob::Invite3pid& pod) + { + QJsonObject o; + o.insert("id_server", toJson(pod.idServer)); + o.insert("medium", toJson(pod.medium)); + o.insert("address", toJson(pod.address)); + + return o; + } + + QJsonObject toJson(const CreateRoomJob::StateEvent& pod) + { + QJsonObject o; + o.insert("type", toJson(pod.type)); + o.insert("state_key", toJson(pod.stateKey)); + o.insert("content", toJson(pod.content)); + + return o; + } +} // namespace QMatrixClient + +class CreateRoomJob::Private +{ + public: + QString roomId; +}; + +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", + basePath % "/createRoom") + , d(new Private) +{ + QJsonObject _data; + if (!visibility.isEmpty()) + _data.insert("visibility", toJson(visibility)); + if (!roomAliasName.isEmpty()) + _data.insert("room_alias_name", toJson(roomAliasName)); + if (!name.isEmpty()) + _data.insert("name", toJson(name)); + if (!topic.isEmpty()) + _data.insert("topic", toJson(topic)); + _data.insert("invite", toJson(invite)); + _data.insert("invite_3pid", toJson(invite3pid)); + _data.insert("creation_content", toJson(creationContent)); + _data.insert("initial_state", toJson(initialState)); + if (!preset.isEmpty()) + _data.insert("preset", toJson(preset)); + _data.insert("is_direct", toJson(isDirect)); + _data.insert("guest_can_join", toJson(guestCanJoin)); + setRequestData(_data); +} + +CreateRoomJob::~CreateRoomJob() = default; + +const QString& CreateRoomJob::roomId() const +{ + return d->roomId; +} + +BaseJob::Status CreateRoomJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->roomId = fromJson<QString>(json.value("room_id")); + return Success; +} + diff --git a/lib/jobs/generated/create_room.h b/lib/csapi/create_room.h index b479615a..8ade7a9c 100644 --- a/lib/jobs/generated/create_room.h +++ b/lib/csapi/create_room.h @@ -4,10 +4,11 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" -#include <QtCore/QJsonObject> #include <QtCore/QVector> +#include <QtCore/QJsonObject> +#include <QtCore/QStringList> #include "converters.h" @@ -25,8 +26,6 @@ namespace QMatrixClient QString idServer; QString medium; QString address; - - operator QJsonObject() const; }; struct StateEvent @@ -34,15 +33,15 @@ namespace QMatrixClient QString type; QString stateKey; QJsonObject content; - - operator QJsonObject() const; }; - // End of inner data structures + // Construction/destruction - explicit CreateRoomJob(const QString& visibility = {}, const QString& roomAliasName = {}, const QString& name = {}, const QString& topic = {}, const QVector<QString>& invite = {}, const QVector<Invite3pid>& invite3pid = {}, const QJsonObject& creationContent = {}, const QVector<StateEvent>& initialState = {}, const QString& preset = {}, bool isDirect = {}, bool guestCanJoin = {}); + explicit CreateRoomJob(const QString& visibility = {}, const QString& roomAliasName = {}, const QString& name = {}, const QString& topic = {}, const QStringList& invite = {}, const QVector<Invite3pid>& invite3pid = {}, const QJsonObject& creationContent = {}, const QVector<StateEvent>& initialState = {}, const QString& preset = {}, bool isDirect = {}, bool guestCanJoin = {}); ~CreateRoomJob() override; + // Result properties + const QString& roomId() const; protected: diff --git a/lib/jobs/generated/directory.cpp b/lib/csapi/directory.cpp index 6324a1f5..3066ebe2 100644 --- a/lib/jobs/generated/directory.cpp +++ b/lib/csapi/directory.cpp @@ -26,7 +26,7 @@ class GetRoomIdByAliasJob::Private { public: QString roomId; - QVector<QString> servers; + QStringList servers; }; QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) @@ -49,7 +49,7 @@ const QString& GetRoomIdByAliasJob::roomId() const return d->roomId; } -const QVector<QString>& GetRoomIdByAliasJob::servers() const +const QStringList& GetRoomIdByAliasJob::servers() const { return d->servers; } @@ -58,7 +58,7 @@ BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data) { auto json = data.object(); d->roomId = fromJson<QString>(json.value("room_id")); - d->servers = fromJson<QVector<QString>>(json.value("servers")); + d->servers = fromJson<QStringList>(json.value("servers")); return Success; } diff --git a/lib/jobs/generated/directory.h b/lib/csapi/directory.h index 87591240..b6e62b6a 100644 --- a/lib/jobs/generated/directory.h +++ b/lib/csapi/directory.h @@ -4,9 +4,9 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" -#include <QtCore/QVector> +#include <QtCore/QStringList> namespace QMatrixClient @@ -22,6 +22,8 @@ namespace QMatrixClient class GetRoomIdByAliasJob : public BaseJob { public: + explicit GetRoomIdByAliasJob(const QString& roomAlias); + /** Construct a URL out of baseUrl and usual parameters passed to * GetRoomIdByAliasJob. This function can be used when * a URL for GetRoomIdByAliasJob is necessary but the job @@ -29,11 +31,12 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias); - explicit GetRoomIdByAliasJob(const QString& roomAlias); ~GetRoomIdByAliasJob() override; + // Result properties + const QString& roomId() const; - const QVector<QString>& servers() const; + const QStringList& servers() const; protected: Status parseJson(const QJsonDocument& data) override; @@ -46,6 +49,8 @@ namespace QMatrixClient class DeleteRoomAliasJob : public BaseJob { public: + explicit DeleteRoomAliasJob(const QString& roomAlias); + /** Construct a URL out of baseUrl and usual parameters passed to * DeleteRoomAliasJob. This function can be used when * a URL for DeleteRoomAliasJob is necessary but the job @@ -53,6 +58,5 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias); - explicit DeleteRoomAliasJob(const QString& roomAlias); }; } // namespace QMatrixClient diff --git a/lib/csapi/event_context.cpp b/lib/csapi/event_context.cpp new file mode 100644 index 00000000..d9ab45ca --- /dev/null +++ b/lib/csapi/event_context.cpp @@ -0,0 +1,91 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "event_context.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetEventContextJob::Private +{ + public: + QString begin; + QString end; + RoomEvents eventsBefore; + RoomEventPtr event; + RoomEvents eventsAfter; + StateEvents state; +}; + +BaseJob::Query queryToGetEventContext(int limit) +{ + BaseJob::Query _q; + _q.addQueryItem("limit", QString("%1").arg(limit)); + return _q; +} + +QUrl GetEventContextJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId, int limit) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/context/" % eventId, + queryToGetEventContext(limit)); +} + +GetEventContextJob::GetEventContextJob(const QString& roomId, const QString& eventId, int limit) + : BaseJob(HttpVerb::Get, "GetEventContextJob", + basePath % "/rooms/" % roomId % "/context/" % eventId, + queryToGetEventContext(limit)) + , d(new Private) +{ +} + +GetEventContextJob::~GetEventContextJob() = default; + +const QString& GetEventContextJob::begin() const +{ + return d->begin; +} + +const QString& GetEventContextJob::end() const +{ + return d->end; +} + +RoomEvents&& GetEventContextJob::eventsBefore() +{ + return std::move(d->eventsBefore); +} + +RoomEventPtr&& GetEventContextJob::event() +{ + return std::move(d->event); +} + +RoomEvents&& GetEventContextJob::eventsAfter() +{ + return std::move(d->eventsAfter); +} + +StateEvents&& GetEventContextJob::state() +{ + return std::move(d->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")); + return Success; +} + diff --git a/lib/csapi/event_context.h b/lib/csapi/event_context.h new file mode 100644 index 00000000..caf1dfd4 --- /dev/null +++ b/lib/csapi/event_context.h @@ -0,0 +1,46 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include "events/event.h" + + +namespace QMatrixClient +{ + // Operations + + class GetEventContextJob : public BaseJob + { + public: + explicit GetEventContextJob(const QString& roomId, const QString& eventId, int limit = {}); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetEventContextJob. This function can be used when + * a URL for GetEventContextJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId, int limit = {}); + + ~GetEventContextJob() override; + + // Result properties + + const QString& begin() const; + const QString& end() const; + RoomEvents&& eventsBefore(); + RoomEventPtr&& event(); + RoomEvents&& eventsAfter(); + StateEvents&& state(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml new file mode 100644 index 00000000..7f6a97e0 --- /dev/null +++ b/lib/csapi/gtad.yaml @@ -0,0 +1,139 @@ +analyzer: + subst: + "%CLIENT_RELEASE_LABEL%": r0 + "%CLIENT_MAJOR_VERSION%": r0 + identifiers: + signed: signedData + unsigned: unsignedData + default: isDefault + origin_server_ts: originServerTimestamp # Instead of originServerTs + start: begin # Because start() is a method in BaseJob + + types: + # Structure: + # swaggerType: <targetTypeSpec> + # OR + # swaggerType: + # - swaggerFormat: <targetTypeSpec> + # - /swaggerFormatRegEx/: <targetTypeSpec> + # - //: <targetTypeSpec> # default, if the format doesn't mach anything above + # WHERE + # targetTypeSpec = targetType OR + # { type: targetType, imports: <filename OR [ filenames... ]>, <other attributes...> } + integer: + - int64: qint64 + - int32: qint32 + - //: int + number: + - float: float + - //: double + boolean: { type: bool, initializer: false } + string: + - byte: &ByteStream + type: QIODevice* + #initializer: '"{{defaultValue}}"' + #string?: true + imports: <QtCore/QIODevice> + - binary: *ByteStream + - date: + type: QDate + initializer: QDate::fromString("{{defaultValue}}") + avoidCopy?: true + imports: <QtCore/QDate> + - dateTime: + type: QDateTime + initializer: QDateTime::fromString("{{defaultValue}}") + avoidCopy?: true + imports: <QtCore/QDateTime> + - //: + type: QString + initializer: QStringLiteral("{{defaultValue}}") + string?: true + avoidCopy?: true + file: *ByteStream + object: + - /m\.room\.member$/: # A stub for EventsBatch<RoomMemberEvent> + - /state_event.yaml$/: + type: StateEventPtr + noCopy?: true + imports: '"events/event.h"' + - /room_event.yaml$/: + type: RoomEventPtr + noCopy?: true + imports: '"events/event.h"' + - /event.yaml$/: + type: EventPtr + noCopy?: true + imports: '"events/event.h"' + - //: + type: QJsonObject + avoidCopy?: true + imports: <QtCore/QJsonObject> + array: + - string: + type: QStringList + avoidCopy?: true + imports: <QtCore/QStringList> + - /^Notification|Result$/: + type: "std::vector<{{1}}>" + noCopy?: true + imports: '"events/event.h"' + - /m\.room\.member$/: + type: "EventsArray<RoomMemberEvent>" + noCopy?: true + imports: '"events/roommemberevent.h"' + - /state_event.yaml$/: + type: StateEvents + noCopy?: true + - /room_event.yaml$/: + type: RoomEvents + noCopy?: true + - /event.yaml$/: + type: Events + noCopy?: true + - /.+/: + type: "QVector<{{1}}>" + avoidCopy?: true + imports: <QtCore/QVector> + - //: { type: QJsonArray, "avoidCopy?": true, imports: <QtCore/QJsonArray> } + map: + - RoomState: + type: "std::unordered_map<QString, {{1}}>" + noCopy?: true + imports: <unordered_map> + - /.+/: + type: "QHash<QString, {{1}}>" + avoidCopy?: true + imports: <QtCore/QHash> + - //: + type: QVariantHash + avoidCopy?: true + imports: <QtCore/QVariantHash> + variant: { type: QVariant, "avoidCopy?": true, imports: <QtCore/QVariant> } + schema: # Properties of inline structure definitions + avoidCopy?: true + + #operations: + +mustache: + definitions: + _scopeRenderer: "{{scopeCamelCase}}Job::" + _literalQuote: '"' + maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}{{#noCopy?}}&&{{/noCopy?}}" + qualifiedMaybeCrefType: + "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}{{#noCopy?}}&&{{/noCopy?}}" + initializeDefaultValue: "{{#defaultValue}}{{>initializer}}{{/defaultValue}}{{^defaultValue}}{}{{/defaultValue}}" + joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{#@join}}, {{/@join}}' + joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}' + passQueryParams: '{{#queryParams}}{{paramName}}{{#@join}}, {{/@join}}{{/queryParams}}' + paramToString: '{{#string?}}{{nameCamelCase}}{{/string?}}{{^string?}}QString("%1").arg({{nameCamelCase}}){{/string?}}' + # preamble: preamble.mustache + copyrightName: Kitsune Ral + copyrightEmail: <kitsune-ral@users.sf.net> + + templates: + - "{{base}}.h.mustache" + - "{{base}}.cpp.mustache" + + #outFilesList: apifiles.txt + diff --git a/lib/jobs/generated/inviting.cpp b/lib/csapi/inviting.cpp index d2ee2107..d2ee2107 100644 --- a/lib/jobs/generated/inviting.cpp +++ b/lib/csapi/inviting.cpp diff --git a/lib/jobs/generated/inviting.h b/lib/csapi/inviting.h index eaa884df..3119de6a 100644 --- a/lib/jobs/generated/inviting.h +++ b/lib/csapi/inviting.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" diff --git a/lib/csapi/joining.cpp b/lib/csapi/joining.cpp new file mode 100644 index 00000000..705e8f83 --- /dev/null +++ b/lib/csapi/joining.cpp @@ -0,0 +1,118 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "joining.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + QJsonObject toJson(const JoinRoomByIdJob::ThirdPartySigned& pod) + { + QJsonObject o; + o.insert("sender", toJson(pod.sender)); + o.insert("mxid", toJson(pod.mxid)); + o.insert("token", toJson(pod.token)); + o.insert("signatures", toJson(pod.signatures)); + + return o; + } +} // namespace QMatrixClient + +class JoinRoomByIdJob::Private +{ + public: + QString roomId; +}; + +JoinRoomByIdJob::JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned& thirdPartySigned) + : BaseJob(HttpVerb::Post, "JoinRoomByIdJob", + basePath % "/rooms/" % roomId % "/join") + , d(new Private) +{ + QJsonObject _data; + _data.insert("third_party_signed", toJson(thirdPartySigned)); + setRequestData(_data); +} + +JoinRoomByIdJob::~JoinRoomByIdJob() = default; + +const QString& JoinRoomByIdJob::roomId() const +{ + return d->roomId; +} + +BaseJob::Status JoinRoomByIdJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("room_id")) + return { JsonParseError, + "The key 'room_id' not found in the response" }; + d->roomId = fromJson<QString>(json.value("room_id")); + return Success; +} + +namespace QMatrixClient +{ + // Converters + + QJsonObject toJson(const JoinRoomJob::Signed& pod) + { + QJsonObject o; + o.insert("sender", toJson(pod.sender)); + o.insert("mxid", toJson(pod.mxid)); + o.insert("token", toJson(pod.token)); + o.insert("signatures", toJson(pod.signatures)); + + return o; + } + + QJsonObject toJson(const JoinRoomJob::ThirdPartySigned& pod) + { + QJsonObject o; + o.insert("signed", toJson(pod.signedData)); + + return o; + } +} // namespace QMatrixClient + +class JoinRoomJob::Private +{ + public: + QString roomId; +}; + +JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& thirdPartySigned) + : BaseJob(HttpVerb::Post, "JoinRoomJob", + basePath % "/join/" % roomIdOrAlias) + , d(new Private) +{ + QJsonObject _data; + _data.insert("third_party_signed", toJson(thirdPartySigned)); + setRequestData(_data); +} + +JoinRoomJob::~JoinRoomJob() = default; + +const QString& JoinRoomJob::roomId() const +{ + return d->roomId; +} + +BaseJob::Status JoinRoomJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("room_id")) + return { JsonParseError, + "The key 'room_id' not found in the response" }; + d->roomId = fromJson<QString>(json.value("room_id")); + return Success; +} + diff --git a/lib/csapi/joining.h b/lib/csapi/joining.h new file mode 100644 index 00000000..ccaed04e --- /dev/null +++ b/lib/csapi/joining.h @@ -0,0 +1,81 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QJsonObject> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class JoinRoomByIdJob : public BaseJob + { + public: + // Inner data structures + + struct ThirdPartySigned + { + QString sender; + QString mxid; + QString token; + QJsonObject signatures; + }; + + // Construction/destruction + + explicit JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned& thirdPartySigned = {}); + ~JoinRoomByIdJob() override; + + // Result properties + + const QString& roomId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class JoinRoomJob : public BaseJob + { + public: + // Inner data structures + + struct Signed + { + QString sender; + QString mxid; + QString token; + QJsonObject signatures; + }; + + struct ThirdPartySigned + { + Signed signedData; + }; + + // Construction/destruction + + explicit JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& thirdPartySigned = {}); + ~JoinRoomJob() override; + + // Result properties + + const QString& roomId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/kicking.cpp b/lib/csapi/kicking.cpp index bf2490b7..bf2490b7 100644 --- a/lib/jobs/generated/kicking.cpp +++ b/lib/csapi/kicking.cpp diff --git a/lib/jobs/generated/kicking.h b/lib/csapi/kicking.h index 3814bef7..030dff88 100644 --- a/lib/jobs/generated/kicking.h +++ b/lib/csapi/kicking.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" diff --git a/lib/jobs/generated/leaving.cpp b/lib/csapi/leaving.cpp index afc4adbd..afc4adbd 100644 --- a/lib/jobs/generated/leaving.cpp +++ b/lib/csapi/leaving.cpp diff --git a/lib/jobs/generated/leaving.h b/lib/csapi/leaving.h index 9bae2363..f6711c32 100644 --- a/lib/jobs/generated/leaving.h +++ b/lib/csapi/leaving.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -15,6 +15,8 @@ namespace QMatrixClient class LeaveRoomJob : public BaseJob { public: + explicit LeaveRoomJob(const QString& roomId); + /** Construct a URL out of baseUrl and usual parameters passed to * LeaveRoomJob. This function can be used when * a URL for LeaveRoomJob is necessary but the job @@ -22,12 +24,13 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); - explicit LeaveRoomJob(const QString& roomId); }; class ForgetRoomJob : public BaseJob { public: + explicit ForgetRoomJob(const QString& roomId); + /** Construct a URL out of baseUrl and usual parameters passed to * ForgetRoomJob. This function can be used when * a URL for ForgetRoomJob is necessary but the job @@ -35,6 +38,5 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); - explicit ForgetRoomJob(const QString& roomId); }; } // namespace QMatrixClient diff --git a/lib/csapi/list_joined_rooms.cpp b/lib/csapi/list_joined_rooms.cpp new file mode 100644 index 00000000..82ec8849 --- /dev/null +++ b/lib/csapi/list_joined_rooms.cpp @@ -0,0 +1,50 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "list_joined_rooms.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetJoinedRoomsJob::Private +{ + public: + QStringList joinedRooms; +}; + +QUrl GetJoinedRoomsJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/joined_rooms"); +} + +GetJoinedRoomsJob::GetJoinedRoomsJob() + : BaseJob(HttpVerb::Get, "GetJoinedRoomsJob", + basePath % "/joined_rooms") + , d(new Private) +{ +} + +GetJoinedRoomsJob::~GetJoinedRoomsJob() = default; + +const QStringList& GetJoinedRoomsJob::joinedRooms() const +{ + return d->joinedRooms; +} + +BaseJob::Status GetJoinedRoomsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("joined_rooms")) + return { JsonParseError, + "The key 'joined_rooms' not found in the response" }; + d->joinedRooms = fromJson<QStringList>(json.value("joined_rooms")); + return Success; +} + diff --git a/lib/csapi/list_joined_rooms.h b/lib/csapi/list_joined_rooms.h new file mode 100644 index 00000000..e590fa18 --- /dev/null +++ b/lib/csapi/list_joined_rooms.h @@ -0,0 +1,41 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QStringList> + + +namespace QMatrixClient +{ + // Operations + + class GetJoinedRoomsJob : public BaseJob + { + public: + explicit GetJoinedRoomsJob(); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetJoinedRoomsJob. This function can be used when + * a URL for GetJoinedRoomsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + ~GetJoinedRoomsJob() override; + + // Result properties + + const QStringList& joinedRooms() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/csapi/list_public_rooms.cpp index 1e3c4ed8..b27bdd58 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/csapi/list_public_rooms.cpp @@ -10,23 +10,53 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); -GetPublicRoomsJob::PublicRoomsChunk::operator QJsonObject() const +class GetRoomVisibilityOnDirectoryJob::Private { - QJsonObject o; - o.insert("aliases", toJson(aliases)); - o.insert("canonical_alias", toJson(canonicalAlias)); - o.insert("name", toJson(name)); - o.insert("num_joined_members", toJson(numJoinedMembers)); - o.insert("room_id", toJson(roomId)); - o.insert("topic", toJson(topic)); - o.insert("world_readable", toJson(worldReadable)); - o.insert("guest_can_join", toJson(guestCanJoin)); - o.insert("avatar_url", toJson(avatarUrl)); - - return o; + public: + QString visibility; +}; + +QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/directory/list/room/" % roomId); +} + +GetRoomVisibilityOnDirectoryJob::GetRoomVisibilityOnDirectoryJob(const QString& roomId) + : BaseJob(HttpVerb::Get, "GetRoomVisibilityOnDirectoryJob", + basePath % "/directory/list/room/" % roomId, false) + , d(new Private) +{ +} + +GetRoomVisibilityOnDirectoryJob::~GetRoomVisibilityOnDirectoryJob() = default; + +const QString& GetRoomVisibilityOnDirectoryJob::visibility() const +{ + return d->visibility; +} + +BaseJob::Status GetRoomVisibilityOnDirectoryJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->visibility = fromJson<QString>(json.value("visibility")); + return Success; +} + +SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility) + : BaseJob(HttpVerb::Put, "SetRoomVisibilityOnDirectoryJob", + basePath % "/directory/list/room/" % roomId) +{ + QJsonObject _data; + if (!visibility.isEmpty()) + _data.insert("visibility", toJson(visibility)); + setRequestData(_data); } + namespace QMatrixClient { + // Converters + template <> struct FromJson<GetPublicRoomsJob::PublicRoomsChunk> { GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) @@ -34,13 +64,13 @@ namespace QMatrixClient const auto& o = jv.toObject(); GetPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson<QVector<QString>>(o.value("aliases")); + fromJson<QStringList>(o.value("aliases")); result.canonicalAlias = fromJson<QString>(o.value("canonical_alias")); result.name = fromJson<QString>(o.value("name")); result.numJoinedMembers = - fromJson<double>(o.value("num_joined_members")); + fromJson<qint64>(o.value("num_joined_members")); result.roomId = fromJson<QString>(o.value("room_id")); result.topic = @@ -51,7 +81,7 @@ namespace QMatrixClient fromJson<bool>(o.value("guest_can_join")); result.avatarUrl = fromJson<QString>(o.value("avatar_url")); - + return result; } }; @@ -63,10 +93,10 @@ class GetPublicRoomsJob::Private QVector<PublicRoomsChunk> chunk; QString nextBatch; QString prevBatch; - double totalRoomCountEstimate; + qint64 totalRoomCountEstimate; }; -BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const QString& server) +BaseJob::Query queryToGetPublicRooms(int limit, const QString& since, const QString& server) { BaseJob::Query _q; _q.addQueryItem("limit", QString("%1").arg(limit)); @@ -77,14 +107,14 @@ BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const Q return _q; } -QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, double limit, const QString& since, const QString& server) +QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, int limit, const QString& since, const QString& server) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/publicRooms", queryToGetPublicRooms(limit, since, server)); } -GetPublicRoomsJob::GetPublicRoomsJob(double limit, const QString& since, const QString& server) +GetPublicRoomsJob::GetPublicRoomsJob(int limit, const QString& since, const QString& server) : BaseJob(HttpVerb::Get, "GetPublicRoomsJob", basePath % "/publicRooms", queryToGetPublicRooms(limit, since, server), @@ -110,7 +140,7 @@ const QString& GetPublicRoomsJob::prevBatch() const return d->prevBatch; } -double GetPublicRoomsJob::totalRoomCountEstimate() const +qint64 GetPublicRoomsJob::totalRoomCountEstimate() const { return d->totalRoomCountEstimate; } @@ -124,50 +154,22 @@ BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) 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<double>(json.value("total_room_count_estimate")); + d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate")); return Success; } -QueryPublicRoomsJob::Filter::operator QJsonObject() const -{ - QJsonObject o; - o.insert("generic_search_term", toJson(genericSearchTerm)); - - return o; -} namespace QMatrixClient { - template <> struct FromJson<QueryPublicRoomsJob::Filter> + // Converters + + QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) { - QueryPublicRoomsJob::Filter operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - QueryPublicRoomsJob::Filter result; - result.genericSearchTerm = - fromJson<QString>(o.value("generic_search_term")); - - return result; - } - }; -} // namespace QMatrixClient + QJsonObject o; + o.insert("generic_search_term", toJson(pod.genericSearchTerm)); + + return o; + } -QueryPublicRoomsJob::PublicRoomsChunk::operator QJsonObject() const -{ - QJsonObject o; - o.insert("aliases", toJson(aliases)); - o.insert("canonical_alias", toJson(canonicalAlias)); - o.insert("name", toJson(name)); - o.insert("num_joined_members", toJson(numJoinedMembers)); - o.insert("room_id", toJson(roomId)); - o.insert("topic", toJson(topic)); - o.insert("world_readable", toJson(worldReadable)); - o.insert("guest_can_join", toJson(guestCanJoin)); - o.insert("avatar_url", toJson(avatarUrl)); - - return o; -} -namespace QMatrixClient -{ template <> struct FromJson<QueryPublicRoomsJob::PublicRoomsChunk> { QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) @@ -175,13 +177,13 @@ namespace QMatrixClient const auto& o = jv.toObject(); QueryPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson<QVector<QString>>(o.value("aliases")); + fromJson<QStringList>(o.value("aliases")); result.canonicalAlias = fromJson<QString>(o.value("canonical_alias")); result.name = fromJson<QString>(o.value("name")); result.numJoinedMembers = - fromJson<double>(o.value("num_joined_members")); + fromJson<qint64>(o.value("num_joined_members")); result.roomId = fromJson<QString>(o.value("room_id")); result.topic = @@ -192,7 +194,7 @@ namespace QMatrixClient fromJson<bool>(o.value("guest_can_join")); result.avatarUrl = fromJson<QString>(o.value("avatar_url")); - + return result; } }; @@ -204,7 +206,7 @@ class QueryPublicRoomsJob::Private QVector<PublicRoomsChunk> chunk; QString nextBatch; QString prevBatch; - double totalRoomCountEstimate; + qint64 totalRoomCountEstimate; }; BaseJob::Query queryToQueryPublicRooms(const QString& server) @@ -215,7 +217,7 @@ BaseJob::Query queryToQueryPublicRooms(const QString& server) return _q; } -QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, double limit, const QString& since, const Filter& filter) +QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, int limit, const QString& since, const Filter& filter) : BaseJob(HttpVerb::Post, "QueryPublicRoomsJob", basePath % "/publicRooms", queryToQueryPublicRooms(server)) @@ -246,7 +248,7 @@ const QString& QueryPublicRoomsJob::prevBatch() const return d->prevBatch; } -double QueryPublicRoomsJob::totalRoomCountEstimate() const +qint64 QueryPublicRoomsJob::totalRoomCountEstimate() const { return d->totalRoomCountEstimate; } @@ -260,7 +262,7 @@ BaseJob::Status QueryPublicRoomsJob::parseJson(const QJsonDocument& data) 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<double>(json.value("total_room_count_estimate")); + d->totalRoomCountEstimate = fromJson<qint64>(json.value("total_room_count_estimate")); return Success; } diff --git a/lib/jobs/generated/list_public_rooms.h b/lib/csapi/list_public_rooms.h index 5c281de3..76d78577 100644 --- a/lib/jobs/generated/list_public_rooms.h +++ b/lib/csapi/list_public_rooms.h @@ -4,9 +4,10 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" #include <QtCore/QVector> +#include <QtCore/QStringList> #include "converters.h" @@ -14,6 +15,38 @@ namespace QMatrixClient { // Operations + class GetRoomVisibilityOnDirectoryJob : public BaseJob + { + public: + explicit GetRoomVisibilityOnDirectoryJob(const QString& roomId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomVisibilityOnDirectoryJob. This function can be used when + * a URL for GetRoomVisibilityOnDirectoryJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); + + ~GetRoomVisibilityOnDirectoryJob() override; + + // Result properties + + const QString& visibility() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class SetRoomVisibilityOnDirectoryJob : public BaseJob + { + public: + explicit SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility = {}); + }; + class GetPublicRoomsJob : public BaseJob { public: @@ -21,35 +54,36 @@ namespace QMatrixClient struct PublicRoomsChunk { - QVector<QString> aliases; + QStringList aliases; QString canonicalAlias; QString name; - double numJoinedMembers; + qint64 numJoinedMembers; QString roomId; QString topic; bool worldReadable; bool guestCanJoin; QString avatarUrl; - - operator QJsonObject() const; }; - // End of inner data structures + // Construction/destruction + + explicit GetPublicRoomsJob(int limit = {}, const QString& since = {}, const QString& server = {}); /** Construct a URL out of baseUrl and usual parameters passed to * GetPublicRoomsJob. This function can be used when * a URL for GetPublicRoomsJob is necessary but the job * itself isn't. */ - static QUrl makeRequestUrl(QUrl baseUrl, double limit = {}, const QString& since = {}, const QString& server = {}); + static QUrl makeRequestUrl(QUrl baseUrl, int limit = {}, const QString& since = {}, const QString& server = {}); - explicit GetPublicRoomsJob(double limit = {}, const QString& since = {}, const QString& server = {}); ~GetPublicRoomsJob() override; + // Result properties + const QVector<PublicRoomsChunk>& chunk() const; const QString& nextBatch() const; const QString& prevBatch() const; - double totalRoomCountEstimate() const; + qint64 totalRoomCountEstimate() const; protected: Status parseJson(const QJsonDocument& data) override; @@ -67,34 +101,32 @@ namespace QMatrixClient struct Filter { QString genericSearchTerm; - - operator QJsonObject() const; }; struct PublicRoomsChunk { - QVector<QString> aliases; + QStringList aliases; QString canonicalAlias; QString name; - double numJoinedMembers; + qint64 numJoinedMembers; QString roomId; QString topic; bool worldReadable; bool guestCanJoin; QString avatarUrl; - - operator QJsonObject() const; }; - // End of inner data structures + // Construction/destruction - explicit QueryPublicRoomsJob(const QString& server = {}, double limit = {}, const QString& since = {}, const Filter& filter = {}); + explicit QueryPublicRoomsJob(const QString& server = {}, int limit = {}, const QString& since = {}, const Filter& filter = {}); ~QueryPublicRoomsJob() override; + // Result properties + const QVector<PublicRoomsChunk>& chunk() const; const QString& nextBatch() const; const QString& prevBatch() const; - double totalRoomCountEstimate() const; + qint64 totalRoomCountEstimate() const; protected: Status parseJson(const QJsonDocument& data) override; diff --git a/lib/jobs/generated/login.cpp b/lib/csapi/login.cpp index a4dab428..a4dab428 100644 --- a/lib/jobs/generated/login.cpp +++ b/lib/csapi/login.cpp diff --git a/lib/jobs/generated/login.h b/lib/csapi/login.h index 3ac955d4..2adbdb4d 100644 --- a/lib/jobs/generated/login.h +++ b/lib/csapi/login.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -18,6 +18,8 @@ namespace QMatrixClient explicit 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 = {}); ~LoginJob() override; + // Result properties + const QString& userId() const; const QString& accessToken() const; const QString& homeServer() const; diff --git a/lib/jobs/generated/logout.cpp b/lib/csapi/logout.cpp index b943dcd3..b943dcd3 100644 --- a/lib/jobs/generated/logout.cpp +++ b/lib/csapi/logout.cpp diff --git a/lib/jobs/generated/logout.h b/lib/csapi/logout.h index 7640ba55..7993335f 100644 --- a/lib/jobs/generated/logout.h +++ b/lib/csapi/logout.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -15,6 +15,8 @@ namespace QMatrixClient class LogoutJob : public BaseJob { public: + explicit LogoutJob(); + /** Construct a URL out of baseUrl and usual parameters passed to * LogoutJob. This function can be used when * a URL for LogoutJob is necessary but the job @@ -22,6 +24,5 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl); - explicit LogoutJob(); }; } // namespace QMatrixClient diff --git a/lib/csapi/message_pagination.cpp b/lib/csapi/message_pagination.cpp new file mode 100644 index 00000000..f89ccd03 --- /dev/null +++ b/lib/csapi/message_pagination.cpp @@ -0,0 +1,76 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "message_pagination.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetRoomEventsJob::Private +{ + public: + QString begin; + QString end; + RoomEvents chunk; +}; + +BaseJob::Query queryToGetRoomEvents(const QString& from, const QString& to, const QString& dir, int limit, const QString& filter) +{ + BaseJob::Query _q; + _q.addQueryItem("from", from); + if (!to.isEmpty()) + _q.addQueryItem("to", to); + _q.addQueryItem("dir", dir); + _q.addQueryItem("limit", QString("%1").arg(limit)); + if (!filter.isEmpty()) + _q.addQueryItem("filter", filter); + return _q; +} + +QUrl GetRoomEventsJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& from, const QString& dir, const QString& to, int limit, const QString& filter) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/messages", + queryToGetRoomEvents(from, to, dir, limit, filter)); +} + +GetRoomEventsJob::GetRoomEventsJob(const QString& roomId, const QString& from, const QString& dir, const QString& to, int limit, const QString& filter) + : BaseJob(HttpVerb::Get, "GetRoomEventsJob", + basePath % "/rooms/" % roomId % "/messages", + queryToGetRoomEvents(from, to, dir, limit, filter)) + , d(new Private) +{ +} + +GetRoomEventsJob::~GetRoomEventsJob() = default; + +const QString& GetRoomEventsJob::begin() const +{ + return d->begin; +} + +const QString& GetRoomEventsJob::end() const +{ + return d->end; +} + +RoomEvents&& GetRoomEventsJob::chunk() +{ + return std::move(d->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")); + return Success; +} + diff --git a/lib/csapi/message_pagination.h b/lib/csapi/message_pagination.h new file mode 100644 index 00000000..61e7323f --- /dev/null +++ b/lib/csapi/message_pagination.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include "events/event.h" + + +namespace QMatrixClient +{ + // Operations + + class GetRoomEventsJob : public BaseJob + { + public: + explicit GetRoomEventsJob(const QString& roomId, const QString& from, const QString& dir, const QString& to = {}, int limit = {}, const QString& filter = {}); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomEventsJob. This function can be used when + * a URL for GetRoomEventsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& from, const QString& dir, const QString& to = {}, int limit = {}, const QString& filter = {}); + + ~GetRoomEventsJob() override; + + // Result properties + + const QString& begin() const; + const QString& end() const; + RoomEvents&& chunk(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/notifications.cpp b/lib/csapi/notifications.cpp index df6b10ba..04ad0175 100644 --- a/lib/jobs/generated/notifications.cpp +++ b/lib/csapi/notifications.cpp @@ -12,6 +12,8 @@ static const auto basePath = QStringLiteral("/_matrix/client/r0"); namespace QMatrixClient { + // Converters + template <> struct FromJson<GetNotificationsJob::Notification> { GetNotificationsJob::Notification operator()(const QJsonValue& jv) @@ -30,7 +32,7 @@ namespace QMatrixClient fromJson<QString>(o.value("room_id")); result.ts = fromJson<qint64>(o.value("ts")); - + return result; } }; @@ -76,9 +78,9 @@ const QString& GetNotificationsJob::nextToken() const return d->nextToken; } -const std::vector<GetNotificationsJob::Notification>& GetNotificationsJob::notifications() const +std::vector<GetNotificationsJob::Notification>&& GetNotificationsJob::notifications() { - return d->notifications; + return std::move(d->notifications); } BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) diff --git a/lib/jobs/generated/notifications.h b/lib/csapi/notifications.h index 798b9576..61da518b 100644 --- a/lib/jobs/generated/notifications.h +++ b/lib/csapi/notifications.h @@ -4,9 +4,8 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" -#include <vector> #include "events/event.h" #include <QtCore/QJsonObject> #include <QtCore/QVector> @@ -30,10 +29,11 @@ namespace QMatrixClient bool read; QString roomId; qint64 ts; - }; - // End of inner data structures + // Construction/destruction + + explicit GetNotificationsJob(const QString& from = {}, int limit = {}, const QString& only = {}); /** Construct a URL out of baseUrl and usual parameters passed to * GetNotificationsJob. This function can be used when @@ -42,11 +42,12 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& from = {}, int limit = {}, const QString& only = {}); - explicit GetNotificationsJob(const QString& from = {}, int limit = {}, const QString& only = {}); ~GetNotificationsJob() override; + // Result properties + const QString& nextToken() const; - const std::vector<Notification>& notifications() const; + std::vector<Notification>&& notifications(); protected: Status parseJson(const QJsonDocument& data) override; diff --git a/lib/csapi/preamble.mustache b/lib/csapi/preamble.mustache new file mode 100644 index 00000000..3ba87d61 --- /dev/null +++ b/lib/csapi/preamble.mustache @@ -0,0 +1,3 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ diff --git a/lib/jobs/generated/profile.cpp b/lib/csapi/profile.cpp index d8ddbc14..d8ddbc14 100644 --- a/lib/jobs/generated/profile.cpp +++ b/lib/csapi/profile.cpp diff --git a/lib/jobs/generated/profile.h b/lib/csapi/profile.h index 024130f5..604291b4 100644 --- a/lib/jobs/generated/profile.h +++ b/lib/csapi/profile.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -21,6 +21,8 @@ namespace QMatrixClient class GetDisplayNameJob : public BaseJob { public: + explicit GetDisplayNameJob(const QString& userId); + /** Construct a URL out of baseUrl and usual parameters passed to * GetDisplayNameJob. This function can be used when * a URL for GetDisplayNameJob is necessary but the job @@ -28,9 +30,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - explicit GetDisplayNameJob(const QString& userId); ~GetDisplayNameJob() override; + // Result properties + const QString& displayname() const; protected: @@ -50,6 +53,8 @@ namespace QMatrixClient class GetAvatarUrlJob : public BaseJob { public: + explicit GetAvatarUrlJob(const QString& userId); + /** Construct a URL out of baseUrl and usual parameters passed to * GetAvatarUrlJob. This function can be used when * a URL for GetAvatarUrlJob is necessary but the job @@ -57,9 +62,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - explicit GetAvatarUrlJob(const QString& userId); ~GetAvatarUrlJob() override; + // Result properties + const QString& avatarUrl() const; protected: @@ -73,6 +79,8 @@ namespace QMatrixClient class GetUserProfileJob : public BaseJob { public: + explicit GetUserProfileJob(const QString& userId); + /** Construct a URL out of baseUrl and usual parameters passed to * GetUserProfileJob. This function can be used when * a URL for GetUserProfileJob is necessary but the job @@ -80,9 +88,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - explicit GetUserProfileJob(const QString& userId); ~GetUserProfileJob() override; + // Result properties + const QString& avatarUrl() const; const QString& displayname() const; diff --git a/lib/csapi/pusher.cpp b/lib/csapi/pusher.cpp new file mode 100644 index 00000000..dea7cf8b --- /dev/null +++ b/lib/csapi/pusher.cpp @@ -0,0 +1,121 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "pusher.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<GetPushersJob::PusherData> + { + GetPushersJob::PusherData operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetPushersJob::PusherData result; + result.url = + fromJson<QString>(o.value("url")); + + return result; + } + }; + + template <> struct FromJson<GetPushersJob::Pusher> + { + GetPushersJob::Pusher operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + GetPushersJob::Pusher result; + result.pushkey = + fromJson<QString>(o.value("pushkey")); + result.kind = + fromJson<QString>(o.value("kind")); + result.appId = + fromJson<QString>(o.value("app_id")); + result.appDisplayName = + fromJson<QString>(o.value("app_display_name")); + result.deviceDisplayName = + fromJson<QString>(o.value("device_display_name")); + result.profileTag = + fromJson<QString>(o.value("profile_tag")); + result.lang = + fromJson<QString>(o.value("lang")); + result.data = + fromJson<GetPushersJob::PusherData>(o.value("data")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetPushersJob::Private +{ + public: + QVector<Pusher> pushers; +}; + +QUrl GetPushersJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/pushers"); +} + +GetPushersJob::GetPushersJob() + : BaseJob(HttpVerb::Get, "GetPushersJob", + basePath % "/pushers") + , d(new Private) +{ +} + +GetPushersJob::~GetPushersJob() = default; + +const QVector<GetPushersJob::Pusher>& GetPushersJob::pushers() const +{ + return d->pushers; +} + +BaseJob::Status GetPushersJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->pushers = fromJson<QVector<Pusher>>(json.value("pushers")); + return Success; +} + +namespace QMatrixClient +{ + // Converters + + QJsonObject toJson(const PostPusherJob::PusherData& pod) + { + QJsonObject o; + o.insert("url", toJson(pod.url)); + + return o; + } +} // namespace QMatrixClient + +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", + basePath % "/pushers/set") +{ + QJsonObject _data; + _data.insert("pushkey", toJson(pushkey)); + _data.insert("kind", toJson(kind)); + _data.insert("app_id", toJson(appId)); + _data.insert("app_display_name", toJson(appDisplayName)); + _data.insert("device_display_name", toJson(deviceDisplayName)); + if (!profileTag.isEmpty()) + _data.insert("profile_tag", toJson(profileTag)); + _data.insert("lang", toJson(lang)); + _data.insert("data", toJson(data)); + _data.insert("append", toJson(append)); + setRequestData(_data); +} + diff --git a/lib/csapi/pusher.h b/lib/csapi/pusher.h new file mode 100644 index 00000000..97e3ba38 --- /dev/null +++ b/lib/csapi/pusher.h @@ -0,0 +1,78 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QVector> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class GetPushersJob : public BaseJob + { + public: + // Inner data structures + + struct PusherData + { + QString url; + }; + + struct Pusher + { + QString pushkey; + QString kind; + QString appId; + QString appDisplayName; + QString deviceDisplayName; + QString profileTag; + QString lang; + PusherData data; + }; + + // Construction/destruction + + explicit GetPushersJob(); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetPushersJob. This function can be used when + * a URL for GetPushersJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + ~GetPushersJob() override; + + // Result properties + + const QVector<Pusher>& pushers() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class PostPusherJob : public BaseJob + { + public: + // Inner data structures + + struct PusherData + { + QString url; + }; + + // Construction/destruction + + explicit PostPusherJob(const QString& pushkey, const QString& kind, const QString& appId, const QString& appDisplayName, const QString& deviceDisplayName, const QString& lang, const PusherData& data, const QString& profileTag = {}, bool append = {}); + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/receipts.cpp b/lib/csapi/receipts.cpp index 83c38b6f..945e8673 100644 --- a/lib/jobs/generated/receipts.cpp +++ b/lib/csapi/receipts.cpp @@ -16,6 +16,6 @@ PostReceiptJob::PostReceiptJob(const QString& roomId, const QString& receiptType : BaseJob(HttpVerb::Post, "PostReceiptJob", basePath % "/rooms/" % roomId % "/receipt/" % receiptType % "/" % eventId) { - setRequestData(Data(receipt)); + setRequestData(Data(toJson(receipt))); } diff --git a/lib/jobs/generated/receipts.h b/lib/csapi/receipts.h index 9eb7a489..b109282e 100644 --- a/lib/jobs/generated/receipts.h +++ b/lib/csapi/receipts.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" #include <QtCore/QJsonObject> diff --git a/lib/jobs/generated/redaction.cpp b/lib/csapi/redaction.cpp index 0da35dfc..0da35dfc 100644 --- a/lib/jobs/generated/redaction.cpp +++ b/lib/csapi/redaction.cpp diff --git a/lib/jobs/generated/redaction.h b/lib/csapi/redaction.h index e3b3ff4f..56645ee5 100644 --- a/lib/jobs/generated/redaction.h +++ b/lib/csapi/redaction.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -18,6 +18,8 @@ namespace QMatrixClient explicit RedactEventJob(const QString& roomId, const QString& eventId, const QString& txnId, const QString& reason = {}); ~RedactEventJob() override; + // Result properties + const QString& eventId() const; protected: diff --git a/lib/csapi/room_send.cpp b/lib/csapi/room_send.cpp new file mode 100644 index 00000000..9637a205 --- /dev/null +++ b/lib/csapi/room_send.cpp @@ -0,0 +1,42 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "room_send.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class SendMessageJob::Private +{ + public: + QString eventId; +}; + +SendMessageJob::SendMessageJob(const QString& roomId, const QString& eventType, const QString& txnId, const QJsonObject& body) + : BaseJob(HttpVerb::Put, "SendMessageJob", + basePath % "/rooms/" % roomId % "/send/" % eventType % "/" % txnId) + , d(new Private) +{ + setRequestData(Data(toJson(body))); +} + +SendMessageJob::~SendMessageJob() = default; + +const QString& SendMessageJob::eventId() const +{ + return d->eventId; +} + +BaseJob::Status SendMessageJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->eventId = fromJson<QString>(json.value("event_id")); + return Success; +} + diff --git a/lib/csapi/room_send.h b/lib/csapi/room_send.h new file mode 100644 index 00000000..3bfb48c4 --- /dev/null +++ b/lib/csapi/room_send.h @@ -0,0 +1,33 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QJsonObject> + + +namespace QMatrixClient +{ + // Operations + + class SendMessageJob : public BaseJob + { + public: + explicit SendMessageJob(const QString& roomId, const QString& eventType, const QString& txnId, const QJsonObject& body = {}); + ~SendMessageJob() override; + + // Result properties + + const QString& eventId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/csapi/room_state.cpp b/lib/csapi/room_state.cpp new file mode 100644 index 00000000..39f36afb --- /dev/null +++ b/lib/csapi/room_state.cpp @@ -0,0 +1,70 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "room_state.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class SetRoomStateWithKeyJob::Private +{ + public: + QString eventId; +}; + +SetRoomStateWithKeyJob::SetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey, const QJsonObject& body) + : BaseJob(HttpVerb::Put, "SetRoomStateWithKeyJob", + basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey) + , d(new Private) +{ + setRequestData(Data(toJson(body))); +} + +SetRoomStateWithKeyJob::~SetRoomStateWithKeyJob() = default; + +const QString& SetRoomStateWithKeyJob::eventId() const +{ + return d->eventId; +} + +BaseJob::Status SetRoomStateWithKeyJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->eventId = fromJson<QString>(json.value("event_id")); + return Success; +} + +class SetRoomStateJob::Private +{ + public: + QString eventId; +}; + +SetRoomStateJob::SetRoomStateJob(const QString& roomId, const QString& eventType, const QJsonObject& body) + : BaseJob(HttpVerb::Put, "SetRoomStateJob", + basePath % "/rooms/" % roomId % "/state/" % eventType) + , d(new Private) +{ + setRequestData(Data(toJson(body))); +} + +SetRoomStateJob::~SetRoomStateJob() = default; + +const QString& SetRoomStateJob::eventId() const +{ + return d->eventId; +} + +BaseJob::Status SetRoomStateJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->eventId = fromJson<QString>(json.value("event_id")); + return Success; +} + diff --git a/lib/csapi/room_state.h b/lib/csapi/room_state.h new file mode 100644 index 00000000..5c42b868 --- /dev/null +++ b/lib/csapi/room_state.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QJsonObject> + + +namespace QMatrixClient +{ + // Operations + + class SetRoomStateWithKeyJob : public BaseJob + { + public: + explicit SetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey, const QJsonObject& body = {}); + ~SetRoomStateWithKeyJob() override; + + // Result properties + + const QString& eventId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class SetRoomStateJob : public BaseJob + { + public: + explicit SetRoomStateJob(const QString& roomId, const QString& eventType, const QJsonObject& body = {}); + ~SetRoomStateJob() override; + + // Result properties + + const QString& eventId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/csapi/tags.cpp b/lib/csapi/tags.cpp new file mode 100644 index 00000000..9cd78aec --- /dev/null +++ b/lib/csapi/tags.cpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "tags.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetRoomTagsJob::Private +{ + public: + QJsonObject tags; +}; + +QUrl GetRoomTagsJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& roomId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/user/" % userId % "/rooms/" % roomId % "/tags"); +} + +GetRoomTagsJob::GetRoomTagsJob(const QString& userId, const QString& roomId) + : BaseJob(HttpVerb::Get, "GetRoomTagsJob", + basePath % "/user/" % userId % "/rooms/" % roomId % "/tags") + , d(new Private) +{ +} + +GetRoomTagsJob::~GetRoomTagsJob() = default; + +const QJsonObject& GetRoomTagsJob::tags() const +{ + return d->tags; +} + +BaseJob::Status GetRoomTagsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->tags = fromJson<QJsonObject>(json.value("tags")); + return Success; +} + +SetRoomTagJob::SetRoomTagJob(const QString& userId, const QString& roomId, const QString& tag, const QJsonObject& body) + : BaseJob(HttpVerb::Put, "SetRoomTagJob", + basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag) +{ + setRequestData(Data(toJson(body))); +} + +QUrl DeleteRoomTagJob::makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& roomId, const QString& tag) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag); +} + +DeleteRoomTagJob::DeleteRoomTagJob(const QString& userId, const QString& roomId, const QString& tag) + : BaseJob(HttpVerb::Delete, "DeleteRoomTagJob", + basePath % "/user/" % userId % "/rooms/" % roomId % "/tags/" % tag) +{ +} + diff --git a/lib/csapi/tags.h b/lib/csapi/tags.h new file mode 100644 index 00000000..e437cee8 --- /dev/null +++ b/lib/csapi/tags.h @@ -0,0 +1,61 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QJsonObject> + + +namespace QMatrixClient +{ + // Operations + + class GetRoomTagsJob : public BaseJob + { + public: + explicit GetRoomTagsJob(const QString& userId, const QString& roomId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomTagsJob. This function can be used when + * a URL for GetRoomTagsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& roomId); + + ~GetRoomTagsJob() override; + + // Result properties + + const QJsonObject& tags() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class SetRoomTagJob : public BaseJob + { + public: + explicit SetRoomTagJob(const QString& userId, const QString& roomId, const QString& tag, const QJsonObject& body = {}); + }; + + class DeleteRoomTagJob : public BaseJob + { + public: + explicit DeleteRoomTagJob(const QString& userId, const QString& roomId, const QString& tag); + + /** Construct a URL out of baseUrl and usual parameters passed to + * DeleteRoomTagJob. This function can be used when + * a URL for DeleteRoomTagJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId, const QString& roomId, const QString& tag); + + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/third_party_membership.cpp b/lib/csapi/third_party_membership.cpp index b637d481..b637d481 100644 --- a/lib/jobs/generated/third_party_membership.cpp +++ b/lib/csapi/third_party_membership.cpp diff --git a/lib/jobs/generated/third_party_membership.h b/lib/csapi/third_party_membership.h index c7b5214e..9cf6e6f6 100644 --- a/lib/jobs/generated/third_party_membership.h +++ b/lib/csapi/third_party_membership.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" diff --git a/lib/csapi/to_device.cpp b/lib/csapi/to_device.cpp new file mode 100644 index 00000000..e893fa44 --- /dev/null +++ b/lib/csapi/to_device.cpp @@ -0,0 +1,23 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "to_device.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +SendToDeviceJob::SendToDeviceJob(const QString& eventType, const QString& txnId, const QHash<QString, QHash<QString, QJsonObject>>& messages) + : BaseJob(HttpVerb::Put, "SendToDeviceJob", + basePath % "/sendToDevice/" % eventType % "/" % txnId) +{ + QJsonObject _data; + _data.insert("messages", toJson(messages)); + setRequestData(_data); +} + diff --git a/lib/csapi/to_device.h b/lib/csapi/to_device.h new file mode 100644 index 00000000..7743b883 --- /dev/null +++ b/lib/csapi/to_device.h @@ -0,0 +1,22 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QJsonObject> +#include <QtCore/QHash> + + +namespace QMatrixClient +{ + // Operations + + class SendToDeviceJob : public BaseJob + { + public: + explicit SendToDeviceJob(const QString& eventType, const QString& txnId, const QHash<QString, QHash<QString, QJsonObject>>& messages = {}); + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/typing.cpp b/lib/csapi/typing.cpp index fa700290..fa700290 100644 --- a/lib/jobs/generated/typing.cpp +++ b/lib/csapi/typing.cpp diff --git a/lib/jobs/generated/typing.h b/lib/csapi/typing.h index 0495ed0a..0506c77b 100644 --- a/lib/jobs/generated/typing.h +++ b/lib/csapi/typing.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" diff --git a/lib/csapi/users.cpp b/lib/csapi/users.cpp new file mode 100644 index 00000000..fd2944e4 --- /dev/null +++ b/lib/csapi/users.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "users.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<SearchUserDirectoryJob::User> + { + SearchUserDirectoryJob::User operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + SearchUserDirectoryJob::User result; + result.userId = + fromJson<QString>(o.value("user_id")); + result.displayName = + fromJson<QString>(o.value("display_name")); + result.avatarUrl = + fromJson<QString>(o.value("avatar_url")); + + return result; + } + }; +} // namespace QMatrixClient + +class SearchUserDirectoryJob::Private +{ + public: + QVector<User> results; + bool limited; +}; + +SearchUserDirectoryJob::SearchUserDirectoryJob(const QString& searchTerm, int limit) + : BaseJob(HttpVerb::Post, "SearchUserDirectoryJob", + basePath % "/user_directory/search") + , d(new Private) +{ + QJsonObject _data; + _data.insert("search_term", toJson(searchTerm)); + _data.insert("limit", toJson(limit)); + setRequestData(_data); +} + +SearchUserDirectoryJob::~SearchUserDirectoryJob() = default; + +const QVector<SearchUserDirectoryJob::User>& SearchUserDirectoryJob::results() const +{ + return d->results; +} + +bool SearchUserDirectoryJob::limited() const +{ + return d->limited; +} + +BaseJob::Status SearchUserDirectoryJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("results")) + return { JsonParseError, + "The key 'results' not found in the response" }; + d->results = fromJson<QVector<User>>(json.value("results")); + if (!json.contains("limited")) + return { JsonParseError, + "The key 'limited' not found in the response" }; + d->limited = fromJson<bool>(json.value("limited")); + return Success; +} + diff --git a/lib/csapi/users.h b/lib/csapi/users.h new file mode 100644 index 00000000..85ebd47c --- /dev/null +++ b/lib/csapi/users.h @@ -0,0 +1,46 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include <QtCore/QVector> + +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class SearchUserDirectoryJob : public BaseJob + { + public: + // Inner data structures + + struct User + { + QString userId; + QString displayName; + QString avatarUrl; + }; + + // Construction/destruction + + explicit SearchUserDirectoryJob(const QString& searchTerm, int limit = {}); + ~SearchUserDirectoryJob() override; + + // Result properties + + const QVector<User>& results() const; + bool limited() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient diff --git a/lib/jobs/generated/versions.cpp b/lib/csapi/versions.cpp index 3b03172c..7b55b94f 100644 --- a/lib/jobs/generated/versions.cpp +++ b/lib/csapi/versions.cpp @@ -15,7 +15,7 @@ static const auto basePath = QStringLiteral("/_matrix/client"); class GetVersionsJob::Private { public: - QVector<QString> versions; + QStringList versions; }; QUrl GetVersionsJob::makeRequestUrl(QUrl baseUrl) @@ -33,7 +33,7 @@ GetVersionsJob::GetVersionsJob() GetVersionsJob::~GetVersionsJob() = default; -const QVector<QString>& GetVersionsJob::versions() const +const QStringList& GetVersionsJob::versions() const { return d->versions; } @@ -41,7 +41,7 @@ const QVector<QString>& GetVersionsJob::versions() const BaseJob::Status GetVersionsJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->versions = fromJson<QVector<QString>>(json.value("versions")); + d->versions = fromJson<QStringList>(json.value("versions")); return Success; } diff --git a/lib/jobs/generated/versions.h b/lib/csapi/versions.h index 18f6bb44..c386f0af 100644 --- a/lib/jobs/generated/versions.h +++ b/lib/csapi/versions.h @@ -4,9 +4,9 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" -#include <QtCore/QVector> +#include <QtCore/QStringList> namespace QMatrixClient @@ -16,6 +16,8 @@ namespace QMatrixClient class GetVersionsJob : public BaseJob { public: + explicit GetVersionsJob(); + /** Construct a URL out of baseUrl and usual parameters passed to * GetVersionsJob. This function can be used when * a URL for GetVersionsJob is necessary but the job @@ -23,10 +25,11 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl); - explicit GetVersionsJob(); ~GetVersionsJob() override; - const QVector<QString>& versions() const; + // Result properties + + const QStringList& versions() const; protected: Status parseJson(const QJsonDocument& data) override; diff --git a/lib/jobs/generated/whoami.cpp b/lib/csapi/whoami.cpp index 4c231b5f..4c231b5f 100644 --- a/lib/jobs/generated/whoami.cpp +++ b/lib/csapi/whoami.cpp diff --git a/lib/jobs/generated/whoami.h b/lib/csapi/whoami.h index 835232ee..08fcb5a3 100644 --- a/lib/jobs/generated/whoami.h +++ b/lib/csapi/whoami.h @@ -4,7 +4,7 @@ #pragma once -#include "../basejob.h" +#include "jobs/basejob.h" @@ -15,6 +15,8 @@ namespace QMatrixClient class GetTokenOwnerJob : public BaseJob { public: + explicit GetTokenOwnerJob(); + /** Construct a URL out of baseUrl and usual parameters passed to * GetTokenOwnerJob. This function can be used when * a URL for GetTokenOwnerJob is necessary but the job @@ -22,9 +24,10 @@ namespace QMatrixClient */ static QUrl makeRequestUrl(QUrl baseUrl); - explicit GetTokenOwnerJob(); ~GetTokenOwnerJob() override; + // Result properties + const QString& userId() const; protected: diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache new file mode 100644 index 00000000..d3726f1e --- /dev/null +++ b/lib/csapi/{{base}}.cpp.mustache @@ -0,0 +1,121 @@ +{{#@filePartial}}preamble{{/@filePartial}} +#include "{{filenameBase}}.h" +{{^allModels}} +#include "converters.h" +{{/allModels}}{{#operations}} +{{#producesNonJson?}}#include <QtNetwork/QNetworkReply> +{{/producesNonJson?}}#include <QtCore/QStringBuilder> +{{/operations}} +using namespace QMatrixClient; +{{#models.model}}{{#in?}} +QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod) +{ + QJsonObject o; +{{#vars}} o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}})); +{{/vars}} + return o; +} +{{/in?}}{{#out?}} +{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(const QJsonValue& jv) +{ + const auto& o = jv.toObject(); + {{qualifiedName}} result; + {{#vars}}result.{{nameCamelCase}} = + fromJson<{{dataType.name}}>(o.value("{{baseName}}")); + {{/vars}} + return result; +} +{{/out?}}{{/models.model}}{{#operations}} +static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); +{{# operation}}{{#models}} +namespace QMatrixClient +{ + // Converters +{{#model}}{{#in?}} + QJsonObject toJson(const {{qualifiedName}}& pod) + { + QJsonObject o; +{{#vars}} o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}})); +{{/vars}} + return o; + } +{{/in?}}{{#out?}} + template <> struct FromJson<{{qualifiedName}}> + { + {{qualifiedName}} operator()(const QJsonValue& jv) + { + const auto& o = jv.toObject(); + {{qualifiedName}} result; +{{#vars}} result.{{nameCamelCase}} = + fromJson<{{dataType.qualifiedName}}>(o.value("{{baseName}}")); +{{/vars}} + return result; + } + }; +{{/out?}}{{/model}}} // namespace QMatrixClient +{{/ models}}{{#responses}}{{#normalResponse?}}{{#allProperties?}} +class {{camelCaseOperationId}}Job::Private +{ + public:{{#allProperties}} + {{dataType.name}} {{paramName}};{{/allProperties}} +}; +{{/ allProperties?}}{{/normalResponse?}}{{/responses}}{{#queryParams?}} +BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}}) +{ + BaseJob::Query _q;{{#queryParams}} +{{^required?}}{{#string?}} if (!{{nameCamelCase}}.isEmpty()) + {{/string?}}{{/required?}} _q.addQueryItem("{{baseName}}", {{>paramToString}});{{/queryParams}} + return _q; +} +{{/queryParams?}}{{^bodyParams}} +QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}}) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}}, + queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}); +} +{{/ bodyParams}} +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}}) + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", + basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}}, + queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}{{#skipAuth}}{{#queryParams?}}, + {}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}} + , d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}} +{ +{{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1()); +{{/headerParams}} +{{/headerParams? +}}{{#bodyParams? +}}{{#inlineBody}} setRequestData(Data({{! + }}{{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson? + }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));{{/inlineBody +}}{{^inlineBody}} QJsonObject _data;{{#bodyParams}} +{{^required?}}{{#string?}} if (!{{paramName}}.isEmpty()) + {{/string?}}{{/required?}} _data.insert("{{baseName}}", toJson({{paramName}}));{{/bodyParams}} + setRequestData(_data);{{/inlineBody}} +{{/bodyParams?}}{{#producesNonJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{#@join}}, {{/@join}}{{/produces}} }); +{{/producesNonJson?}}}{{!<- mind the actual brace}} +{{# responses}}{{#normalResponse?}}{{#allProperties?}} +{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default; +{{# allProperties}} +{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}(){{^noCopy?}} const{{/noCopy?}} +{ + return {{#noCopy?}}std::move({{/noCopy?}}d->{{paramName}}{{#noCopy?}}){{/noCopy?}}; +} +{{/ allProperties}}{{#producesNonJson?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply) +{ + {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}"); {{! We don't check for required headers yet }} + {{/headers}}{{#properties}}d->{{paramName}} = reply;{{/properties}} + return Success; +}{{/ producesNonJson?}}{{^producesNonJson?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + {{# properties}}{{#required?}}if (!json.contains("{{baseName}}")) + return { JsonParseError, + "The key '{{baseName}}' not found in the response" }; + {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}")); + {{/ properties}}return Success; +}{{/ producesNonJson?}} +{{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} diff --git a/lib/csapi/{{base}}.h.mustache b/lib/csapi/{{base}}.h.mustache new file mode 100644 index 00000000..a9bed527 --- /dev/null +++ b/lib/csapi/{{base}}.h.mustache @@ -0,0 +1,63 @@ +{{#@filePartial}}preamble{{/@filePartial}} +#pragma once + +{{#operations}}#include "jobs/basejob.h" +{{/operations}} +{{#imports}}#include {{_}} +{{/imports}} +{{#allModels}}#include "converters.h" +{{/allModels}} +namespace QMatrixClient +{ +{{#models}} // Data structures +{{# model}} + struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}} + { +{{#vars}} {{dataType.name}} {{nameCamelCase}}; +{{/vars}} }; +{{#in?}} + QJsonObject toJson(const {{name}}& pod); +{{/in?}}{{#out?}} + template <> struct FromJson<{{name}}> + { + {{name}} operator()(const QJsonValue& jv); + }; +{{/ out?}}{{/model}} +{{/models}}{{#operations}} // Operations +{{# operation}} + class {{camelCaseOperationId}}Job : public BaseJob + { + public:{{#models}} + // Inner data structures +{{# model}} + struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}} + { +{{#vars}} {{dataType.name}} {{nameCamelCase}}; +{{/vars}} }; +{{/ model}} + // Construction/destruction +{{/ models}} + explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}});{{^bodyParams}} + + /** Construct a URL out of baseUrl and usual parameters passed to + * {{camelCaseOperationId}}Job. This function can be used when + * a URL for {{camelCaseOperationId}}Job is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDecl}}{{/allParams}}{{/allParams?}}); +{{/bodyParams}}{{# responses}}{{#normalResponse?}}{{#allProperties?}} + ~{{camelCaseOperationId}}Job() override; + + // Result properties +{{#allProperties}} + {{>maybeCrefType}} {{paramName}}(){{^noCopy?}} const{{/noCopy?}};{{/allProperties}} + + protected: + Status {{#producesNonJson?}}parseReply(QNetworkReply* reply){{/producesNonJson?}}{{^producesNonJson?}}parseJson(const QJsonDocument& data){{/producesNonJson?}} override; + + private: + class Private; + QScopedPointer<Private> d;{{/allProperties?}}{{/normalResponse?}}{{/responses}} + }; +{{/operation}}{{/operations}}{{!skip EOL +}}} // namespace QMatrixClient diff --git a/lib/events/accountdataevents.h b/lib/events/accountdataevents.h index f3ba27bb..11667172 100644 --- a/lib/events/accountdataevents.h +++ b/lib/events/accountdataevents.h @@ -54,8 +54,7 @@ namespace QMatrixClient class _Name : public Event \ { \ public: \ - static constexpr const char* TypeId = _TypeId; \ - static const char* typeId() { return TypeId; } \ + static constexpr const char* typeId() { return _TypeId; } \ explicit _Name(const QJsonObject& obj) \ : Event((_EnumType), obj) \ , _content(contentJson(), QStringLiteral(#_ContentKey)) \ diff --git a/lib/events/directchatevent.h b/lib/events/directchatevent.h index 2b0ad0a0..bd8f2d35 100644 --- a/lib/events/directchatevent.h +++ b/lib/events/directchatevent.h @@ -29,6 +29,6 @@ namespace QMatrixClient QMultiHash<QString, QString> usersToDirectChats() const; - static constexpr const char * TypeId = "m.direct"; + static constexpr const char* typeId() { return "m.direct"; } }; } diff --git a/lib/events/event.cpp b/lib/events/event.cpp index 1d5f1b0d..576e9426 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -76,7 +76,7 @@ template <typename BaseEventT, typename EventT, typename... EventTs> inline event_ptr_tt<BaseEventT> makeIfMatches(const QJsonObject& o, const QString& selector) { - if (selector == EventT::TypeId) + if (selector == EventT::typeId()) return _impl::create<EventT>(o); return makeIfMatches<BaseEventT, EventTs...>(o, selector); @@ -160,14 +160,13 @@ void RoomEvent::addId(const QString& id) template <> RoomEventPtr _impl::doMakeEvent(const QJsonObject& obj) { - return RoomEventPtr { makeIfMatches<RoomEvent, - RoomMessageEvent, RoomNameEvent, RoomAliasesEvent, - RoomCanonicalAliasEvent, RoomMemberEvent, RoomTopicEvent, - RoomAvatarEvent, EncryptionEvent, RedactionEvent> - (obj, obj["type"].toString()) }; -} + // Check more specific event types first + if (auto e = doMakeEvent<StateEventBase>(obj)) + return ptrCast<RoomEvent>(move(e)); -StateEventBase::~StateEventBase() = default; + return makeIfMatches<RoomEvent, + RoomMessageEvent, RedactionEvent>(obj, obj["type"].toString()); +} bool StateEventBase::repeatsState() const { @@ -176,3 +175,13 @@ bool StateEventBase::repeatsState() const .toObject().value("prev_content"); return contentJson == prevContentJson; } + +template<> +StateEventPtr _impl::doMakeEvent<StateEventBase>(const QJsonObject& obj) +{ + return makeIfMatches<StateEventBase, + RoomNameEvent, RoomAliasesEvent, + RoomCanonicalAliasEvent, RoomMemberEvent, RoomTopicEvent, + RoomAvatarEvent, EncryptionEvent>(obj, obj["type"].toString()); + +} diff --git a/lib/events/event.h b/lib/events/event.h index 396406f1..8449c2ec 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -53,7 +53,10 @@ namespace QMatrixClient } template <typename EventT> - event_ptr_tt<EventT> doMakeEvent(const QJsonObject& obj); + inline event_ptr_tt<EventT> doMakeEvent(const QJsonObject& obj) + { + return create<EventT>(obj); + } } class Event @@ -114,7 +117,7 @@ namespace QMatrixClient * parameter type) and create an event object of that type. */ template <typename EventT> - event_ptr_tt<EventT> makeEvent(const QJsonObject& obj) + inline event_ptr_tt<EventT> makeEvent(const QJsonObject& obj) { auto e = _impl::doMakeEvent<EventT>(obj); if (!e) @@ -128,50 +131,17 @@ namespace QMatrixClient EventPtr doMakeEvent<Event>(const QJsonObject& obj); } - template <> struct FromJson<EventPtr> + template <typename EventT> struct FromJson<event_ptr_tt<EventT>> { - EventPtr operator()(const QJsonValue& jv) const + auto operator()(const QJsonValue& jv) const { - return makeEvent<Event>(jv.toObject()); + return makeEvent<EventT>(jv.toObject()); } }; - /** - * \brief A vector of pointers to events with deserialisation capabilities - * - * This is a simple wrapper over a generic vector type that adds - * a convenience method to deserialise events from QJsonArray. - * \tparam EventT base type of all events in the vector - */ template <typename EventT> - class EventsBatch : public std::vector<event_ptr_tt<EventT>> - { - public: - /** - * \brief Deserialise events from an array - * - * Given the following JSON construct, creates events from - * the array stored at key "node": - * \code - * "container": { - * "node": [ { "event_id": "!evt1:srv.org", ... }, ... ] - * } - * \endcode - * \param container - the wrapping JSON object - * \param node - the key in container that holds the array of events - */ - void fromJson(const QJsonObject& container, const QString& node) - { - const auto objs = container.value(node).toArray(); - using size_type = typename std::vector<event_ptr_tt<EventT>>::size_type; - // The below line accommodates the difference in size types of - // STL and Qt containers. - this->reserve(static_cast<size_type>(objs.size())); - for (const auto& objValue: objs) - this->emplace_back(makeEvent<EventT>(objValue.toObject())); - } - }; - using Events = EventsBatch<Event>; + using EventsArray = std::vector<event_ptr_tt<EventT>>; + using Events = EventsArray<Event>; class RedactionEvent; @@ -231,8 +201,9 @@ namespace QMatrixClient event_ptr_tt<RedactionEvent> _redactedBecause; QString _txnId; }; - using RoomEvents = EventsBatch<RoomEvent>; using RoomEventPtr = event_ptr_tt<RoomEvent>; + using RoomEvents = EventsArray<RoomEvent>; + using RoomEventsRange = Range<RoomEvents>; namespace _impl { @@ -240,29 +211,6 @@ namespace QMatrixClient RoomEventPtr doMakeEvent<RoomEvent>(const QJsonObject& obj); } - /** - * Conceptually similar to QStringView (but much more primitive), it's a - * simple abstraction over a pair of RoomEvents::const_iterator values - * referring to the beginning and the end of a range in a RoomEvents - * container. - */ - struct RoomEventsRange - { - RoomEvents::iterator from; - RoomEvents::iterator to; - - RoomEvents::size_type size() const - { - Q_ASSERT(std::distance(from, to) >= 0); - return RoomEvents::size_type(std::distance(from, to)); - } - bool empty() const { return from == to; } - RoomEvents::const_iterator begin() const { return from; } - RoomEvents::const_iterator end() const { return to; } - RoomEvents::iterator begin() { return from; } - RoomEvents::iterator end() { return to; } - }; - class StateEventBase: public RoomEvent { public: @@ -273,10 +221,18 @@ namespace QMatrixClient explicit StateEventBase(Type type) : RoomEvent(type) { } - ~StateEventBase() override = 0; + ~StateEventBase() override = default; virtual bool repeatsState() const; }; + using StateEventPtr = event_ptr_tt<StateEventBase>; + using StateEvents = EventsArray<StateEventBase>; + + namespace _impl + { + template <> + StateEventPtr doMakeEvent<StateEventBase>(const QJsonObject& obj); + } template <typename ContentT> struct Prev diff --git a/lib/events/receiptevent.cpp b/lib/events/receiptevent.cpp index 7555db82..a12f4c05 100644 --- a/lib/events/receiptevent.cpp +++ b/lib/events/receiptevent.cpp @@ -43,7 +43,7 @@ using namespace QMatrixClient; ReceiptEvent::ReceiptEvent(const QJsonObject& obj) : Event(Type::Receipt, obj) { - Q_ASSERT(obj["type"].toString() == TypeId); + Q_ASSERT(obj["type"].toString() == typeId()); const QJsonObject contents = contentJson(); _eventsWithReceipts.reserve(contents.size()); diff --git a/lib/events/receiptevent.h b/lib/events/receiptevent.h index 5b99ae3f..e1d2d1ec 100644 --- a/lib/events/receiptevent.h +++ b/lib/events/receiptevent.h @@ -42,7 +42,7 @@ namespace QMatrixClient EventsWithReceipts eventsWithReceipts() const { return _eventsWithReceipts; } - static constexpr const char* const TypeId = "m.receipt"; + static constexpr const char* typeId() { return "m.receipt"; } private: EventsWithReceipts _eventsWithReceipts; diff --git a/lib/events/redactionevent.h b/lib/events/redactionevent.h index 829b9085..dad54788 100644 --- a/lib/events/redactionevent.h +++ b/lib/events/redactionevent.h @@ -25,7 +25,7 @@ namespace QMatrixClient class RedactionEvent : public RoomEvent { public: - static constexpr const char* const TypeId = "m.room.redaction"; + static constexpr const char* typeId() { return "m.room.redaction"; } explicit RedactionEvent(const QJsonObject& obj) : RoomEvent(Type::Redaction, obj) diff --git a/lib/events/roomavatarevent.h b/lib/events/roomavatarevent.h index ccfe8fbf..0e44ad7c 100644 --- a/lib/events/roomavatarevent.h +++ b/lib/events/roomavatarevent.h @@ -37,7 +37,7 @@ namespace QMatrixClient : StateEvent(Type::RoomAvatar, obj) { } - static constexpr const char* TypeId = "m.room.avatar"; + static constexpr const char* typeId() { return "m.room.avatar"; } }; } // namespace QMatrixClient diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index 89b970c9..8e0cc0a4 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -52,16 +52,18 @@ namespace QMatrixClient { Q_GADGET public: - static constexpr const char* TypeId = "m.room.member"; + static constexpr const char* typeId() { return "m.room.member"; } using MembershipType = MemberEventContent::MembershipType; + explicit RoomMemberEvent(Type type, const QJsonObject& obj) + : StateEvent(type, obj) + { } RoomMemberEvent(MemberEventContent&& c) : StateEvent(Type::RoomMember, c) { } explicit RoomMemberEvent(const QJsonObject& obj) - : StateEvent(Type::RoomMember, obj) -// , _userId(obj["state_key"].toString()) + : RoomMemberEvent(Type::RoomMember, obj) { } MembershipType membership() const { return content().membership; } @@ -72,7 +74,6 @@ namespace QMatrixClient QUrl avatarUrl() const { return content().avatarUrl; } private: -// QString _userId; REGISTER_ENUM(MembershipType) }; } // namespace QMatrixClient diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index a55564ed..dc734b6e 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -65,7 +65,7 @@ namespace QMatrixClient QJsonObject toJson() const; - static constexpr const char* TypeId = "m.room.message"; + static constexpr const char* typeId() { return "m.room.message"; } private: QString _msgtype; diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index 6b0cd51a..d9f403e8 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -28,7 +28,7 @@ namespace QMatrixClient : public StateEvent<EventContent::SimpleContent<_ContentType>> \ { \ public: \ - static constexpr const char* TypeId = _TypeId; \ + static constexpr const char* typeId() { return _TypeId; } \ explicit _Name(const QJsonObject& obj) \ : StateEvent(_EnumType, obj, QStringLiteral(#_ContentKey)) \ { } \ diff --git a/lib/events/typingevent.h b/lib/events/typingevent.h index 8c9551a4..6ccbc1c8 100644 --- a/lib/events/typingevent.h +++ b/lib/events/typingevent.h @@ -27,7 +27,7 @@ namespace QMatrixClient class TypingEvent: public Event { public: - static constexpr const char* const TypeId = "m.typing"; + static constexpr const char* typeId() { return "m.typing"; } TypingEvent(const QJsonObject& obj); diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 56565859..2d41650a 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -25,7 +25,6 @@ #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> #include <QtCore/QRegularExpression> -//#include <QtCore/QStringBuilder> #include <array> diff --git a/lib/jobs/downloadfilejob.h b/lib/jobs/downloadfilejob.h index 1815a7c8..ce47ab1c 100644 --- a/lib/jobs/downloadfilejob.h +++ b/lib/jobs/downloadfilejob.h @@ -1,6 +1,6 @@ #pragma once -#include "generated/content-repo.h" +#include "csapi/content-repo.h" namespace QMatrixClient { diff --git a/lib/jobs/generated/create_room.cpp b/lib/jobs/generated/create_room.cpp deleted file mode 100644 index 6e582791..00000000 --- a/lib/jobs/generated/create_room.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "create_room.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -CreateRoomJob::Invite3pid::operator QJsonObject() const -{ - QJsonObject o; - o.insert("id_server", toJson(idServer)); - o.insert("medium", toJson(medium)); - o.insert("address", toJson(address)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<CreateRoomJob::Invite3pid> - { - CreateRoomJob::Invite3pid operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - CreateRoomJob::Invite3pid result; - result.idServer = - fromJson<QString>(o.value("id_server")); - result.medium = - fromJson<QString>(o.value("medium")); - result.address = - fromJson<QString>(o.value("address")); - - return result; - } - }; -} // namespace QMatrixClient - -CreateRoomJob::StateEvent::operator QJsonObject() const -{ - QJsonObject o; - o.insert("type", toJson(type)); - o.insert("state_key", toJson(stateKey)); - o.insert("content", toJson(content)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<CreateRoomJob::StateEvent> - { - CreateRoomJob::StateEvent operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - CreateRoomJob::StateEvent result; - result.type = - fromJson<QString>(o.value("type")); - result.stateKey = - fromJson<QString>(o.value("state_key")); - result.content = - fromJson<QJsonObject>(o.value("content")); - - return result; - } - }; -} // namespace QMatrixClient - -class CreateRoomJob::Private -{ - public: - QString roomId; -}; - -CreateRoomJob::CreateRoomJob(const QString& visibility, const QString& roomAliasName, const QString& name, const QString& topic, const QVector<QString>& invite, const QVector<Invite3pid>& invite3pid, const QJsonObject& creationContent, const QVector<StateEvent>& initialState, const QString& preset, bool isDirect, bool guestCanJoin) - : BaseJob(HttpVerb::Post, "CreateRoomJob", - basePath % "/createRoom") - , d(new Private) -{ - QJsonObject _data; - if (!visibility.isEmpty()) - _data.insert("visibility", toJson(visibility)); - if (!roomAliasName.isEmpty()) - _data.insert("room_alias_name", toJson(roomAliasName)); - if (!name.isEmpty()) - _data.insert("name", toJson(name)); - if (!topic.isEmpty()) - _data.insert("topic", toJson(topic)); - _data.insert("invite", toJson(invite)); - _data.insert("invite_3pid", toJson(invite3pid)); - _data.insert("creation_content", toJson(creationContent)); - _data.insert("initial_state", toJson(initialState)); - if (!preset.isEmpty()) - _data.insert("preset", toJson(preset)); - _data.insert("is_direct", toJson(isDirect)); - _data.insert("guest_can_join", toJson(guestCanJoin)); - setRequestData(_data); -} - -CreateRoomJob::~CreateRoomJob() = default; - -const QString& CreateRoomJob::roomId() const -{ - return d->roomId; -} - -BaseJob::Status CreateRoomJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id")); - return Success; -} - diff --git a/lib/jobs/joinroomjob.cpp b/lib/jobs/joinroomjob.cpp deleted file mode 100644 index 66a75089..00000000 --- a/lib/jobs/joinroomjob.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "joinroomjob.h" -#include "util.h" - -using namespace QMatrixClient; - -class JoinRoomJob::Private -{ - public: - QString roomId; -}; - -JoinRoomJob::JoinRoomJob(const QString& roomAlias) - : BaseJob(HttpVerb::Post, "JoinRoomJob", - QStringLiteral("_matrix/client/r0/join/%1").arg(roomAlias)) - , d(new Private) -{ -} - -JoinRoomJob::~JoinRoomJob() -{ - delete d; -} - -QString JoinRoomJob::roomId() -{ - return d->roomId; -} - -BaseJob::Status JoinRoomJob::parseJson(const QJsonDocument& data) -{ - QJsonObject json = data.object(); - if( json.contains("room_id") ) - { - d->roomId = json.value("room_id").toString(); - return Success; - } - - qCDebug(JOBS) << data; - return { UserDefinedError, "No room_id in the JSON response" }; -} diff --git a/lib/jobs/joinroomjob.h b/lib/jobs/joinroomjob.h deleted file mode 100644 index f3ba216f..00000000 --- a/lib/jobs/joinroomjob.h +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -namespace QMatrixClient -{ - class JoinRoomJob: public BaseJob - { - public: - explicit JoinRoomJob(const QString& roomAlias); - virtual ~JoinRoomJob(); - - QString roomId(); - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - Private* d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/mediathumbnailjob.h b/lib/jobs/mediathumbnailjob.h index 6e0b94f3..7963796e 100644 --- a/lib/jobs/mediathumbnailjob.h +++ b/lib/jobs/mediathumbnailjob.h @@ -18,7 +18,7 @@ #pragma once -#include "generated/content-repo.h" +#include "csapi/content-repo.h" #include <QtGui/QPixmap> diff --git a/lib/jobs/roommessagesjob.cpp b/lib/jobs/roommessagesjob.cpp deleted file mode 100644 index e5568f17..00000000 --- a/lib/jobs/roommessagesjob.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "roommessagesjob.h" - -using namespace QMatrixClient; - -class RoomMessagesJob::Private -{ - public: - RoomEvents events; - QString end; -}; - -RoomMessagesJob::RoomMessagesJob(const QString& roomId, const QString& from, - int limit, FetchDirection dir) - : BaseJob(HttpVerb::Get, "RoomMessagesJob", - QStringLiteral("/_matrix/client/r0/rooms/%1/messages").arg(roomId), - Query( - { { "from", from } - , { "dir", dir == FetchDirection::Backward ? "b" : "f" } - , { "limit", QString::number(limit) } - })) - , d(new Private) -{ - qCDebug(JOBS) << "Room messages query:" << query().toString(QUrl::PrettyDecoded); -} - -RoomMessagesJob::~RoomMessagesJob() -{ - delete d; -} - -RoomEvents&& RoomMessagesJob::releaseEvents() -{ - return move(d->events); -} - -QString RoomMessagesJob::end() const -{ - return d->end; -} - -BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data) -{ - const auto obj = data.object(); - d->events.fromJson(obj, "chunk"); - d->end = obj.value("end").toString(); - return Success; -} diff --git a/lib/jobs/roommessagesjob.h b/lib/jobs/roommessagesjob.h deleted file mode 100644 index 7b3fd9c9..00000000 --- a/lib/jobs/roommessagesjob.h +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -#include "../events/event.h" - -namespace QMatrixClient -{ - enum class FetchDirection { Backward, Forward }; - - class RoomMessagesJob: public BaseJob - { - public: - RoomMessagesJob(const QString& roomId, const QString& from, - int limit = 10, - FetchDirection dir = FetchDirection::Backward); - virtual ~RoomMessagesJob(); - - RoomEvents&& releaseEvents(); - QString end() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - Private* d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/sendeventjob.h b/lib/jobs/sendeventjob.h index 3a11eb6a..a3e9a291 100644 --- a/lib/jobs/sendeventjob.h +++ b/lib/jobs/sendeventjob.h @@ -32,7 +32,7 @@ namespace QMatrixClient SendEventJob(const QString& roomId, const EvT& event) : BaseJob(HttpVerb::Put, QStringLiteral("SendEventJob"), QStringLiteral("_matrix/client/r0/rooms/%1/send/%2/") - .arg(roomId, EvT::TypeId), // See also beforeStart() + .arg(roomId, EvT::typeId()), // See also beforeStart() Query(), Data(event.toJson())) { } diff --git a/lib/jobs/setroomstatejob.cpp b/lib/jobs/setroomstatejob.cpp deleted file mode 100644 index c2beb87b..00000000 --- a/lib/jobs/setroomstatejob.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "setroomstatejob.h" - -using namespace QMatrixClient; - -BaseJob::Status SetRoomStateJob::parseJson(const QJsonDocument& data) -{ - _eventId = data.object().value("event_id").toString(); - if (!_eventId.isEmpty()) - return Success; - - qCDebug(JOBS) << data; - return { UserDefinedError, "No event_id in the JSON response" }; -} - diff --git a/lib/jobs/setroomstatejob.h b/lib/jobs/setroomstatejob.h deleted file mode 100644 index b7e6d4a1..00000000 --- a/lib/jobs/setroomstatejob.h +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -#include "connectiondata.h" - -namespace QMatrixClient -{ - class SetRoomStateJob: public BaseJob - { - public: - /** - * Constructs a job that sets a state using an arbitrary room event - * with a state key. - */ - template <typename EvT> - SetRoomStateJob(const QString& roomId, const QString& stateKey, - const EvT& event) - : BaseJob(HttpVerb::Put, "SetRoomStateJob", - QStringLiteral("_matrix/client/r0/rooms/%1/state/%2/%3") - .arg(roomId, EvT::TypeId, stateKey), - Query(), - Data(event.toJson())) - { } - /** - * Constructs a job that sets a state using an arbitrary room event - * without a state key. - */ - template <typename EvT> - SetRoomStateJob(const QString& roomId, const EvT& event) - : BaseJob(HttpVerb::Put, "SetRoomStateJob", - QStringLiteral("_matrix/client/r0/rooms/%1/state/%2") - .arg(roomId, EvT::TypeId), - Query(), - Data(event.toJson())) - { } - - QString eventId() const { return _eventId; } - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - QString _eventId; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/syncjob.cpp b/lib/jobs/syncjob.cpp index 435dfd0e..a739ea0d 100644 --- a/lib/jobs/syncjob.cpp +++ b/lib/jobs/syncjob.cpp @@ -54,11 +54,17 @@ SyncDataList&& SyncData::takeRoomData() return std::move(roomData); } -SyncBatch<Event>&& SyncData::takeAccountData() +Events&& SyncData::takeAccountData() { return std::move(accountData); } +template <typename EventsArrayT, typename StrT> +inline EventsArrayT load(const QJsonObject& batches, StrT keyName) +{ + return fromJson<EventsArrayT>(batches[keyName].toObject().value("events")); +} + BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { return d.parseJson(data); @@ -71,7 +77,7 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data) auto json = data.object(); nextBatch_ = json.value("next_batch").toString(); // TODO: presence - accountData.fromJson(json); + accountData = load<Events>(json, "account_data"); QJsonObject rooms = json.value("rooms").toObject(); JoinStates::Int ii = 1; // ii is used to make a JoinState value @@ -96,33 +102,26 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const QJsonObject& room_) : roomId(roomId_) , joinState(joinState_) - , state(joinState == JoinState::Invite ? "invite_state" : "state") - , timeline("timeline") - , ephemeral("ephemeral") - , accountData("account_data") + , state(load<StateEvents>(room_, + joinState == JoinState::Invite ? "invite_state" : "state")) { switch (joinState) { - case JoinState::Invite: - state.fromJson(room_); - break; case JoinState::Join: - state.fromJson(room_); - timeline.fromJson(room_); - ephemeral.fromJson(room_); - accountData.fromJson(room_); - break; + ephemeral = load<Events>(room_, "ephemeral"); + accountData = load<Events>(room_, "account_data"); + // [[fallthrough]] case JoinState::Leave: - state.fromJson(room_); - timeline.fromJson(room_); + { + timeline = load<RoomEvents>(room_, "timeline"); + auto timelineJson = room_.value("timeline").toObject(); + timelineLimited = timelineJson.value("limited").toBool(); + timelinePrevBatch = timelineJson.value("prev_batch").toString(); + break; - default: - qCWarning(SYNCJOB) << "SyncRoomData: Unknown JoinState value, ignoring:" << int(joinState); + } + default: /* nothing on top of state */; } - auto timelineJson = room_.value("timeline").toObject(); - timelineLimited = timelineJson.value("limited").toBool(); - timelinePrevBatch = timelineJson.value("prev_batch").toString(); - auto unreadJson = room_.value("unread_notifications").toObject(); unreadCount = unreadJson.value(UnreadCountKey).toInt(-2); highlightCount = unreadJson.value("highlight_count").toInt(); diff --git a/lib/jobs/syncjob.h b/lib/jobs/syncjob.h index 919060be..b12f9fff 100644 --- a/lib/jobs/syncjob.h +++ b/lib/jobs/syncjob.h @@ -26,30 +26,15 @@ namespace QMatrixClient { - template <typename EventT> - class SyncBatch : public EventsBatch<EventT> - { - public: - explicit SyncBatch(QString k) : jsonKey(std::move(k)) { } - void fromJson(const QJsonObject& roomContents) - { - EventsBatch<EventT>::fromJson( - roomContents[jsonKey].toObject(), "events"); - } - - private: - QString jsonKey; - }; - class SyncRoomData { public: QString roomId; JoinState joinState; - SyncBatch<RoomEvent> state; - SyncBatch<RoomEvent> timeline; - SyncBatch<Event> ephemeral; - SyncBatch<Event> accountData; + StateEvents state; + RoomEvents timeline; + Events ephemeral; + Events accountData; bool timelineLimited; QString timelinePrevBatch; @@ -71,13 +56,13 @@ namespace QMatrixClient { public: BaseJob::Status parseJson(const QJsonDocument &data); - SyncBatch<Event>&& takeAccountData(); + Events&& takeAccountData(); SyncDataList&& takeRoomData(); QString nextBatch() const; private: QString nextBatch_; - SyncBatch<Event> accountData { "account_data" }; + Events accountData; SyncDataList roomData; }; diff --git a/lib/room.cpp b/lib/room.cpp index a4cfadb4..5f2e3088 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -18,14 +18,15 @@ #include "room.h" -#include "jobs/generated/kicking.h" -#include "jobs/generated/inviting.h" -#include "jobs/generated/banning.h" -#include "jobs/generated/leaving.h" -#include "jobs/generated/receipts.h" -#include "jobs/generated/redaction.h" -#include "jobs/generated/account-data.h" -#include "jobs/setroomstatejob.h" +#include "csapi/kicking.h" +#include "csapi/inviting.h" +#include "csapi/banning.h" +#include "csapi/leaving.h" +#include "csapi/receipts.h" +#include "csapi/redaction.h" +#include "csapi/account-data.h" +#include "csapi/message_pagination.h" +#include "csapi/room_state.h" #include "events/simplestateevents.h" #include "events/roomavatarevent.h" #include "events/roommemberevent.h" @@ -33,7 +34,6 @@ #include "events/receiptevent.h" #include "events/redactionevent.h" #include "jobs/sendeventjob.h" -#include "jobs/roommessagesjob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" #include "jobs/postreadmarkersjob.h" @@ -112,7 +112,7 @@ class Room::Private TagsMap tags; QHash<QString, AccountDataMap> accountData; QString prevBatch; - QPointer<RoomMessagesJob> roomMessagesJob; + QPointer<GetRoomEventsJob> eventsHistoryJob; struct FileTransferPrivateInfo { @@ -199,13 +199,27 @@ class Room::Private void markMessagesAsRead(rev_iter_t upToMarker); + template <typename EvT> + auto requestSetState(const QString& stateKey, const EvT& event) + { + return connection->callApi<SetRoomStateWithKeyJob>( + id, EvT::typeId(), stateKey, event.toJson()); + } + + template <typename EvT> + auto requestSetState(const EvT& event) + { + return connection->callApi<SetRoomStateJob>( + id, EvT::typeId(), event.toJson()); + } + /** * @brief Apply redaction to the timeline * * Tries to find an event in the timeline and redact it; deletes the * redaction event whether the redacted event was found or not. */ - void processRedaction(RoomEventPtr&& redactionEvent); + void processRedaction(event_ptr_tt<RedactionEvent>&& redaction); void broadcastTagUpdates() { @@ -1036,21 +1050,31 @@ void Room::updateData(SyncRoomData&& data) for (auto&& event: data.accountData) processAccountDataEvent(move(event)); + bool emitNamesChanged = false; if (!data.state.empty()) { et.restart(); - processStateEvents(data.state); - qCDebug(PROFILER) << "*** Room::processStateEvents(state):" + for (const auto& e: data.state) + emitNamesChanged |= processStateEvent(*e); + + qCDebug(PROFILER) << "*** Room::processStateEvents():" << data.state.size() << "event(s)," << et; } if (!data.timeline.empty()) { et.restart(); // State changes can arrive in a timeline event; so check those. - processStateEvents(data.timeline); + for (const auto& e: data.timeline) + emitNamesChanged |= processStateEvent(*e); qCDebug(PROFILER) << "*** Room::processStateEvents(timeline):" << data.timeline.size() << "event(s)," << et; + } + if (emitNamesChanged) + emit namesChanged(this); + d->updateDisplayname(); + if (!data.timeline.empty()) + { et.restart(); d->addNewMessageEvents(move(data.timeline)); qCDebug(PROFILER) << "*** Room::addNewMessageEvents():" << et; @@ -1100,19 +1124,17 @@ void Room::postMessage(const RoomMessageEvent& event) void Room::setName(const QString& newName) { - connection()->callApi<SetRoomStateJob>(id(), RoomNameEvent(newName)); + d->requestSetState(RoomNameEvent(newName)); } void Room::setCanonicalAlias(const QString& newAlias) { - connection()->callApi<SetRoomStateJob>(id(), - RoomCanonicalAliasEvent(newAlias)); + d->requestSetState(RoomCanonicalAliasEvent(newAlias)); } void Room::setTopic(const QString& newTopic) { - RoomTopicEvent evt(newTopic); - connection()->callApi<SetRoomStateJob>(id(), evt); + d->requestSetState(RoomTopicEvent(newTopic)); } void Room::getPreviousContent(int limit) @@ -1122,13 +1144,13 @@ void Room::getPreviousContent(int limit) void Room::Private::getPreviousContent(int limit) { - if( !isJobRunning(roomMessagesJob) ) + if( !isJobRunning(eventsHistoryJob) ) { - roomMessagesJob = - connection->callApi<RoomMessagesJob>(id, prevBatch, limit); - connect( roomMessagesJob, &RoomMessagesJob::success, [=] { - prevBatch = roomMessagesJob->end(); - addHistoricalMessageEvents(roomMessagesJob->releaseEvents()); + eventsHistoryJob = + connection->callApi<GetRoomEventsJob>(id, prevBatch, "b", "", limit); + connect( eventsHistoryJob, &BaseJob::success, q, [=] { + prevBatch = eventsHistoryJob->end(); + addHistoricalMessageEvents(eventsHistoryJob->chunk()); }); } } @@ -1143,6 +1165,11 @@ LeaveRoomJob* Room::leaveRoom() return connection()->callApi<LeaveRoomJob>(id()); } +SetRoomStateWithKeyJob*Room::setMemberState(const QString& memberId, const RoomMemberEvent& event) const +{ + return d->requestSetState(memberId, event); +} + void Room::kickMember(const QString& memberId, const QString& reason) { connection()->callApi<KickJob>(id(), memberId, reason); @@ -1287,11 +1314,8 @@ inline bool isRedaction(const RoomEventPtr& e) return e->type() == EventType::Redaction; } -void Room::Private::processRedaction(RoomEventPtr&& redactionEvent) +void Room::Private::processRedaction(event_ptr_tt<RedactionEvent>&& redaction) { - Q_ASSERT(redactionEvent && isRedaction(redactionEvent)); - const auto& redaction = ptrCast<RedactionEvent>(move(redactionEvent)); - const auto pIdx = eventsIndex.find(redaction->redactedEvent()); if (pIdx == eventsIndex.end()) { @@ -1385,7 +1409,7 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) const auto normalsBegin = stable_partition(events.begin(), events.end(), isRedaction); RoomEventsRange redactions { events.begin(), normalsBegin }, - normalEvents { normalsBegin, events.end() }; + normalEvents { normalsBegin, events.end() }; if (!normalEvents.empty()) emit q->aboutToAddNewMessages(normalEvents); @@ -1399,7 +1423,10 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) q->onAddNewTimelineEvents(from); } for (auto&& r: redactions) - processRedaction(move(r)); + { + Q_ASSERT(isRedaction(r)); + processRedaction(ptrCast<RedactionEvent>(move(r))); + } if (insertedSize > 0) { emit q->addedMessages(); @@ -1450,107 +1477,95 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events) Q_ASSERT(timeline.size() == timelineSize + insertedSize); } -void Room::processStateEvents(const RoomEvents& events) +bool Room::processStateEvent(const RoomEvent& e) { - bool emitNamesChanged = false; - for (const auto& e: events) + switch (e.type()) { - switch (e->type()) - { - case EventType::RoomName: { - auto* nameEvent = weakPtr<const RoomNameEvent>(e); - d->name = nameEvent->name(); - qCDebug(MAIN) << "Room name updated:" << d->name; - emitNamesChanged = true; - break; - } - case EventType::RoomAliases: { - auto* aliasesEvent = weakPtr<const RoomAliasesEvent>(e); - d->aliases = aliasesEvent->aliases(); - qCDebug(MAIN) << "Room aliases updated:" << d->aliases; - emitNamesChanged = true; - break; - } - case EventType::RoomCanonicalAlias: { - auto* aliasEvent = weakPtr<const RoomCanonicalAliasEvent>(e); - d->canonicalAlias = aliasEvent->alias(); - setObjectName(d->canonicalAlias); - qCDebug(MAIN) << "Room canonical alias updated:" << d->canonicalAlias; - emitNamesChanged = true; - break; - } - case EventType::RoomTopic: { - auto* topicEvent = weakPtr<const RoomTopicEvent>(e); - d->topic = topicEvent->topic(); - qCDebug(MAIN) << "Room topic updated:" << d->topic; - emit topicChanged(); - break; + case EventType::RoomName: { + d->name = static_cast<const RoomNameEvent&>(e).name(); + qCDebug(MAIN) << "Room name updated:" << d->name; + return true; + } + case EventType::RoomAliases: { + d->aliases = static_cast<const RoomAliasesEvent&>(e).aliases(); + qCDebug(MAIN) << "Room aliases updated:" << d->aliases; + return true; + } + case EventType::RoomCanonicalAlias: { + d->canonicalAlias = + static_cast<const RoomCanonicalAliasEvent&>(e).alias(); + setObjectName(d->canonicalAlias); + qCDebug(MAIN) << "Room canonical alias updated:" << d->canonicalAlias; + return true; + } + case EventType::RoomTopic: { + d->topic = static_cast<const RoomTopicEvent&>(e).topic(); + qCDebug(MAIN) << "Room topic updated:" << d->topic; + emit topicChanged(); + return false; + } + case EventType::RoomAvatar: { + const auto& avatarEventContent = + static_cast<const RoomAvatarEvent&>(e).content(); + if (d->avatar.updateUrl(avatarEventContent.url)) + { + qCDebug(MAIN) << "Room avatar URL updated:" + << avatarEventContent.url.toString(); + emit avatarChanged(); } - case EventType::RoomAvatar: { - const auto& avatarEventContent = - weakPtr<const RoomAvatarEvent>(e)->content(); - if (d->avatar.updateUrl(avatarEventContent.url)) + return false; + } + case EventType::RoomMember: { + const auto& memberEvent = static_cast<const RoomMemberEvent&>(e); + auto* u = user(memberEvent.userId()); + u->processEvent(memberEvent, this); + if (u == localUser() && memberJoinState(u) == JoinState::Invite + && memberEvent.isDirect()) + connection()->addToDirectChats(this, + user(memberEvent.senderId())); + + if( memberEvent.membership() == MembershipType::Join ) + { + if (memberJoinState(u) != JoinState::Join) { - qCDebug(MAIN) << "Room avatar URL updated:" - << avatarEventContent.url.toString(); - emit avatarChanged(); + d->insertMemberIntoMap(u); + connect(u, &User::nameAboutToChange, this, + [=] (QString newName, QString, const Room* context) { + if (context == this) + emit memberAboutToRename(u, newName); + }); + connect(u, &User::nameChanged, this, + [=] (QString, QString oldName, const Room* context) { + if (context == this) + d->renameMember(u, oldName); + }); + emit userAdded(u); } - break; } - case EventType::RoomMember: { - auto* memberEvent = weakPtr<const RoomMemberEvent>(e); - auto u = user(memberEvent->userId()); - u->processEvent(memberEvent, this); - if (u == localUser() && memberJoinState(u) == JoinState::Invite - && memberEvent->isDirect()) - connection()->addToDirectChats(this, - user(memberEvent->senderId())); - - if( memberEvent->membership() == MembershipType::Join ) - { - if (memberJoinState(u) != JoinState::Join) - { - d->insertMemberIntoMap(u); - connect(u, &User::nameAboutToChange, this, - [=] (QString newName, QString, const Room* context) { - if (context == this) - emit memberAboutToRename(u, newName); - }); - connect(u, &User::nameChanged, this, - [=] (QString, QString oldName, const Room* context) { - if (context == this) - d->renameMember(u, oldName); - }); - emit userAdded(u); - } - } - else if( memberEvent->membership() == MembershipType::Leave ) + else if( memberEvent.membership() == MembershipType::Leave ) + { + if (memberJoinState(u) == JoinState::Join) { - if (memberJoinState(u) == JoinState::Join) - { - if (!d->membersLeft.contains(u)) - d->membersLeft.append(u); - d->removeMemberFromMap(u->name(this), u); - emit userRemoved(u); - } + if (!d->membersLeft.contains(u)) + d->membersLeft.append(u); + d->removeMemberFromMap(u->name(this), u); + emit userRemoved(u); } - break; - } - case EventType::RoomEncryption: - { - d->encryptionAlgorithm = - weakPtr<const EncryptionEvent>(e)->algorithm(); - qCDebug(MAIN) << "Encryption switched on in" << displayName(); - emit encryption(); - break; } - default: /* Ignore events of other types */; + return false; } + case EventType::RoomEncryption: + { + d->encryptionAlgorithm = + static_cast<const EncryptionEvent&>(e).algorithm(); + qCDebug(MAIN) << "Encryption switched on in" << displayName(); + emit encryption(); + return false; + } + default: + /* Ignore events of other types */ + return false; } - if (emitNamesChanged) { - emit namesChanged(this); - } - d->updateDisplayname(); } void Room::processEphemeralEvent(EventPtr&& event) @@ -1776,7 +1791,7 @@ void appendEvent(QJsonArray& events, const QString& type, template <typename EvtT> void appendEvent(QJsonArray& events, const EvtT& event) { - appendEvent(events, EvtT::TypeId, event.toJson()); + appendEvent(events, EvtT::typeId(), event.toJson()); } QJsonObject Room::Private::toJson() const @@ -32,10 +32,12 @@ namespace QMatrixClient { class Event; + class RoomMemberEvent; class Connection; class User; class MemberSorter; class LeaveRoomJob; + class SetRoomStateWithKeyJob; class RedactEventJob; class TimelineItem @@ -344,6 +346,8 @@ namespace QMatrixClient void inviteToRoom(const QString& memberId); LeaveRoomJob* leaveRoom(); + SetRoomStateWithKeyJob* setMemberState( + const QString& memberId, const RoomMemberEvent& event) const; void kickMember(const QString& memberId, const QString& reason = {}); void ban(const QString& userId, const QString& reason = {}); void unban(const QString& userId); @@ -408,13 +412,14 @@ namespace QMatrixClient void fileTransferCancelled(QString id); protected: - virtual void processStateEvents(const RoomEvents& events); + /// Returns true if any of room names/aliases has changed + virtual bool processStateEvent(const RoomEvent& e); virtual void processEphemeralEvent(EventPtr&& event); virtual void processAccountDataEvent(EventPtr&& event); - virtual void onAddNewTimelineEvents(timeline_iter_t from) { } - virtual void onAddHistoricalTimelineEvents(rev_iter_t from) { } - virtual void onRedaction(const RoomEvent& prevEvent, - const RoomEvent& after) { } + virtual void onAddNewTimelineEvents(timeline_iter_t /*from*/) { } + virtual void onAddHistoricalTimelineEvents(rev_iter_t /*from*/) { } + virtual void onRedaction(const RoomEvent& /*prevEvent*/, + const RoomEvent& /*after*/) { } private: class Private; diff --git a/lib/user.cpp b/lib/user.cpp index 91b340d5..025d669c 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -23,9 +23,9 @@ #include "avatar.h" #include "events/event.h" #include "events/roommemberevent.h" -#include "jobs/setroomstatejob.h" -#include "jobs/generated/profile.h" -#include "jobs/generated/content-repo.h" +#include "csapi/room_state.h" +#include "csapi/profile.h" +#include "csapi/content-repo.h" #include <QtCore/QTimer> #include <QtCore/QRegularExpression> @@ -277,8 +277,7 @@ void User::rename(const QString& newName, const Room* r) "Attempt to rename a user that's not a room member"); MemberEventContent evtC; evtC.displayName = newName; - auto job = d->connection->callApi<SetRoomStateJob>( - r->id(), id(), RoomMemberEvent(move(evtC))); + auto job = r->setMemberState(id(), RoomMemberEvent(move(evtC))); connect(job, &BaseJob::success, this, [=] { updateName(newName, r); }); } @@ -358,19 +357,20 @@ QUrl User::avatarUrl(const Room* room) const return avatarObject(room).url(); } -void User::processEvent(const RoomMemberEvent* event, const Room* room) +void User::processEvent(const RoomMemberEvent& event, const Room* room) { - if (event->membership() != MembershipType::Invite && - event->membership() != MembershipType::Join) + Q_ASSERT(room); + if (event.membership() != MembershipType::Invite && + event.membership() != MembershipType::Join) return; auto aboutToEnter = room->memberJoinState(this) == JoinState::Leave && - (event->membership() == MembershipType::Join || - event->membership() == MembershipType::Invite); + (event.membership() == MembershipType::Join || + event.membership() == MembershipType::Invite); if (aboutToEnter) ++d->totalRooms; - auto newName = event->displayName(); + auto newName = event.displayName(); // `bridged` value uses the same notification signal as the name; // it is assumed that first setting of the bridge occurs together with // the first setting of the name, and further bridge updates are @@ -390,17 +390,17 @@ void User::processEvent(const RoomMemberEvent* event, const Room* room) } newName.truncate(match.capturedStart(0)); } - if (event->prevContent()) + if (event.prevContent()) { // FIXME: the hint doesn't work for bridged users auto oldNameHint = - d->nameForRoom(room, event->prevContent()->displayName); + d->nameForRoom(room, event.prevContent()->displayName); updateName(newName, oldNameHint, room); - updateAvatarUrl(event->avatarUrl(), - d->avatarUrlForRoom(room, event->prevContent()->avatarUrl), + updateAvatarUrl(event.avatarUrl(), + d->avatarUrlForRoom(room, event.prevContent()->avatarUrl), room); } else { updateName(newName, room); - updateAvatarUrl(event->avatarUrl(), d->avatarUrlForRoom(room), room); + updateAvatarUrl(event.avatarUrl(), d->avatarUrlForRoom(room), room); } } @@ -103,8 +103,7 @@ namespace QMatrixClient QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; - void processEvent(const RoomMemberEvent* event, - const Room* r = nullptr); + void processEvent(const RoomMemberEvent& event, const Room* r); public slots: void rename(const QString& newName); @@ -58,6 +58,37 @@ namespace QMatrixClient static void qAsConst(const T &&) Q_DECL_EQ_DELETE; #endif + /** An abstraction over a pair of iterators + * This is a very basic range type over a container with iterators that + * are at least ForwardIterators. Inspired by Ranges TS. + */ + template <typename ArrayT> + class Range + { + // Looking forward for Ranges TS to produce something (in C++23?..) + using iterator = typename ArrayT::iterator; + using const_iterator = typename ArrayT::const_iterator; + using size_type = typename ArrayT::size_type; + public: + Range(ArrayT& arr) : from(std::begin(arr)), to(std::end(arr)) { } + Range(iterator from, iterator to) : from(from), to(to) { } + + size_type size() const + { + Q_ASSERT(std::distance(from, to) >= 0); + return size_type(std::distance(from, to)); + } + bool empty() const { return from == to; } + const_iterator begin() const { return from; } + const_iterator end() const { return to; } + iterator begin() { return from; } + iterator end() { return to; } + + private: + iterator from; + iterator to; + }; + /** A guard pointer that disconnects an interested object upon destruction * It's almost QPointer<> except that you have to initialise it with one * more additional parameter - a pointer to a QObject that will be |