diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/basejob.cpp | 14 | ||||
-rw-r--r-- | jobs/basejob.h | 1 | ||||
-rw-r--r-- | jobs/generated/leaving.cpp | 30 | ||||
-rw-r--r-- | jobs/generated/leaving.h | 31 | ||||
-rw-r--r-- | jobs/generated/logout.cpp | 22 | ||||
-rw-r--r-- | jobs/generated/logout.h | 24 | ||||
-rw-r--r-- | jobs/generated/profile.cpp | 144 | ||||
-rw-r--r-- | jobs/generated/profile.h | 80 | ||||
-rw-r--r-- | jobs/leaveroomjob.cpp | 26 | ||||
-rw-r--r-- | jobs/leaveroomjob.h | 30 | ||||
-rw-r--r-- | jobs/logoutjob.cpp | 26 | ||||
-rw-r--r-- | jobs/logoutjob.h | 30 | ||||
-rw-r--r-- | jobs/sendeventjob.cpp | 2 | ||||
-rw-r--r-- | jobs/sendeventjob.h | 4 | ||||
-rw-r--r-- | jobs/setroomstatejob.h | 8 | ||||
-rw-r--r-- | jobs/syncjob.cpp | 12 |
16 files changed, 351 insertions, 133 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index 240192d9..7794337e 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -24,7 +24,7 @@ #include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> -//#include <QtCore/QStringBuilder> +#include <QtCore/QRegularExpression> #include <array> @@ -79,6 +79,13 @@ inline QDebug operator<<(QDebug dbg, const BaseJob* j) return dbg << j->objectName(); } +QDebug QMatrixClient::operator<<(QDebug dbg, const BaseJob::Status& s) +{ + QRegularExpression filter { "(access_token)=[-_A-Za-z0-9]+" }; + return dbg << s.code << ':' + << QString(s.message).replace(filter, "\1=HIDDEN"); +} + BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint, const Query& query, const Data& data, bool needsToken) : d(new Private(verb, endpoint, query, data, needsToken)) @@ -331,10 +338,7 @@ void BaseJob::setStatus(Status s) { d->status = s; if (!s.good()) - { - qCWarning(d->logCat) << this << "status" << s.code - << ":" << s.message; - } + qCWarning(d->logCat) << this << "status" << s; } void BaseJob::setStatus(int code, QString message) diff --git a/jobs/basejob.h b/jobs/basejob.h index 2f7bd9cd..f8b367c6 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -110,6 +110,7 @@ namespace QMatrixClient Status(int c, QString m) : code(c), message(std::move(m)) { } bool good() const { return code < ErrorLevel; } + friend QDebug operator<<(QDebug dbg, const Status& s); int code; QString message; diff --git a/jobs/generated/leaving.cpp b/jobs/generated/leaving.cpp new file mode 100644 index 00000000..7fed347b --- /dev/null +++ b/jobs/generated/leaving.cpp @@ -0,0 +1,30 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#include "leaving.h" + +#include "jobs/converters.h" +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +LeaveRoomJob::LeaveRoomJob(QString roomId) + : BaseJob(HttpVerb::Post, "LeaveRoomJob", + basePath % "/rooms/" % roomId % "/leave", + Query { }, + Data { } + ) +{ } + +ForgetRoomJob::ForgetRoomJob(QString roomId) + : BaseJob(HttpVerb::Post, "ForgetRoomJob", + basePath % "/rooms/" % roomId % "/forget", + Query { }, + Data { } + ) +{ } + diff --git a/jobs/generated/leaving.h b/jobs/generated/leaving.h new file mode 100644 index 00000000..96304084 --- /dev/null +++ b/jobs/generated/leaving.h @@ -0,0 +1,31 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#pragma once + +#include "../basejob.h" + +#include <QtCore/QString> + + +namespace QMatrixClient +{ + + // Operations + + class LeaveRoomJob : public BaseJob + { + public: + explicit LeaveRoomJob(QString roomId); + + }; + class ForgetRoomJob : public BaseJob + { + public: + explicit ForgetRoomJob(QString roomId); + + }; + +} // namespace QMatrixClient diff --git a/jobs/generated/logout.cpp b/jobs/generated/logout.cpp new file mode 100644 index 00000000..b750efe2 --- /dev/null +++ b/jobs/generated/logout.cpp @@ -0,0 +1,22 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#include "logout.h" + +#include "jobs/converters.h" +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +LogoutJob::LogoutJob() + : BaseJob(HttpVerb::Post, "LogoutJob", + basePath % "/logout", + Query { }, + Data { } + ) +{ } + diff --git a/jobs/generated/logout.h b/jobs/generated/logout.h new file mode 100644 index 00000000..28e85d8f --- /dev/null +++ b/jobs/generated/logout.h @@ -0,0 +1,24 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#pragma once + +#include "../basejob.h" + + + +namespace QMatrixClient +{ + + // Operations + + class LogoutJob : public BaseJob + { + public: + explicit LogoutJob(); + + }; + +} // namespace QMatrixClient diff --git a/jobs/generated/profile.cpp b/jobs/generated/profile.cpp new file mode 100644 index 00000000..9d20a480 --- /dev/null +++ b/jobs/generated/profile.cpp @@ -0,0 +1,144 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#include "profile.h" + +#include "jobs/converters.h" +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +SetDisplayNameJob::SetDisplayNameJob(QString userId, QString displayname) + : BaseJob(HttpVerb::Put, "SetDisplayNameJob", + basePath % "/profile/" % userId % "/displayname", + Query { }, + Data { + { "displayname", toJson(displayname) } + } + ) +{ } + +class GetDisplayNameJob::Private +{ + public: + QString displayname; + +}; + +GetDisplayNameJob::GetDisplayNameJob(QString userId) + : BaseJob(HttpVerb::Get, "GetDisplayNameJob", + basePath % "/profile/" % userId % "/displayname", + Query { }, + Data { } + ), d(new Private) +{ } + +GetDisplayNameJob::~GetDisplayNameJob() +{ + delete d; +} + +const QString& GetDisplayNameJob::displayname() const +{ + return d->displayname; +} + +BaseJob::Status GetDisplayNameJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + + d->displayname = fromJson<QString>(json.value("displayname")); + + return Success; +} + +SetAvatarUrlJob::SetAvatarUrlJob(QString userId, QString avatar_url) + : BaseJob(HttpVerb::Put, "SetAvatarUrlJob", + basePath % "/profile/" % userId % "/avatar_url", + Query { }, + Data { + { "avatar_url", toJson(avatar_url) } + } + ) +{ } + +class GetAvatarUrlJob::Private +{ + public: + QString avatar_url; + +}; + +GetAvatarUrlJob::GetAvatarUrlJob(QString userId) + : BaseJob(HttpVerb::Get, "GetAvatarUrlJob", + basePath % "/profile/" % userId % "/avatar_url", + Query { }, + Data { } + ), d(new Private) +{ } + +GetAvatarUrlJob::~GetAvatarUrlJob() +{ + delete d; +} + +const QString& GetAvatarUrlJob::avatar_url() const +{ + return d->avatar_url; +} + +BaseJob::Status GetAvatarUrlJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + + d->avatar_url = fromJson<QString>(json.value("avatar_url")); + + return Success; +} + +class GetUserProfileJob::Private +{ + public: + QString avatar_url; + QString displayname; + +}; + +GetUserProfileJob::GetUserProfileJob(QString userId) + : BaseJob(HttpVerb::Get, "GetUserProfileJob", + basePath % "/profile/" % userId, + Query { }, + Data { } + ), d(new Private) +{ } + +GetUserProfileJob::~GetUserProfileJob() +{ + delete d; +} + +const QString& GetUserProfileJob::avatar_url() const +{ + return d->avatar_url; +} + +const QString& GetUserProfileJob::displayname() const +{ + return d->displayname; +} + +BaseJob::Status GetUserProfileJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + + d->avatar_url = fromJson<QString>(json.value("avatar_url")); + + d->displayname = fromJson<QString>(json.value("displayname")); + + return Success; +} + diff --git a/jobs/generated/profile.h b/jobs/generated/profile.h new file mode 100644 index 00000000..8e2b195b --- /dev/null +++ b/jobs/generated/profile.h @@ -0,0 +1,80 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#pragma once + +#include "../basejob.h" + +#include <QtCore/QString> + + +namespace QMatrixClient +{ + + // Operations + + class SetDisplayNameJob : public BaseJob + { + public: + explicit SetDisplayNameJob(QString userId, QString displayname = {}); + + }; + class GetDisplayNameJob : public BaseJob + { + public: + explicit GetDisplayNameJob(QString userId); + + ~GetDisplayNameJob() override; + + const QString& displayname() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + Private* d; + }; + class SetAvatarUrlJob : public BaseJob + { + public: + explicit SetAvatarUrlJob(QString userId, QString avatar_url = {}); + + }; + class GetAvatarUrlJob : public BaseJob + { + public: + explicit GetAvatarUrlJob(QString userId); + + ~GetAvatarUrlJob() override; + + const QString& avatar_url() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + Private* d; + }; + class GetUserProfileJob : public BaseJob + { + public: + explicit GetUserProfileJob(QString userId); + + ~GetUserProfileJob() override; + + const QString& avatar_url() const; + const QString& displayname() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + Private* d; + }; + +} // namespace QMatrixClient diff --git a/jobs/leaveroomjob.cpp b/jobs/leaveroomjob.cpp deleted file mode 100644 index 54e7f307..00000000 --- a/jobs/leaveroomjob.cpp +++ /dev/null @@ -1,26 +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 "leaveroomjob.h" - -using namespace QMatrixClient; - -LeaveRoomJob::LeaveRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Post, "LeaveRoomJob", - QStringLiteral("_matrix/client/r0/rooms/%1/leave").arg(roomId)) -{ } diff --git a/jobs/leaveroomjob.h b/jobs/leaveroomjob.h deleted file mode 100644 index 9224c1c8..00000000 --- a/jobs/leaveroomjob.h +++ /dev/null @@ -1,30 +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 LeaveRoomJob: public BaseJob - { - public: - explicit LeaveRoomJob(const QString& roomId); - }; -} // namespace QMatrixClient diff --git a/jobs/logoutjob.cpp b/jobs/logoutjob.cpp deleted file mode 100644 index 5ea5cf4d..00000000 --- a/jobs/logoutjob.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Kitsune Ral <kitsune-ral@users.sf.net> - * - * 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 "logoutjob.h" - -using namespace QMatrixClient; - -LogoutJob::LogoutJob() - : BaseJob(HttpVerb::Post, "LogoutJob", "/_matrix/client/r0/logout") -{ -} diff --git a/jobs/logoutjob.h b/jobs/logoutjob.h deleted file mode 100644 index e1b988dc..00000000 --- a/jobs/logoutjob.h +++ /dev/null @@ -1,30 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Kitsune Ral <kitsune-ral@users.sf.net> - * - * 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 LogoutJob: public BaseJob - { - public: - LogoutJob(); - }; -} diff --git a/jobs/sendeventjob.cpp b/jobs/sendeventjob.cpp index 7e33e089..f5190d4b 100644 --- a/jobs/sendeventjob.cpp +++ b/jobs/sendeventjob.cpp @@ -24,7 +24,7 @@ using namespace QMatrixClient; SendEventJob::SendEventJob(const QString& roomId, const QString& type, const QString& plainText) - : SendEventJob(roomId, new RoomMessageEvent(plainText, type)) + : SendEventJob(roomId, RoomMessageEvent(plainText, type)) { } void SendEventJob::beforeStart(const ConnectionData* connData) diff --git a/jobs/sendeventjob.h b/jobs/sendeventjob.h index 7b10b3d4..3a11eb6a 100644 --- a/jobs/sendeventjob.h +++ b/jobs/sendeventjob.h @@ -29,12 +29,12 @@ namespace QMatrixClient public: /** Constructs a job that sends an arbitrary room event */ template <typename EvT> - SendEventJob(const QString& roomId, const EvT* event) + 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() Query(), - Data(event->toJson())) + Data(event.toJson())) { } /** diff --git a/jobs/setroomstatejob.h b/jobs/setroomstatejob.h index ddc271b9..b7e6d4a1 100644 --- a/jobs/setroomstatejob.h +++ b/jobs/setroomstatejob.h @@ -33,24 +33,24 @@ namespace QMatrixClient */ template <typename EvT> SetRoomStateJob(const QString& roomId, const QString& stateKey, - const EvT* event) + 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())) + 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) + 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())) + Data(event.toJson())) { } QString eventId() const { return _eventId; } diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp index 6d37db5c..ce5dd894 100644 --- a/jobs/syncjob.cpp +++ b/jobs/syncjob.cpp @@ -69,19 +69,13 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data) // TODO: account_data QJsonObject rooms = json.value("rooms").toObject(); - static const struct { QString jsonKey; JoinState enumVal; } roomStates[] + for (size_t i = 0; i < JoinStateStrings.size(); ++i) { - { "join", JoinState::Join }, - { "invite", JoinState::Invite }, - { "leave", JoinState::Leave } - }; - for (const auto& roomState: roomStates) - { - const QJsonObject rs = rooms.value(roomState.jsonKey).toObject(); + const auto rs = rooms.value(JoinStateStrings[i]).toObject(); // We have a Qt container on the right and an STL one on the left roomData.reserve(static_cast<size_t>(rs.size())); for(auto roomIt = rs.begin(); roomIt != rs.end(); ++roomIt) - roomData.emplace_back(roomIt.key(), roomState.enumVal, + roomData.emplace_back(roomIt.key(), JoinState(i), roomIt.value().toObject()); } qCDebug(PROFILER) << "*** SyncData::parseJson():" << et.elapsed() << "ms"; |