diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 12:12:07 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-04 13:27:28 +0900 |
commit | 4cbe1a5fe9b0ae17e89425c3127db2af9b328320 (patch) | |
tree | 70e88c522a412d4502fcf439907304abe2990bdc /lib/jobs | |
parent | 28a0d70164e2596d306521cd18d25c0e8c0b5336 (diff) | |
download | libquotient-4cbe1a5fe9b0ae17e89425c3127db2af9b328320.tar.gz libquotient-4cbe1a5fe9b0ae17e89425c3127db2af9b328320.zip |
Preempt job/setroomstatejob.* with jobs/generated/room_state.*
The template part (not exposed in the auto-generated class) goes to Room::Private::requestSetState(). Also, Room::setMemberState() to interface with User class.
Diffstat (limited to 'lib/jobs')
-rw-r--r-- | lib/jobs/generated/room_state.cpp | 70 | ||||
-rw-r--r-- | lib/jobs/generated/room_state.h | 47 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.cpp | 32 | ||||
-rw-r--r-- | lib/jobs/setroomstatejob.h | 64 |
4 files changed, 117 insertions, 96 deletions
diff --git a/lib/jobs/generated/room_state.cpp b/lib/jobs/generated/room_state.cpp new file mode 100644 index 00000000..39f36afb --- /dev/null +++ b/lib/jobs/generated/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/jobs/generated/room_state.h b/lib/jobs/generated/room_state.h new file mode 100644 index 00000000..5d16b2a6 --- /dev/null +++ b/lib/jobs/generated/room_state.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "../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; + + 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; + + const QString& eventId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient 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 36047667..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 |