diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-03 22:41:12 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-03 22:48:00 +0900 |
commit | a5b6d786878ab5c67a7b436ba475e8ac4d22f1f0 (patch) | |
tree | db185f684477a0f627d167c4fb58afc4941ce2bc | |
parent | f3927ca0c16a61fcb0933333ecff8095917a5b47 (diff) | |
download | libquotient-a5b6d786878ab5c67a7b436ba475e8ac4d22f1f0.tar.gz libquotient-a5b6d786878ab5c67a7b436ba475e8ac4d22f1f0.zip |
Preempt jobs/joinroomjob.* with jobs/generated/joining.*
Enables responding to third-party invites.
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/connection.cpp | 2 | ||||
-rw-r--r-- | lib/jobs/generated/joining.cpp | 118 | ||||
-rw-r--r-- | lib/jobs/generated/joining.h | 77 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.cpp | 58 | ||||
-rw-r--r-- | lib/jobs/joinroomjob.h | 40 | ||||
-rw-r--r-- | libqmatrixclient.pri | 2 |
7 files changed, 196 insertions, 102 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c69d0cfa..5da87063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,6 @@ set(libqmatrixclient_SRCS lib/jobs/checkauthmethods.cpp lib/jobs/sendeventjob.cpp lib/jobs/setroomstatejob.cpp - lib/jobs/joinroomjob.cpp lib/jobs/syncjob.cpp lib/jobs/mediathumbnailjob.cpp lib/jobs/downloadfilejob.cpp diff --git a/lib/connection.cpp b/lib/connection.cpp index b433ccbc..05640c66 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -28,8 +28,8 @@ #include "jobs/generated/receipts.h" #include "jobs/generated/leaving.h" #include "jobs/generated/account-data.h" +#include "jobs/generated/joining.h" #include "jobs/sendeventjob.h" -#include "jobs/joinroomjob.h" #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" diff --git a/lib/jobs/generated/joining.cpp b/lib/jobs/generated/joining.cpp new file mode 100644 index 00000000..705e8f83 --- /dev/null +++ b/lib/jobs/generated/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/jobs/generated/joining.h b/lib/jobs/generated/joining.h new file mode 100644 index 00000000..76edb339 --- /dev/null +++ b/lib/jobs/generated/joining.h @@ -0,0 +1,77 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "../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; + }; + + // End of inner data structures + + explicit JoinRoomByIdJob(const QString& roomId, const ThirdPartySigned& thirdPartySigned = {}); + ~JoinRoomByIdJob() override; + + 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; + }; + + // End of inner data structures + + explicit JoinRoomJob(const QString& roomIdOrAlias, const ThirdPartySigned& thirdPartySigned = {}); + ~JoinRoomJob() override; + + const QString& roomId() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient 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/libqmatrixclient.pri b/libqmatrixclient.pri index 52a12be0..39e153a2 100644 --- a/libqmatrixclient.pri +++ b/libqmatrixclient.pri @@ -34,7 +34,6 @@ HEADERS += \ $$SRCPATH/jobs/passwordlogin.h \ $$SRCPATH/jobs/sendeventjob.h \ $$SRCPATH/jobs/postreceiptjob.h \ - $$SRCPATH/jobs/joinroomjob.h \ $$SRCPATH/jobs/syncjob.h \ $$SRCPATH/jobs/mediathumbnailjob.h \ $$SRCPATH/jobs/setroomstatejob.h \ @@ -66,7 +65,6 @@ SOURCES += \ $$SRCPATH/jobs/passwordlogin.cpp \ $$SRCPATH/jobs/sendeventjob.cpp \ $$SRCPATH/jobs/postreceiptjob.cpp \ - $$SRCPATH/jobs/joinroomjob.cpp \ $$SRCPATH/jobs/syncjob.cpp \ $$SRCPATH/jobs/mediathumbnailjob.cpp \ $$SRCPATH/jobs/setroomstatejob.cpp \ |